Adds possibility to cancel installation
authorMatthias Schmidt <gravatronics@live.com>
Sat, 1 Jun 2013 19:49:56 +0000 (21:49 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 1 Jun 2013 19:49:56 +0000 (21:49 +0200)
Closes #1078

wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl
wcfsetup/install/files/lib/data/package/installation/queue/PackageInstallationQueueAction.class.php

index 6fc46c28ed7ca16dffb67f2d3da0ac95bdb2ae76..e508dde145ab700b98cf4f137d25c8fadf815c2e 100644 (file)
@@ -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.
  * 
index 6c0a13d0429c51710e2e22d895d13df55ebb78ac..4f7574bc9c51a0edc480173db0292c7bd2e697c9 100644 (file)
                        '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});
        });
        //]]>
 </script>
 {/if}
 
 <div class="formSubmit">
-       {* @todo: <input type="button" onclick="document.location.href=fixURL('{link controller='Package'}action={@$action}&queueID={@$queue->queueID}&step=cancel{/link}')" value="{lang}wcf.global.button.back{/lang}" accesskey="c" />*}
+       <input type="button" id="backButton" value="{lang}wcf.global.button.back{/lang}" accesskey="c" />
        {if $missingPackages == 0 && $excludingPackages|count == 0 && $excludedPackages|count == 0}
                <input type="button" class="buttonPrimary" id="submitButton" value="{lang}wcf.global.button.next{/lang}" class="default" accesskey="s" />
        {/if}
index 30a0574ab98a3a85c87d52909047ab9937a30c98..31658c8c2104ff208dc646dcaf8830862aecd742 100644 (file)
@@ -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')
+               );
+       }
 }