fixed some minor errors in sql pip
authorMarcel Werk <burntime@woltlab.com>
Tue, 19 Jul 2011 16:40:41 +0000 (18:40 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 19 Jul 2011 16:40:41 +0000 (18:40 +0200)
wcfsetup/install/files/lib/system/database/util/SQLParser.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php
wcfsetup/install/files/lib/system/package/plugin/SqlPackageInstallationPlugin.class.php

index d0bc91801dffabc38f35349a994f2b01a2116e53..853c07500a1d412f654381683a8c4581db8c4fb7 100644 (file)
@@ -10,7 +10,7 @@ use wcf\util\StringUtil;
  * Given queries will be parsed, converted and executed in the active database.
  * 
  * @author     Marcel Werk
- * @copyright  2001-2008 WoltLab GmbH
+ * @copyright  2001-2011 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.database.util
index e2238a1f58f41257fdcd552d8e7f2b2d536d9b0f..8a25526ef574735ebabf2d6026b92d944c054f81 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-namespace wcf\acp\package;
+namespace wcf\system\package;
 use wcf\data\package\Package;
 use wcf\system\database\util\SQLParser;
 use wcf\system\exception\SystemException;
@@ -17,71 +17,61 @@ use wcf\system\WCF;
  */
 class PackageInstallationSQLParser extends SQLParser {
        /**
-        * Package object
-        *
-        * @var Package
+        * package object
+        * @var wcf\data\package\Package
         */
-       protected $package;
+       protected $package = null;
        
        /**
         * activates the testing mode
-        * 
         * @var boolean
         */
        protected $test = false;
        
        /**
         * installation type
-        * 
         * @var string
         */
        protected $action = 'install';
        
        /**
         * list of existing database tables
-        * 
         * @var array
         */
        protected $existingTables = array();
        
        /**
         * list of logged tables
-        * 
         * @var array
         */
        protected $knownTables = array();
        
        /**
         * list of package ids
-        * 
         * @var array
         */
-       protected $dependentPackageIDArray = array();
+       protected $dependentPackageIDs = array();
        
        /**
         * list of conflicted database tables
-        * 
         * @var array
         */
        protected $conflicts = array();
        
        /**
         * list of created/deleted tables
-        * 
         * @var array
         */
        protected $tableLog = array();
        
        /**
         * list of created/deleted columns
-        * 
         * @var array
         */
        protected $columnLog = array();
        
        /**
         * list of created/deleted indices
-        * 
         * @var array
         */
        protected $indexLog = array();
@@ -89,9 +79,9 @@ class PackageInstallationSQLParser extends SQLParser {
        /**
         * Creates a new PackageInstallationSQLParser object.
         * 
-        * @param       string          $queries
-        * @param       Package         $package
-        * @param       string          $action
+        * @param       string                          $queries
+        * @param       wcf\data\package\Package        $package
+        * @param       string                          $action
         */
        public function __construct($queries, Package $package, $action = 'install') {
                $this->package = $package;
@@ -114,7 +104,7 @@ class PackageInstallationSQLParser extends SQLParser {
                $this->getKnownTables();
                                
                // get package ids of dependencies
-               $this->getDependentPackageIDArray();
+               $this->getDependentPackageIDs();
                
                // enable testing mode
                $this->test = true;
@@ -196,14 +186,14 @@ class PackageInstallationSQLParser extends SQLParser {
                                $deleteStatement->execute(array(
                                        $logEntry['tableName'],
                                        $logEntry['indexName']
-                                       ));
+                               ));
                                
                                if ($logEntry['action'] == 'insert') {
                                        $insertStatement->execute(array(
                                                $logEntry['packageID'],
                                                $logEntry['tableName'],
                                                $logEntry['indexName']
-                                               ));
+                                       ));
                                }
                        }
                }
@@ -227,7 +217,7 @@ class PackageInstallationSQLParser extends SQLParser {
        /**
         * Gets a list of dependent packages.
         */
-       protected function getDependentPackageIDArray() {
+       protected function getDependentPackageIDs() {
                $sql = "SELECT          dependency
                        FROM            wcf".WCF_N."_package_dependency
                        WHERE           packageID = ?";
@@ -235,7 +225,7 @@ class PackageInstallationSQLParser extends SQLParser {
                $statement->execute(array($this->package->packageID));
                $packages = array();
                while ($row = $statement->fetchArray()) {
-                       $this->dependentPackageIDArray[] = $row['dependency'];
+                       $this->dependentPackageIDs[] = $row['dependency'];
                }
        }
        
@@ -286,7 +276,7 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeCreateTableStatement()
+        * @see wcf\system\database\util\SQLParser::executeCreateTableStatement()
         */
        protected function executeCreateTableStatement($tableName, $columns, $indices = array()) {
                if ($this->test) {
@@ -312,12 +302,12 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeAddColumnStatement()
+        * @see wcf\system\database\util\SQLParser::executeAddColumnStatement()
         */
        protected function executeAddColumnStatement($tableName, $columnName, $columnData) {
                if ($this->test) {
                        if (isset($this->knownTables[$tableName])) {
-                               if ($this->knownTables[$tableName] != $this->package->packageID && !in_array($this->knownTables[$tableName], $this->dependentPackageIDArray)) {
+                               if ($this->knownTables[$tableName] != $this->package->packageID && !in_array($this->knownTables[$tableName], $this->dependentPackageIDs)) {
                                        throw new SystemException("Can not add column '".$columnName."' to table '.$tableName.'. An installion can only 'ADD' things to tables from the same package environment.", 13019);
                                }
                        }
@@ -332,7 +322,7 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeAddColumnStatement()
+        * @see wcf\system\database\util\SQLParser::executeAddColumnStatement()
         */
        protected function executeAlterColumnStatement($tableName, $oldColumnName, $newColumnName, $newColumnData) {
                if ($this->test) {
@@ -355,12 +345,12 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeAddIndexStatement()
+        * @see wcf\system\database\util\SQLParser::executeAddIndexStatement()
         */
        protected function executeAddIndexStatement($tableName, $indexName, $indexData) {
                if ($this->test) {
                        if (isset($this->knownTables[$tableName])) {
-                               if ($this->knownTables[$tableName] != $this->package->packageID && !in_array($this->knownTables[$tableName], $this->dependentPackageIDArray)) {
+                               if ($this->knownTables[$tableName] != $this->package->packageID && !in_array($this->knownTables[$tableName], $this->dependentPackageIDs)) {
                                        throw new SystemException("Can not add index '".$indexName."' to table '.$tableName.'. An installion can only 'ADD' things to tables from the same package environment.", 13019);
                                }
                        }
@@ -375,7 +365,27 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeDropColumnStatement()
+        * @see wcf\system\database\util\SQLParser::executeAddForeignKeyStatement()
+        */
+       protected function executeAddForeignKeyStatement($tableName, $indexName, $indexData) {
+               if ($this->test) {
+                       if (isset($this->knownTables[$tableName])) {
+                               if ($this->knownTables[$tableName] != $this->package->packageID && !in_array($this->knownTables[$tableName], $this->dependentPackageIDs)) {
+                                       throw new SystemException("Can not add foreign key '".$indexName."' to table '.$tableName.'. An installion can only 'ADD' things to tables from the same package environment.", 13019);
+                               }
+                       }
+               }
+               else {
+                       // log
+                       $this->indexLog[] = array('tableName' => $tableName, 'indexName' => $indexName, 'packageID' => $this->package->packageID, 'action' => 'insert');
+                       
+                       // execute
+                       parent::executeAddForeignKeyStatement($tableName, $indexName, $indexData);
+               }
+       }
+       
+       /**
+        * @see wcf\system\database\util\SQLParser::executeDropColumnStatement()
         */
        protected function executeDropColumnStatement($tableName, $columnName) {
                if ($this->test) {
@@ -395,7 +405,7 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeDropIndexStatement()
+        * @see wcf\system\database\util\SQLParser::executeDropIndexStatement()
         */
        protected function executeDropIndexStatement($tableName, $indexName) {
                if ($this->test) {
@@ -415,7 +425,7 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeDropTableStatement()
+        * @see wcf\system\database\util\SQLParser::executeDropTableStatement()
         */
        protected function executeDropTableStatement($tableName) {
                if ($this->test) {
@@ -441,7 +451,7 @@ class PackageInstallationSQLParser extends SQLParser {
        }
        
        /**
-        * @see SQLParser::executeStandardStatement()
+        * @see wcf\system\database\util\SQLParser::executeStandardStatement()
         */
        protected function executeStandardStatement($query) {
                if (!$this->test) {
@@ -449,4 +459,3 @@ class PackageInstallationSQLParser extends SQLParser {
                }
        }
 }
-?>
index 0220f3db0dbe18a4fa568dbc60403ee661273a0d..ab9f0485716d5de74b42bb4c08956c56312de719 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\package\plugin;
+use wcf\system\package\PackageInstallationSQLParser;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
 use wcf\util\StringUtil;