From e852aa82f145e6d4653ea683114b48431fcdec62 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 6 Dec 2012 22:26:42 +0100 Subject: [PATCH] Bunch of fixes and enhancements for package uninstallation --- wcfsetup/install/files/acp/js/WCF.ACP.js | 35 ++++++++++++- .../install/files/acp/templates/package.tpl | 4 +- .../acp/templates/packageListDetailed.tpl | 2 +- .../files/lib/data/package/Package.class.php | 49 +++++++------------ .../lib/data/package/PackageAction.class.php | 34 +++++++++++++ wcfsetup/install/lang/de.xml | 6 +++ 6 files changed, 94 insertions(+), 36 deletions(-) diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index c04083b562..641e336bd4 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -657,10 +657,41 @@ WCF.ACP.Package.Uninstallation = WCF.ACP.Package.Installation.extend({ _prepareQueue: function(event) { var $element = $(event.target); + if ($element.data('isRequired')) { + new WCF.Action.Proxy({ + autoSend: true, + data: { + actionName: 'getConfirmMessage', + className: 'wcf\\data\\package\\PackageAction', + objectIDs: [ $element.data('objectID') ] + }, + success: $.proxy(function(data, textStatus, jqXHR) { + // remove isRequired flag to prevent loading the same content again + $element.data('isRequired', false); + + // update confirmation message + $element.data('confirmMessage', data.returnValues.confirmMessage); + + // display confirmation dialog + this._showConfirmationDialog($element); + }, this) + }); + } + else { + this._showConfirmationDialog($element); + } + }, + + /** + * Displays a confirmation dialog prior to package uninstallation. + * + * @param jQuery element + */ + _showConfirmationDialog: function(element) { var self = this; - WCF.System.Confirmation.show($element.data('confirmMessage'), function(action) { + WCF.System.Confirmation.show(element.data('confirmMessage'), function(action) { if (action === 'confirm') { - self._packageID = $element.data('objectID'); + self._packageID = element.data('objectID'); self.prepareInstallation(); } }); diff --git a/wcfsetup/install/files/acp/templates/package.tpl b/wcfsetup/install/files/acp/templates/package.tpl index 42d731a5dc..78db50eb4c 100644 --- a/wcfsetup/install/files/acp/templates/package.tpl +++ b/wcfsetup/install/files/acp/templates/package.tpl @@ -135,7 +135,7 @@ {/if} {if $requiredPackage->canUninstall()} - + {else} {/if} @@ -195,7 +195,7 @@ {/if} {if $dependentPackage->canUninstall()} - + {else} {/if} diff --git a/wcfsetup/install/files/acp/templates/packageListDetailed.tpl b/wcfsetup/install/files/acp/templates/packageListDetailed.tpl index cc5ab073ad..bbdee27f26 100644 --- a/wcfsetup/install/files/acp/templates/packageListDetailed.tpl +++ b/wcfsetup/install/files/acp/templates/packageListDetailed.tpl @@ -63,7 +63,7 @@ {/if} {if $package->canUninstall()} - + {else} {/if} diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index 44993a77cb..baa60762ae 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -43,12 +43,6 @@ class Package extends DatabaseObject { */ protected $dependencies = null; - /** - * list of packages that require this package - * @var array - */ - protected $dependentPackages = null; - /** * installation directory * @var string @@ -119,31 +113,6 @@ class Package extends DatabaseObject { return $this->dependencies; } - /** - * Returns a list of all packages that require this package. - * Returns packages that require this package and packages that require these packages. - * - * @return array - */ - public function getDependentPackages() { - if ($this->dependentPackages === null) { - $this->dependentPackages = array(); - - $sql = "SELECT package.*, CASE WHEN instanceName <> '' THEN instanceName ELSE packageName END AS packageName - FROM wcf".WCF_N."_package_requirement package_requirement - LEFT JOIN wcf".WCF_N."_package package ON (package.packageID = package_requirement.packageID) - WHERE package_requirement.requirement = ? - ORDER BY packageName ASC"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($this->packageID)); - while ($package = $statement->fetchObject('wcf\data\package\Package')) { - $this->dependentPackages[$package->packageID] = $package; - } - } - - return $this->dependentPackages; - } - /** * Returns a list of the requirements of this package. * Contains the content of the tag in the package.xml of this package. @@ -192,6 +161,24 @@ class Package extends DatabaseObject { return true; } + /** + * Returns a list of packages dependent from current package. + * + * @return array + */ + public function getDependentPackages() { + self::loadRequirementMap(); + + $packages = array(); + if (isset(self::$requirementMap[$this->packageID])) { + foreach (self::$requirementMap[$this->packageID] as $packageID) { + $packages[$packageID] = PackageCache::getInstance()->getPackage($packageID); + } + } + + return $packages; + } + /** * Returns true, if package $packageID is required by package $targetPackageID. * diff --git a/wcfsetup/install/files/lib/data/package/PackageAction.class.php b/wcfsetup/install/files/lib/data/package/PackageAction.class.php index 92a132b523..e509cf2db0 100644 --- a/wcfsetup/install/files/lib/data/package/PackageAction.class.php +++ b/wcfsetup/install/files/lib/data/package/PackageAction.class.php @@ -1,5 +1,7 @@ WCF::getTPL()->fetch('packageListPlugins') ); } + + /** + * Validates parameters to return the confirm message for package uninstallation. + */ + public function validateGetConfirmMessage() { + WCF::getSession()->checkPermissions($this->permissionsUpdate); + + $this->packageEditor = $this->getSingleObject(); + if (!$this->packageEditor->canUninstall()) { + throw new PermissionDeniedException(); + } + } + + /** + * Returns the confirm message for package uninstallation. + * + * @return array + */ + public function getConfirmMessage() { + return array( + 'confirmMessage' => WCF::getLanguage()->getDynamicVariable('wcf.acp.package.uninstallation.confirmDependentPackages', array( + 'package' => $this->packageEditor->getDecoratedObject(), + 'showDependentPackages' => true + )) + ); + } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 919f047536..1fbd32a0b5 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -393,6 +393,12 @@ getName()}“ wirklich deinstallieren?]]> + getName()}“ wirklich deinstallieren? Beachten Sie bitte, dass die folgenden Pakete ebenfalls deinstalliert werden: +
    + {foreach from=$package->getDependentPackages() as $dependentPackage} +
  • {$dependentPackage}
  • + {/foreach} +
]]>
-- 2.20.1