From a45fa84d07268d8bdf962604260a49429bb25589 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 1 Jun 2013 21:49:56 +0200 Subject: [PATCH] Adds possibility to cancel installation Closes #1078 --- wcfsetup/install/files/acp/js/WCF.ACP.js | 27 ++++++++++ .../templates/packageInstallationConfirm.tpl | 5 +- .../PackageInstallationQueueAction.class.php | 53 +++++++++++++++++-- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 6fc46c28ed..e508dde145 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -655,6 +655,33 @@ WCF.ACP.Package.Installation = Class.extend({ } }); +/** + * Handles canceling the package installation at the package installation + * confirm page. + */ +WCF.ACP.Package.Installation.Cancel = Class.extend({ + /** + * Creates a new instance of WCF.ACP.Package.Installation.Cancel. + * + * @param integer queueID + */ + init: function(queueID) { + $('#backButton').click(function() { + new WCF.Action.Proxy({ + autoSend: true, + data: { + actionName: 'cancelInstallation', + className: 'wcf\\data\\package\\installation\\queue\\PackageInstallationQueueAction', + objectIDs: [ queueID ] + }, + success: function(data) { + window.location = data.returnValues.url; + } + }); + }); + } +}); + /** * Provides the package uninstallation. * diff --git a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl index 6c0a13d042..4f7574bc9c 100644 --- a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl +++ b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl @@ -10,7 +10,10 @@ 'wcf.acp.package.uninstallation.title': '{lang}wcf.acp.package.uninstallation.title{/lang}', 'wcf.acp.package.update.title': '{lang}wcf.acp.package.update.title{/lang}' }); + new WCF.ACP.Package.Installation({@$queue->queueID}, undefined, {if $queue->action == 'install'}true, false{else}false, true{/if}); + + new WCF.ACP.Package.Installation.Cancel({@$queue->queueID}); }); //]]> @@ -114,7 +117,7 @@ {/if}
- {* @todo: *} + {if $missingPackages == 0 && $excludingPackages|count == 0 && $excludedPackages|count == 0} {/if} diff --git a/wcfsetup/install/files/lib/data/package/installation/queue/PackageInstallationQueueAction.class.php b/wcfsetup/install/files/lib/data/package/installation/queue/PackageInstallationQueueAction.class.php index 30a0574ab9..31658c8c21 100644 --- a/wcfsetup/install/files/lib/data/package/installation/queue/PackageInstallationQueueAction.class.php +++ b/wcfsetup/install/files/lib/data/package/installation/queue/PackageInstallationQueueAction.class.php @@ -2,7 +2,9 @@ namespace wcf\data\package\installation\queue; use wcf\data\package\Package; use wcf\data\AbstractDatabaseObjectAction; +use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; +use wcf\system\request\LinkHandler; use wcf\system\WCF; /** @@ -17,15 +19,21 @@ use wcf\system\WCF; */ class PackageInstallationQueueAction extends AbstractDatabaseObjectAction { /** - * package the prepared queue belongs to - * @var wcf\data\package\Package + * @see wcf\data\AbstractDatabaseObjectAction::$className */ - protected $package = null; + protected $className = 'wcf\data\package\installation\queue\PackageInstallationQueueEditor'; /** - * @see wcf\data\AbstractDatabaseObjectAction::$className + * queue of the canceled installation + * @var wcf\data\package\installation\queue\PackageInstallationQueueEditor */ - protected $className = 'wcf\data\package\installation\queue\PackageInstallationQueueEditor'; + protected $queue = null; + + /** + * package the prepared queue belongs to + * @var wcf\data\package\Package + */ + protected $package = null; /** * Validates the 'prepareQueue' action: @@ -65,4 +73,39 @@ class PackageInstallationQueueAction extends AbstractDatabaseObjectAction { 'queueID' => $queue->queueID ); } + + /** + * Validates the 'cancelInstallation' action. + */ + public function validateCancelInstallation() { + // check permissions + WCF::getSession()->checkPermissions(array('admin.system.package.canInstallPackage')); + + // validate queue + $this->queue = $this->getSingleObject(); + if ($this->queue->parentQueueID || $this->queue->action != 'install' || $this->queue->done) { + throw new UserInputException('objectIDs'); + } + + // todo: do confirmInstallation and packageType need validation? + // see https://github.com/WoltLab/WCF/issues/1329 + // see https://github.com/WoltLab/WCF/issues/1330 + + if ($this->queue->userID != WCF::getUser()->userID) { + throw new PermissionDeniedException(); + } + } + + /** + * Cancels a certain installation. + */ + public function cancelInstallation() { + @unlink($this->queue->archive); + + $this->queue->delete(); + + return array( + 'url' => LinkHandler::getInstance()->getLink('PackageList') + ); + } } -- 2.20.1