svn: /web/doc-editor/trunk/php/ ExtJsController.php RepositoryManager.php

[email protected] (Yannick Torres)
Newsgroups php.doc.web
Message-ID <[email protected]>
yannick                                  Mon, 16 Nov 2009 21:59:27 +0000

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

Log:
Stuff on onSuccesCommit's method. Split stuff regarding the file type (new, delete or update). Add a new method into RepositoryManager.php to delete a file into DB

Changed paths:
    U   web/doc-editor/trunk/php/ExtJsController.php
    U   web/doc-editor/trunk/php/RepositoryManager.php

Modified: web/doc-editor/trunk/php/ExtJsController.php
===================================================================
--- web/doc-editor/trunk/php/ExtJsController.php	2009-11-16 21:54:46 UTC (rev 290840)
+++ web/doc-editor/trunk/php/ExtJsController.php	2009-11-16 21:59:27 UTC (rev 290841)
@@ -703,35 +703,78 @@

         $nodes = RepositoryFetcher::getInstance()->getModifiesById($anode);

-        $files = array();
+        // We need to provide a different treatment regarding the file's type...
+        $existFiles = array(); // Can be an updated file or a new file
+        $deleteFiles = array();
+        $j = 0;
+
         for ($i = 0; $i < count($nodes); $i++) {
-            $files[$i] = new File(
-                $nodes[$i]['lang'],
-                $nodes[$i]['path'],
-                $nodes[$i]['name']
-            );
+
+            if( $nodes[$i]['type'] == 'update' || $nodes[$i]['type'] == 'new' ) {
+                $existFiles[] = new File(
+                    $nodes[$i]['lang'],
+                    $nodes[$i]['path'],
+                    $nodes[$i]['name']
+                );
+            }
+
+            if( $nodes[$i]['type'] == 'delete' ) {
+                $deleteFiles[$j]->lang = $nodes[$i]['lang'];
+                $deleteFiles[$j]->path = $nodes[$i]['path'];
+                $deleteFiles[$j]->name = $nodes[$i]['name'];
+                $j ++;
+            }
+
         }

-        // Update revision & reviewed for all this files
-        RepositoryManager::getInstance()->updateFileInfo($files);
+        // ... for existing Files (new or update)
+        if( !empty($existFiles) ) {

-        for ($i = 0; $i < count($files); $i++) {
+            // Update revision & reviewed for all this files (LANG & EN)
+            RepositoryManager::getInstance()->updateFileInfo($existFiles);

-            $en = new File('en', $files[$i]->path, $files[$i]->name);
+            // Stuff only for LANG files
+            $langFiles = array();
+            $j = 0;

-            $en_content   = $en->read(true);
-            $lang_content = $files[$i]->read(true);
+            for ($i = 0; $i < count($existFiles); $i++) {
+                // Only for lang files.
+                if( $existFiles[$i]->lang != 'en' ) {

-            $nodes[$i]['en_content']   = $en_content;
-            $nodes[$i]['lang_content'] = $lang_content;
-        }
+                    $en = new File('en', $existFiles[$i]->path, $existFiles[$i]->name);

-        $errorTools = new ToolsError();
-        $errorTools->updateFilesError($nodes);
+                    $info = $existFiles[$i]->getInfo();

-        // Remove all this files in needcommit
-        RepositoryManager::getInstance()->delPendingCommit($files);
+                    $langFiles[$j]['en_content']   = $en->read(true);
+                    $langFiles[$j]['lang_content'] = $existFiles[$i]->read(true);
+                    $langFiles[$j]['lang'] = $existFiles[$i]->lang;
+                    $langFiles[$j]['path'] = $existFiles[$i]->path;
+                    $langFiles[$j]['name'] = $existFiles[$i]->name;
+                    $langFiles[$j]['maintainer'] = $info['maintainer'];

+                    $j ++;
+                }
+            }
+            if( !empty($langFiles) ) {
+                $errorTools = new ToolsError();
+                $errorTools->updateFilesError($langFiles);
+            }
+            // Remove all this files in needcommit
+            RepositoryManager::getInstance()->delPendingCommit($existFiles);
+        } // End of $existFiles stuff
+
+        // ... for deleted Files
+        if( !empty($deleteFiles) ) {
+
+            // Remove this files from the repository
+            RepositoryManager::getInstance()->delFiles($deleteFiles);
+
+            // Remove all this files in needcommit
+            RepositoryManager::getInstance()->delPendingCommit($deleteFiles);
+
+        } // End of $deleteFiles stuff
+
+        // Manage log message (add new or ignore it if this message already exist for this user)
         LogManager::getInstance()->addCommitLog($logMessage);

         return JsonResponseBuilder::success();

Modified: web/doc-editor/trunk/php/RepositoryManager.php
===================================================================
--- web/doc-editor/trunk/php/RepositoryManager.php	2009-11-16 21:54:46 UTC (rev 290840)
+++ web/doc-editor/trunk/php/RepositoryManager.php	2009-11-16 21:59:27 UTC (rev 290841)
@@ -775,6 +775,27 @@
         }
         @closedir($dh);
     }
+
+    /**
+     * Remove a file from DB
+     *
+     * @param $files An array of File instances.
+     * @return Nothing.
+     */
+    public function delFiles($files)
+    {
+        for ($i = 0; $i < count($files); $i++) {
+            $s = sprintf('DELETE FROM files
+                WHERE
+                    `lang` = "%s" AND
+                    `path` = "%s" AND
+                    `name` = "%s"',
+                $files[$i]->lang, $files[$i]->path, $files[$i]->name
+            );
+            DBConnection::getInstance()->query($s);
+        }
+    }
+
 }

 ?>
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.