Added possibility to prompt user during PIP execution
authorAlexander Ebert <ebert@woltlab.com>
Thu, 23 Feb 2012 19:35:37 +0000 (20:35 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 23 Feb 2012 19:35:37 +0000 (20:35 +0100)
wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php
wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 2e8046c5599a005241eb9a1e7f6edfd9143097cf..e78ab587d895f1e51637721ae1c73762bac33b98 100644 (file)
@@ -25,7 +25,7 @@ class LabelFormElement extends AbstractFormElement {
         * @param       string          $text
         */
        public function setText($text) {
-               $text->text = StringUtil::trim($text);
+               $this->text = StringUtil::trim($text);
        }
        
        /**
@@ -42,12 +42,11 @@ class LabelFormElement extends AbstractFormElement {
         */
        public function getHTML($formName) {
                return <<<HTML
-<dl{$this->getErrorClass()}>
+<dl>
        <dt><label>{$this->getLabel()}</label></dt>
        <dd>
                {$this->getText()}
                <small>{$this->getDescription()}</small>
-               {$this->getErrorField()}
        </dd>
 </dl>
 HTML;
index 0fb67211badc3b0a804bf6124a5129a505b23cd8..dd24daf769af977c0e3251f45cdf564efb0fc0e3 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\package;
+use wcf\system\form\FormDocument;
+
 use wcf\data\application\Application;
 use wcf\data\application\ApplicationEditor;
 use wcf\data\language\LanguageEditor;
@@ -302,11 +304,11 @@ class PackageInstallationDispatcher {
        /**
         * Executes a package installation plugin.
         *
-        * @param       array           $nodeData
+        * @param       array           step
         * @return      boolean
         */
        protected function executePIP(array $nodeData) {
-               $installationStep = new PackageInstallationStep();
+               $step = new PackageInstallationStep();
                
                // fetch all pips associated with current PACKAGE_ID and include pips
                // previously installed by current installation queue
@@ -338,13 +340,18 @@ class PackageInstallationDispatcher {
                
                // execute PIP
                try {
-                       $plugin->{$this->action}();
+                       $document = $plugin->{$this->action}();
                }
                catch (SplitNodeException $e) {
-                       $installationStep->setSplitNode();
+                       $step->setSplitNode();
                }
                
-               return $installationStep;
+               if ($document !== null && ($document instanceof FormDocument)) {
+                       $step->setDocument($document);
+                       $step->setSplitNode();
+               }
+               
+               return $step;
        }
        
        protected function selectOptionalPackages($currentNode, array $nodeData) {
index 8236e6aa90e038ebfe6ffb2af721296d113207af..4b6145574973e28a02c5ff132b271797fe920824 100644 (file)
@@ -286,8 +286,8 @@ class PackageInstallationSQLParser extends SQLParser {
                                        }
                                }
                                else {
-                                       if (!isset($this->conflicts[$tableName])) $this->conflicts[$tableName] = array();
-                                       $this->conflicts[$tableName][] = 'CREATE TABLE';
+                                       if (!isset($this->conflicts['CREATE TABLE'])) $this->conflicts['CREATE TABLE'] = array();
+                                       $this->conflicts['CREATE TABLE'][] = $tableName;
                                }
                        }
                }
@@ -435,8 +435,8 @@ class PackageInstallationSQLParser extends SQLParser {
                                        }
                                }
                                else {
-                                       if (!isset($this->conflicts[$tableName])) $this->conflicts[$tableName] = array();
-                                       $this->conflicts[$tableName][] = 'DROP TABLE';
+                                       if (!isset($this->conflicts['DROP TABLE'])) $this->conflicts['DROP TABLE'] = array();
+                                       $this->conflicts['DROP TABLE'][] = $tableName;
                                }
                        }
                }
index 355efdfdbc554c885822d50fb413ef2ee7fae09b..cdb12ff1203a79b8b681bf975e57b29d943b5101 100644 (file)
@@ -2,6 +2,10 @@
 namespace wcf\system\package\plugin;
 use wcf\data\package\Package;
 use wcf\system\exception\SystemException;
+use wcf\system\form\container\GroupFormElementContainer;
+use wcf\system\form\element\LabelFormElement;
+use wcf\system\form\FormDocument;
+use wcf\system\package\PackageInstallationFormManager;
 use wcf\system\package\PackageInstallationSQLParser;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
@@ -51,7 +55,49 @@ class SQLPackageInstallationPlugin extends AbstractPackageInstallationPlugin {
                        // check queries
                        $parser = new PackageInstallationSQLParser($queries, $package, $this->installation->getAction());
                        $conflicts = $parser->test();
-                       if (count($conflicts)) {
+                       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')) {
index 9949a0bb4df2a73c157a5bcf6e90ef145b287c5a..6554f60983ec0583c62a13a013eed35c40061f4c 100644 (file)
                <item name="wcf.acp.package.dependencies.required.description"><![CDATA[Pakete die zwingend für den Betrieb dieses Paketes benötigt werden]]></item>
                <item name="wcf.acp.package.dependencies.title"><![CDATA[Abhängigkeiten]]></item>
                <item name="wcf.acp.package.description"><![CDATA[Beschreibung]]></item>
+               <item name="wcf.acp.package.error.sql.createTable"><![CDATA[Existierende Tabellen überschreiben]]></item>
+               <item name="wcf.acp.package.error.sql.createTable.description"><![CDATA[Die oben genannten Tabellen existieren bereits und werden beim fortfahren der Installation überschrieben. Alle Daten dieser Tabellen gehen unwiderruflich verloren.]]></item>
+               <item name="wcf.acp.package.error.sql.dropTable"><![CDATA[Existierende Tabellen löschen]]></item>
+               <item name="wcf.acp.package.error.sql.dropTable.description"><![CDATA[Die oben genannten Tabellen existieren bereits und werden beim fortfahren der Installation entfernt. Alle Daten dieser Tabellen gehen unwiderruflich verloren.]]></item>
                <item name="wcf.acp.package.identifier"><![CDATA[Bezeichner]]></item>
                <item name="wcf.acp.package.information.properties"><![CDATA[Eigenschaften]]></item>
                <item name="wcf.acp.package.information.title"><![CDATA[Informationen]]></item>
index f15b345af6585127127028002819aaa5ac314b0e..b6214225b7f202c43e33692642f13625824c8da5 100644 (file)
                <item name="wcf.acp.package.dependencies.required.description"><![CDATA[Packages required for this package to work]]></item>
                <item name="wcf.acp.package.dependencies.title"><![CDATA[Dependencies]]></item>
                <item name="wcf.acp.package.description"><![CDATA[Description]]></item>
+               <item name="wcf.acp.package.error.sql.createTable"><![CDATA[Overwrite existing tables]]></item>
+               <item name="wcf.acp.package.error.sql.createTable.description"><![CDATA[The tables above will be overwritten once you continue the installation process. All data contained in these tables will be lost.]]></item>
+               <item name="wcf.acp.package.error.sql.dropTable"><![CDATA[Remove existing tables]]></item>
+               <item name="wcf.acp.package.error.sql.dropTable.description"><![CDATA[The tables above will be removed once you continue the installation process. All data contained in these tables will be lost.]]></item>
                <item name="wcf.acp.package.identifier"><![CDATA[Identifier]]></item>
                <item name="wcf.acp.package.information.properties"><![CDATA[Properties]]></item>
                <item name="wcf.acp.package.information.title"><![CDATA[Informations]]></item>