svn: /web/doc-editor/trunk/ install/migration.php php/CvsClient.php php/ExtJsController.php php/File.php php/PreviewFile.php php/RepositoryManager.php php/SvnClient.php

[email protected] (Yannick Torres)
Newsgroups php.doc.web
Message-ID <[email protected]>
yannick                                  Thu, 29 Sep 2011 05:20:36 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=317454

Log:
All new files are moved into {module_name}-new/ folder to avoid conflict when they were directly into the repository structure

Changed paths:
    A   web/doc-editor/trunk/install/migration.php
    U   web/doc-editor/trunk/php/CvsClient.php
    U   web/doc-editor/trunk/php/ExtJsController.php
    U   web/doc-editor/trunk/php/File.php
    U   web/doc-editor/trunk/php/PreviewFile.php
    U   web/doc-editor/trunk/php/RepositoryManager.php
    U   web/doc-editor/trunk/php/SvnClient.php
svn-diffs-317454.txt (text/x-diff, 23.3 KB)
Added: web/doc-editor/trunk/install/migration.php
===================================================================
--- web/doc-editor/trunk/install/migration.php	                        (rev 0)
+++ web/doc-editor/trunk/install/migration.php	2011-09-29 05:20:36 UTC (rev 317454)
@@ -0,0 +1,65 @@
+<?php
+error_reporting(E_ALL);
+set_time_limit(0);
+
+require_once '../php/ProjectManager.php';
+require_once '../php/DBConnection.php';
+require_once '../php/RepositoryManager.php';
+require_once '../php/AccountManager.php';
+
+$am = AccountManager::getInstance();
+$rm = RepositoryManager::getInstance();
+$pm = ProjectManager::getInstance();
+$conn = DBConnection::getInstance();
+$availableProject = $pm->getAvailableProject();
+
+while( list($key, $project) = each($availableProject) ) {
+
+    // Only for php project
+    if( $project['code'] != 'php' ) continue;
+
+    // We must delete this var to be re-generated
+    unset($rm->existingLanguage);
+
+    // Define it as a project
+    $pm->setProject($project['code']);
+    $appConf = $am->appConf;
+    $project = $am->project;
+
+    // Get all modified files
+
+        $s = 'SELECT
+                *
+             FROM
+                `work`
+             WHERE
+                `project` = "%s"';
+
+        $params = array($project);
+
+        $r = $conn->query($s, $params);
+
+        $infos = array();
+
+        while ($a = $r->fetch_assoc()) {
+
+            $destFolder = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$a['lang'].$a['path'];
+            $fromFolder = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'/'.$a['lang'].$a['path'];
+
+            echo 'Dest folder : '.$destFolder."\r\n";
+            echo 'From folder : '.$fromFolder."\r\n";
+
+            // Ensure the dest folder exist
+            mkdir($destFolder, 0777, true);
+
+            // If this entrie is a file, we move it into the dest folder
+            if( $a['name'] != '-' && is_file($fromFolder.$a['name'].'.new') ) {
+                rename( $fromFolder.$a['name'].'.new', $destFolder.$a['name'] );
+            }
+
+        }
+
+
+}
+
+?>
\ No newline at end of file

Modified: web/doc-editor/trunk/php/CvsClient.php
===================================================================
--- web/doc-editor/trunk/php/CvsClient.php	2011-09-28 23:56:02 UTC (rev 317453)
+++ web/doc-editor/trunk/php/CvsClient.php	2011-09-29 05:20:36 UTC (rev 317454)
@@ -228,8 +228,9 @@
      */
     public function commit($log, $create=false, $update=false, $delete=false)
     {
-        $appConf = AccountManager::getInstance()->appConf;
-        $project = AccountManager::getInstance()->project;
+        $am      = AccountManager::getInstance();
+        $appConf = $am->appConf;
+        $project = $am->project;

         $create_stack = array();
         for ($i = 0; $create && $i < count($create); $i++) {
@@ -241,8 +242,9 @@
             $p = $update[$i]->lang.'/'.$update[$i]->path.'/'.$update[$i]->name;
             $update_stack[] = $p;

-            @copy(  $appConf[$project]['vcs.path'].$p.'.new', $appConf[$project]['vcs.path'].$p);
-            @unlink($appConf[$project]['vcs.path'].$p.'.new');
+            @copy(  $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$p, $appConf[$project]['vcs.path'].$p);
+
+            @unlink( $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$p );
         }

         $delete_stack = array();

Modified: web/doc-editor/trunk/php/ExtJsController.php
===================================================================
--- web/doc-editor/trunk/php/ExtJsController.php	2011-09-28 23:56:02 UTC (rev 317453)
+++ web/doc-editor/trunk/php/ExtJsController.php	2011-09-29 05:20:36 UTC (rev 317454)
@@ -917,6 +917,10 @@
     }
     /**
      * Save a file. The new file have an extension like ".new", and is saved in the same folder as the original.
+     *
+     * @HERE : The new file no more have an extension '.new'. Now, it's saved into 'module-name-'new folder, with the same folder's hierarchie
+     *
+     *
      */
     public function saveFile()
     {
@@ -974,29 +978,29 @@

         // Rules to allow this file to be saved or not.
         if( $infoModified = $file->isModified() ) {
-
-        	$infoModified = json_decode($infoModified);
-
-        	// If the user who have modified this file isn't the current one
-        	if(
-                    ( !$am->isAnonymous && ( $infoModified->user ==  $am->vcsLogin ) ) ||
-                    (  $am->isAnonymous && ( $infoModified->anonymousIdent == $am->anonymousIdent ) )
-                ) {
-        		// We can modify it, it's mine ;)
-        	} else {
-        		// If he is an anonymous and current user, an authenticated user, the current one can modify it.
-        		if( $am->anonymous($infoModified->user, $infoModified->anonymousIdent) && !$am->anonymous($am->vcsLogin, $am->anonymousIdent) ) {
-        			// The current user can modify it
-        		} else {
-        			// We must trow an error. We can't modify it.
-
-		            return JsonResponseBuilder::failure(
-			            array(
-			              'type' => 'save_you_cant_modify_it'
-			            )
-		            );
-        		}
-        	}
+
+            $infoModified = json_decode($infoModified);
+
+            // If the user who have modified this file isn't the current one
+            if(
+                ( !$am->isAnonymous && ( $infoModified->user ==  $am->vcsLogin ) ) ||
+                (  $am->isAnonymous && ( $infoModified->anonymousIdent == $am->anonymousIdent ) )
+            ) {
+                    // We can modify it, it's mine ;)
+            } else {
+                    // If he is an anonymous and current user, an authenticated user, the current one can modify it.
+                    if( $am->anonymous($infoModified->user, $infoModified->anonymousIdent) && !$am->anonymous($am->vcsLogin, $am->anonymousIdent) ) {
+                            // The current user can modify it
+                    } else {
+                            // We must trow an error. We can't modify it.
+
+                        return JsonResponseBuilder::failure(
+                                array(
+                                    'type' => 'save_you_cant_modify_it'
+                                )
+                        );
+                    }
+            }
         }

         // Detect encoding
@@ -1021,7 +1025,7 @@

         if ($type == 'file') {

-            $er = $file->save($fileContent, false);
+            $er = $file->save($fileContent);

             if( $er['state'] ) {

@@ -1051,7 +1055,7 @@
             // We must ensure that this folder exist localy
             if( $file->folderExist() ) {

-               $er = $file->save($fileContent, false);
+               $er = $file->save($fileContent);

                if( $er['state'] ) {


Modified: web/doc-editor/trunk/php/File.php
===================================================================
--- web/doc-editor/trunk/php/File.php	2011-09-28 23:56:02 UTC (rev 317453)
+++ web/doc-editor/trunk/php/File.php	2011-09-29 05:20:36 UTC (rev 317454)
@@ -9,13 +9,17 @@
 class File
 {
     public $lang;
-    public $path;
     public $name;

+    public $path;
+
     public $full_path;
+    public $full_new_path;
+
     public $full_path_fallback;

     public $full_path_dir;
+    public $full_new_path_dir;

     public $isDir;
     public $isFile;
@@ -48,7 +52,7 @@
         $path_parts = pathinfo($path);

         if( !isset($path_parts['extension']) ) {
-        	$this->isDir = true;
+            $this->isDir = true;
             $this->isFile = false;
             $this->name = '';
             $path_parts['dirname'] = isset($path_parts['dirname']) ? $path_parts['dirname'] : '';
@@ -68,7 +72,10 @@
             $this->path = "/$path/";

             $this->full_path = $appConf[$project]['vcs.path'].$lang.'/'.$path.'/'.$this->name;
+            $this->full_new_path = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$lang.'/'.$path.'/'.$this->name;
+
             $this->full_path_dir = $appConf[$project]['vcs.path'].$lang.'/'.$path.'/';
+            $this->full_new_path_dir = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$lang.'/'.$path.'/';

             // The fallback file : if the file don't exist, we fallback to the EN file witch should always exist
             $this->full_path_fallback = $appConf[$project]['vcs.path'].'en/'.$path.'/'.$this->name;
@@ -76,9 +83,14 @@
             $this->path = '/';

             $this->full_path = $appConf[$project]['vcs.path'].$lang.'/'.$this->name;
+            $this->full_new_path = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$lang.'/'.$this->name;
+
             $this->full_path_dir = $appConf[$project]['vcs.path'].$lang.'/';
+            $this->full_new_path_dir = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$lang.'/';
+
             $this->full_path_fallback = $appConf[$project]['vcs.path'].'en/'.$this->name;
         }
+
         $this->conn = DBConnection::getInstance();
     }

@@ -97,7 +109,7 @@
     public function translate()
     {
         // We must check if the file exist.
-        // For example, when we start a translation, save it, and then open it from work in progress module, the path (without .new) don't exist and we must use the fallback path for translation
+        // For example, when we start a translation, save it, and then open it from work in progress module, the path don't exist and we must use the fallback path for translation

         $originalContent = ( is_file($this->full_path) ) ? file_get_contents($this->full_path) : file_get_contents($this->full_path_fallback);

@@ -155,7 +167,7 @@

         $path = ($readOriginal || !$isModified)
                 ? $this->full_path
-                : $this->full_path . '.new';
+                : $this->full_new_path;

         if( is_file($path) ) {
             return file_get_contents($path);
@@ -172,21 +184,22 @@
      * Save a file after modification.
      *
      * @param $content The new content.
-     * @param $isPatch Indicate whether saving file as patch (default=false)
-     * @param $uniqID Patch unique ID (provided if isPatch=true)
      * @return The path to the new file successfully created.
      */
-    public function save($content, $isPatch, $uniqID=false)
+    public function save($content)
     {
-        $ext  = ($isPatch) ? '.' . $uniqID . '.patch' : '.new';
-        $path = $this->full_path . $ext;

+        // Ensure the folder exist.
+        if( ! is_dir($this->full_new_path_dir) ) {
+            mkdir( $this->full_new_path_dir, 0777, true );
+        }
+
         // Open in w+ mode
-        $h = @fopen($path, 'w+');
+        $h = @fopen($this->full_new_path, 'w+');
         if( $h ) {
             fwrite($h, $content);
             fclose($h);
-            return $path;
+            return $this->full_new_path;
         } else {
             return array(
              'state' => false
@@ -212,7 +225,7 @@
        }

        // We create this folder localy
-       if( ! @mkdir($appConf[$project]['vcs.path'].$this->lang.'/'.$path) ) {
+       if( ! @mkdir($appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$this->lang.'/'.$path, 0777, true) ) {
            return false;
        }

@@ -225,7 +238,7 @@
     }

     /**
-     * Check if the path of this $file exist or not. If not, try to create it recursively with createFolder's method
+     * Check if the path of this $file exist or not. If not, try to create it
      *
      * @return true
      */
@@ -235,28 +248,10 @@
         $appConf = $am->appConf;
         $project = $am->project;

-        $folders = array();
-        $_folders = explode("/", $this->path);
-
-        //Skip empty value
-        for( $i=0; $i < count($_folders); $i++) {
-           if( $_folders[$i] != "" ) {
-              $folders[] = $_folders[$i];
-           }
+        if( !is_dir($this->full_new_path_dir) ) {
+            $this->createFolder();
         }

-        $path = '';
-
-        for( $i=0; $i < count($folders); $i++ ) {
-
-           $herePath = $path.'/'.$folders[$i];
-
-           if( !is_dir($appConf[$project]['vcs.path'].$this->lang.$herePath) ) {
-              $this->createFolder($herePath);
-           }
-
-           $path = $herePath;
-        }
         return true;
     }

@@ -298,13 +293,6 @@
         $am      = AccountManager::getInstance();
         $project = $am->project;

-        // If the current file is a .new file, we must escape the .new otherwise, we haven't any result from the database
-        if( substr($this->name, -4) == ".new" ) {
-            $hereName = substr($this->name, 0, (strlen($this->name) - 4));
-        } else {
-            $hereName = $this->name;
-        }
-
         $s = 'SELECT
                 `id` as fidDB,
                 `user`,
@@ -322,7 +310,7 @@
             $project,
             $this->lang,
             $this->path,
-            $hereName
+            $this->name
         );

         $r = $this->conn->query($s, $params);
@@ -434,9 +422,12 @@
             $patchFiles = RepositoryManager::getInstance()->getPatchFilesByID($patchID);
             for( $i=0; $i < count($patchFiles); $i++ )
             {
+
+                $pathFileOrigin = $appConf[$project]['vcs.path'] . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name;
+                $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name;
+
                 $commands = array(
-                    new ExecStatement('cd %s', array($appConf[$project]['vcs.path'] . $patchFiles[$i]->lang . $patchFiles[$i]->path)),
-                    new ExecStatement('diff -u %s %s', array($patchFiles[$i]->name, $patchFiles[$i]->name . '.new'))
+                    new ExecStatement('diff -u %s %s', array($pathFileOrigin, $pathFileModified))
                 );

                 $trial_threshold = 3;
@@ -454,9 +445,11 @@

         } else {

+            $pathFileOrigin = $appConf[$project]['vcs.path'] . $this->lang . $this->path . $this->name;
+            $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $this->lang . $this->path . $this->name;
+
             $commands = array(
-                new ExecStatement('cd %s', array($appConf[$project]['vcs.path'] . $this->lang . $this->path)),
-                new ExecStatement('diff -u %s %s', array($this->name, $this->name . '.new'))
+                new ExecStatement('diff -u %s %s', array($pathFileOrigin, $pathFileModified))
             );

             $output = array();
@@ -492,7 +485,7 @@

         } elseif( $type == 'file' || $type == 'patch' ) {

-            $ext = ( $options['type'] == 'patch' ) ? '.' . $options['uniqID'] . '.patch' : '.new';
+            //$ext = ( $options['type'] == 'patch' ) ? '.' . $options['uniqID'] . '.patch' : '.new';

             // If this patch is for new file, we only display "This is a new file."
             if( $type == 'patch' && !is_file($appConf[$project]['vcs.path'].$this->lang.$this->path.$this->name) ) {
@@ -501,9 +494,12 @@

                 if( $options['patchID'] == '' )
                 {
+
+                    $pathFileOrigin = $appConf[$project]['vcs.path'] . $this->lang . $this->path . $this->name;
+                    $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $this->lang . $this->path . $this->name;
+
                     $commands = array(
-                        new ExecStatement('cd %s', array($appConf[$project]['vcs.path'] . $this->lang . $this->path)),
-                        new ExecStatement('diff -u %s %s', array($this->name, $this->name . $ext))
+                        new ExecStatement('diff -u %s %s', array($pathFileOrigin, $pathFileModified))
                     );

                     $trial_threshold = 3;
@@ -523,9 +519,12 @@

                     for( $i=0; $i < count($patchFiles); $i++ )
                     {
+
+                        $pathFileOrigin = $appConf[$project]['vcs.path'] . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name;
+                        $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name;
+
                         $commands = array(
-                            new ExecStatement('cd %s', array($appConf[$project]['vcs.path'] . $patchFiles[$i]->lang . $patchFiles[$i]->path)),
-                            new ExecStatement('diff -u %s %s', array($patchFiles[$i]->name, $patchFiles[$i]->name . '.new'))
+                            new ExecStatement('diff -u %s %s', array($pathFileOrigin, $pathFileModified))
                         );

                         $trial_threshold = 3;

Modified: web/doc-editor/trunk/php/PreviewFile.php
===================================================================
--- web/doc-editor/trunk/php/PreviewFile.php	2011-09-28 23:56:02 UTC (rev 317453)
+++ web/doc-editor/trunk/php/PreviewFile.php	2011-09-29 05:20:36 UTC (rev 317454)
@@ -6,10 +6,14 @@
 {
     public $path;
     public $previewUrl;
+
     private $am;
     private $outputDir;
     private $inputDir;
     private $buildCmd;
+
+    private $fullPath;
+    private $fullNewPath;

     /**
      */
@@ -35,6 +39,7 @@
         $project = $this->am->project;

         $this->fullPath = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'/'.$this->path;
+        $this->fullNewPath = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/'.$this->path;

     }

@@ -75,10 +80,10 @@
         $rename = 0;
         $t = time();
         // We are editing temporary file
-        if( file_exists($this->fullPath.'.new') ) {
+        if( file_exists($this->fullNewPath) ) {
             $rename = 1;
             rename($this->fullPath, $this->fullPath . $t);
-            rename($this->fullPath .'.new', $this->fullPath);
+            rename($this->fullNewPath, $this->fullPath);
         }

         // We start the build for this file
@@ -94,7 +99,7 @@

         // Rename it back
         if ($rename) {
-            rename($this->fullPath, $this->fullPath . '.new');
+            rename($this->fullPath, $this->fullNewPath);
             rename($this->fullPath . $t, $this->fullPath);
         }


Modified: web/doc-editor/trunk/php/RepositoryManager.php
===================================================================
--- web/doc-editor/trunk/php/RepositoryManager.php	2011-09-28 23:56:02 UTC (rev 317453)
+++ web/doc-editor/trunk/php/RepositoryManager.php	2011-09-29 05:20:36 UTC (rev 317454)
@@ -910,7 +910,7 @@
                         // We delete our .new, and remove all reference for it from the DB

                         // Delete this new file from the fileSystem
-                        @unlink($files[$i]->full_path.'.new');
+                        @unlink($files[$i]->full_new_path);

                         // Delete from work table
                         $this->delWork(array($files[$i]));
@@ -960,6 +960,23 @@

     }

+    public function ensureFoldersExists($folders)
+    {
+        $am      = AccountManager::getInstance();
+        $appConf = $am->appConf;
+        $project = $am->project;
+
+        while( list($folderPath, $data) = each($folders) ) {
+
+            if( ! is_dir($appConf[$project]['vcs.path'].$folderPath) ) {
+
+                mkdir( $appConf[$project]['vcs.path'].$folderPath, 0777, true );
+
+            }
+        }
+    }
+
+
     /**
      * Get only Folders we need to commit according to chosen files
      *
@@ -1050,15 +1067,15 @@
     {
         switch ($type) {
             case 'new':
-                // remove .new file
+                // remove file in -new folder
                 for ($i=0; $i < count($files); $i++) {
-                    @unlink($files[$i]->full_path.'.new');
+                    @unlink($files[$i]->full_new_path);
                 }
                 break;
             case 'update':
-                // remove .new file
+                // remove file in -new folder
                 for ($i=0; $i < count($files); $i++) {
-                    @unlink($files[$i]->full_path.'.new');
+                    @unlink($files[$i]->full_new_path);
                     @unlink($files[$i]->full_path.'.bak');
                 }
                 break;
@@ -1088,6 +1105,10 @@
         $foldersInfos = $this->getOnlyFoldersForFiles($foldersInfos, $fileInfos);

         if( $foldersInfos ) {
+
+            // We must create this folder before commit it
+            $this->ensureFoldersExists($foldersInfos);
+
             $c = VCSFactory::getInstance()->commitFolders($foldersInfos);
             $commitLog = array_merge($commitLog, $c);
             $this->delWork($foldersInfos);
@@ -1320,8 +1341,7 @@
         }

         // We need delete file on filesystem (for new & update)
-        $doc = $file->full_path.'.new';
-        @unlink($doc);
+        @unlink($file->full_new_path);

         // If type == new, we stop here and return
         if ($type == 'new') {
@@ -1623,7 +1643,7 @@
         $path = $file->path;

         if( substr($name, -4) === '.new' ) {
-        	$toDisplay = true;
+            $toDisplay = true;
         } else {
             $toDisplay = false;
         }
@@ -2078,6 +2098,28 @@
         }
     }

+    /**
+     * Create the folder how hold all modified files for this project.
+     *
+     */
+    public function initCreateFolderForModifiedFiles()
+    {
+        $am      = AccountManager::getInstance();
+        $appConf = $am->appConf;
+        $project = $am->project;
+
+        $folderPath = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new';
+
+        if( is_dir($folderPath) ) {
+            return false; // already exist
+        } else {
+            if( mkdir($folderPath) ) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+    }
 }

 ?>

Modified: web/doc-editor/trunk/php/SvnClient.php
===================================================================
--- web/doc-editor/trunk/php/SvnClient.php	2011-09-28 23:56:02 UTC (rev 317453)
+++ web/doc-editor/trunk/php/SvnClient.php	2011-09-29 05:20:36 UTC (rev 317454)
@@ -547,20 +547,22 @@

         $create_stack = array();
         for ($i = 0; $create && $i < count($create); $i++) {
-            $p = $create[$i]->full_path;
-            $create_stack[] = $p;
+            $p_to = $create[$i]->full_path;
+            $p_from = $create[$i]->full_new_path;
+            $create_stack[] = $p_to;

-            // Pre-commit : rename .new to actual file
-            @copy($p.'.new', $p);
+            // Pre-commit : rename *-new/foo.xml to actual file
+            @copy($p_from, $p_to);
         }

         $update_stack = array();
         for ($i = 0; $update && $i < count($update); $i++) {
-            $p = $update[$i]->full_path;
-            $update_stack[] = $p;
+            $p_to = $update[$i]->full_path;
+            $p_from = $update[$i]->full_new_path;
+            $update_stack[] = $p_to;

-            // Pre-commit : rename .new to actual file
-            @copy($p.'.new', $p);
+            // Pre-commit : rename *-new/foo.xml to actual file
+            @copy($p_from, $p_to);
         }

         $delete_stack = array();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.