Fixes replacement of table prefixes
authorMatthias Schmidt <gravatronics@live.com>
Mon, 15 Apr 2013 18:39:41 +0000 (20:39 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 15 Apr 2013 18:39:41 +0000 (20:39 +0200)
If a package, that is no application, requires an application (in WCF 1, this would have been a plugin), only the `wcf1_` prefix is replaced, thus altering existing application tables or creating new application tables isn't possible.

This commit now replaces app1_ with app{WCF_N}_ for all installed applications.

wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php

index be39869d4ea60702940e99ba9ce49d3898e857ca..54c8bb1d1bc475ff1179bd9d66f8cefa07d7774f 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\package\plugin;
 use wcf\data\package\Package;
+use wcf\data\package\PackageList;
 use wcf\system\exception\SystemException;
 use wcf\system\form\container\GroupFormElementContainer;
 use wcf\system\form\element\LabelFormElement;
@@ -35,18 +36,18 @@ class SQLPackageInstallationPlugin extends AbstractPackageInstallationPlugin {
                // extract sql file from archive
                if ($queries = $this->getSQL($this->instruction['value'])) {
                        $package = $this->installation->getPackage();
-                       if ($package->isApplication == 1) {
-                               // package is application
-                               $packageAbbr = Package::getAbbreviation($package->package);
-                               $tablePrefix = WCF_N.'_';
+                       
+                       // replace app1_ with app{WCF_N}_ in the table names for
+                       // all applications
+                       $packageList = new PackageList();
+                       $packageList->getConditionBuilder()->add('package.isApplication = ?', array(1));
+                       $packageList->readObjects();
+                       foreach ($packageList as $package) {
+                               $abbreviation = Package::getAbbreviation($package->package);
                                
-                               // Replace the variable xyz1_1 with $tablePrefix in the table names.
-                               $queries = StringUtil::replace($packageAbbr.'1_', $packageAbbr.$tablePrefix, $queries);
+                               $queries = StringUtil::replace($abbreviation.'1_', $abbreviation.WCF_N.'_', $queries);
                        }
                        
-                       // replace wcf1_ with the actual WCF_N value
-                       $queries = str_replace("wcf1_", "wcf".WCF_N."_", $queries);
-                       
                        // check queries
                        $parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction());
                        $conflicts = $parser->test();