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

[email protected] (Yannick Torres)
Newsgroups php.doc.web
Message-ID <[email protected]>
yannick                                  Sat, 28 Nov 2009 10:59:56 +0000

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

Log:
More use of multi_query

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

Modified: web/doc-editor/trunk/php/RepositoryManager.php
===================================================================
--- web/doc-editor/trunk/php/RepositoryManager.php	2009-11-28 10:44:34 UTC (rev 291375)
+++ web/doc-editor/trunk/php/RepositoryManager.php	2009-11-28 10:59:56 UTC (rev 291376)
@@ -57,10 +57,12 @@
      */
     public function cleanUp()
     {
-        // We cleanUp the database before update vcs and apply again all tools
+        // We cleanUp the database before update vcs and apply again all tools
+        $query = '';
         foreach (array('files', 'translators', 'errorfiles') as $table) {
-            DBConnection::getInstance()->query("TRUNCATE TABLE $table");
-        }
+            $query .= "TRUNCATE TABLE $table; ";
+        }
+        DBConnection::getInstance()->multi_query($query);
     }

     /**
@@ -162,11 +164,10 @@
      */
     public function delPendingCommit($files)
     {
-        // Initiate the $s var to store the multi_query
-        $s = '';
+        $query = '';

         for ($i = 0; $i < count($files); $i++) {
-            $s .= sprintf('DELETE FROM `pendingCommit`
+            $query .= sprintf('DELETE FROM `pendingCommit`
                 WHERE
                     `lang` = "%s" AND
                     `path` = "%s" AND
@@ -175,7 +176,7 @@
             );
         }

-        DBConnection::getInstance()->multi_query($s);
+        DBConnection::getInstance()->multi_query($query);
     }

     /**
@@ -537,7 +538,9 @@
      * and put it into database.
      */
     public function updateTranslatorInfo()
-    {
+    {
+        $query = '';
+
         foreach ($this->availableLang as $lang) {

             // Path to find translation.xml file, set default values,
@@ -574,9 +577,9 @@

                         $person = array_merge($default, $person);

-                        $s = sprintf(
+                        $query .= sprintf(
                             'INSERT INTO `translators` (`lang`, `nick`, `name`, `mail`, `vcs`, `editor`)
-                             VALUES ("%s", "%s", "%s", "%s", "%s", "%s")',
+                             VALUES ("%s", "%s", "%s", "%s", "%s", "%s"); ',
                             $lang,
                             DBConnection::getInstance()->real_escape_string($person['nick']),
                             DBConnection::getInstance()->real_escape_string($name),
@@ -584,11 +587,12 @@
                             DBConnection::getInstance()->real_escape_string($person['vcs']),
                             DBConnection::getInstance()->real_escape_string($person['editor'])
                         );
-                        DBConnection::getInstance()->query($s);
+
                     }
                 }
             }
-        }
+        }
+        DBConnection::getInstance()->multi_query($query);
     }

     /**
@@ -640,6 +644,7 @@

             $dirs  = array();
             $files = array();
+            $query = '';

             while (($name = readdir($dh)) !== false) {
                 $file = new File($lang, $path, $name);
@@ -660,14 +665,15 @@
                 $lang_file = DOC_EDITOR_VCS_PATH .$lang .$f->path .$f->name;

                 if (!@is_file($en_file)) {
-                    $s = sprintf(
+                    $query .= sprintf(
                         'INSERT INTO `files` (`lang`, `path`, `name`, `status`)
-                         VALUES ("%s", "%s", "%s", "%s")',
+                         VALUES ("%s", "%s", "%s", "%s"); ',
                         $lang, $f->path, $f->name, 'NotInEN'
                     );
-                    DBConnection::getInstance()->query($s);
                 }
             }
+
+            DBConnection::getInstance()->multi_query($query);

             foreach ($dirs as $d) {
                 $this->doUpdateNotInEN($d->path.$d->name.'/', $lang);
@@ -687,7 +693,8 @@
         if ($dh = @opendir(DOC_EDITOR_VCS_PATH.'en'.$path)) {

             $dirs  = array();
-            $files = array();
+            $files = array();
+            $query = '';

             while (($name = readdir($dh)) !== false) {

@@ -720,9 +727,9 @@
                 $ToolsCheckDocResult = $check_doc->checkDoc($infoEN['content'], $f->path);

                 // Sql insert.
-                $s = sprintf(
+                $query .= sprintf(
                     'INSERT INTO `files` (`lang`, `xmlid`, `path`, `name`, `revision`, `size`, `mdate`, `maintainer`, `status`, `check_oldstyle`,  `check_undoc`, `check_roleerror`, `check_badorder`, `check_noseealso`, `check_noreturnvalues`, `check_noparameters`, `check_noexamples`, `check_noerrors`)
-                        VALUES ("%s", "%s", "%s", "%s", "%s", %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
+                        VALUES ("%s", "%s", "%s", "%s", "%s", %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);',
                     'en', $xmlid, $f->path, $f->name, $en_revision, $en_size, $en_date, 'NULL', 'NULL',
                     $ToolsCheckDocResult['check_oldstyle'],
                     $ToolsCheckDocResult['check_undoc'],
@@ -734,7 +741,6 @@
                     $ToolsCheckDocResult['check_noexamples'],
                     $ToolsCheckDocResult['check_noerrors']
                 );
-                DBConnection::getInstance()->query($s);

                 foreach($this->availableLang as $lang) {

@@ -756,15 +762,14 @@
                         $xmlid      = ($infoLANG['xmlid']      == 'NULL') ? 'NULL' : $infoLANG['xmlid'];
                         $reviewed   = ($infoLANG['reviewed']   == 'NULL') ? 'NULL' : $infoLANG['reviewed'];

-                        $s = sprintf(
+                        $query .= sprintf(
                             'INSERT INTO `files` (`lang`, `xmlid`, `path`, `name`, `revision`, `en_revision`, `reviewed`, `size`, `size_diff`, `mdate`, `mdate_diff`, `maintainer`, `status`)
-                                VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", %s, %s, %s, %s, "%s", "%s")',
+                                VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", %s, %s, %s, %s, "%s", "%s"); ',
                             $lang, $xmlid, $lang_file->path, $lang_file->name,
                             $revision, $en_revision, $reviewed,
                             $size, $size_diff, $date, $date_diff,
                             $maintainer, $status
                         );
-                        DBConnection::getInstance()->query($s);

                         // Check for error in this file ONLY if this file is uptodate
                         if ($revision == $en_revision ) {
@@ -777,15 +782,16 @@
                             $error->saveError();
                         }
                     } else {
-                        $s = sprintf(
+                        $query .= sprintf(
                             'INSERT INTO `files` (`lang`, `path`, `name`)
-                                VALUES ("%s", "%s", "%s")',
+                                VALUES ("%s", "%s", "%s"); ',
                             $lang, $lang_file->path, $lang_file->name
                         );
-                        DBConnection::getInstance()->query($s);
                     }
                 }
             }
+
+            DBConnection::getInstance()->multi_query($query);

             foreach ($dirs as $d) {
                 $this->applyRevCheck($d->path.$d->name.'/');
@@ -801,17 +807,19 @@
      * @return Nothing.
      */
     public function delFiles($files)
-    {
+    {
+        $query = '';
+
         for ($i = 0; $i < count($files); $i++) {
-            $s = sprintf('DELETE FROM files
+            $query .= sprintf('DELETE FROM files
                 WHERE
                     `lang` = "%s" AND
                     `path` = "%s" AND
-                    `name` = "%s"',
+                    `name` = "%s"; ',
                 $files[$i]->lang, $files[$i]->path, $files[$i]->name
             );
-            DBConnection::getInstance()->query($s);
-        }
+        }
+        DBConnection::getInstance()->multi_query($query);
     }

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