コード例 #1
0
 /**
  * @see	\wcf\system\package\plugin\IPackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     // extract sql file from archive
     if ($queries = $this->getSQL($this->instruction['value'])) {
         $package = $this->installation->getPackage();
         // 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);
             $queries = str_replace($abbreviation . '1_', $abbreviation . WCF_N . '_', $queries);
         }
         // check queries
         $parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction());
         $conflicts = $parser->test();
         if (!empty($conflicts) && (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE']))) {
             $unknownCreateTable = isset($conflicts['CREATE TABLE']) ? $conflicts['CREATE TABLE'] : array();
             $unknownDropTable = isset($conflicts['DROP TABLE']) ? $conflicts['DROP TABLE'] : array();
             $errorMessage = "Can't";
             if (!empty($unknownDropTable)) {
                 $errorMessage .= " drop unknown table";
                 if (count($unknownDropTable) > 1) {
                     $errorMessage .= "s";
                 }
                 $errorMessage .= " '" . implode("', '", $unknownDropTable) . "'";
             }
             if (!empty($unknownCreateTable)) {
                 if (!empty($unknownDropTable)) {
                     $errorMessage .= " and can't";
                 }
                 $errorMessage .= " overwrite unknown table";
                 if (count($unknownCreateTable) > 1) {
                     $errorMessage .= "s";
                 }
                 $errorMessage .= " '" . implode("', '", $unknownCreateTable) . "'";
             }
             throw new SystemException($errorMessage);
         }
         // execute queries
         $parser->execute();
         // log changes
         $parser->log();
     }
 }
コード例 #2
0
 /**
  * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     // extract sql file from archive
     if ($queries = $this->getSQL($this->instruction['value'])) {
         $package = $this->installation->getPackage();
         if ($package->parentPackageID) {
             // package is a plugin; get parent package
             $package = $package->getParentPackage();
         }
         if ($package->isApplication == 1) {
             // package is application
             $packageAbbr = Package::getAbbreviation($package->package);
             $tablePrefix = WCF_N . '_' . $package->instanceNo . '_';
             // Replace the variable xyz1_1 with $tablePrefix in the table names.
             $queries = StringUtil::replace($packageAbbr . '1_1_', $packageAbbr . $tablePrefix, $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();
         if (!empty($conflicts)) {
             if (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE'])) {
                 if (!PackageInstallationFormManager::findForm($this->installation->queue, 'overwriteDatabaseTables')) {
                     $container = new GroupFormElementContainer();
                     if (isset($conflicts['CREATE TABLE'])) {
                         $text = implode('<br />', $conflicts['CREATE TABLE']);
                         $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable');
                         $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable.description');
                         $element = new LabelFormElement($container);
                         $element->setLabel($label);
                         $element->setText($text);
                         $element->setDescription($description);
                         $container->appendChild($element);
                     }
                     if (isset($conflicts['DROP TABLE'])) {
                         $text = implode('<br />', $conflicts['DROP TABLE']);
                         $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable');
                         $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable.description');
                         $element = new LabelFormElement($container);
                         $element->setLabel($label);
                         $element->setText($text);
                         $element->setDescription($description);
                         $container->appendChild($element);
                     }
                     $document = new FormDocument('overwriteDatabaseTables');
                     $document->appendContainer($container);
                     PackageInstallationFormManager::registerForm($this->installation->queue, $document);
                     return $document;
                 } else {
                     /*
                      * At this point the user decided to continue the installation (he would called the rollback
                      * otherwise), thus we do not care about the form anymore
                      */
                 }
             }
             // ask user here
             // search default value in session
             if (!WCF::getSession()->getVar('overrideAndDontAskAgain')) {
                 // show page
                 if (!empty($_POST['override']) || !empty($_POST['overrideAndDontAskAgain'])) {
                     if (!empty($_POST['overrideAndDontAskAgain'])) {
                         WCF::getSession()->register('overrideAndDontAskAgain', true);
                         WCF::getSession()->update();
                     }
                 } else {
                     WCF::getTPL()->assign('conflicts', $conflicts);
                     WCF::getTPL()->display('packageInstallationCheckOverrideTables');
                     exit;
                 }
             }
         }
         // execute queries
         $parser->execute();
         // log changes
         $parser->log();
     }
 }