From ffdf6f147d1a6907f6b97470c69461e9c91c1430 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 23 Feb 2012 20:35:37 +0100 Subject: [PATCH] Added possibility to prompt user during PIP execution --- .../form/element/LabelFormElement.class.php | 5 +- .../PackageInstallationDispatcher.class.php | 17 +++++-- .../PackageInstallationSQLParser.class.php | 8 ++-- .../SQLPackageInstallationPlugin.class.php | 48 ++++++++++++++++++- wcfsetup/install/lang/de.xml | 4 ++ wcfsetup/install/lang/en.xml | 4 ++ 6 files changed, 73 insertions(+), 13 deletions(-) diff --git a/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php b/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php index 2e8046c559..e78ab587d8 100644 --- a/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php +++ b/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php @@ -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 <<getErrorClass()}> +
{$this->getText()} {$this->getDescription()} - {$this->getErrorField()}
HTML; diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 0fb67211ba..dd24daf769 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -1,5 +1,7 @@ {$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) { diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php index 8236e6aa90..4b61455749 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php @@ -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; } } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php index 355efdfdbc..cdb12ff120 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php @@ -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('
', $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('
', $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')) { diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 9949a0bb4d..6554f60983 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -284,6 +284,10 @@ + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index f15b345af6..b6214225b7 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -284,6 +284,10 @@ + + + + -- 2.20.1