2 namespace wcf\acp\action
;
3 use wcf\action\AbstractDialogAction
;
4 use wcf\data\package\installation\queue\PackageInstallationQueue
;
5 use wcf\data\package\installation\queue\PackageInstallationQueueEditor
;
6 use wcf\data\package\Package
;
7 use wcf\system\exception\IllegalLinkException
;
8 use wcf\system\exception\SystemException
;
9 use wcf\system\package\PackageUninstallationDispatcher
;
11 use wcf\util\StringUtil
;
14 * Handles an AJAX-based package uninstallation.
16 * @author Alexander Ebert
17 * @copyright 2001-2011 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package com.woltlab.wcf
20 * @subpackage acp.action
21 * @category Community Framework
23 class UninstallPackageAction
extends InstallPackageAction
{
28 protected $packageID = 0;
31 * @see wcf\action\AbstractDialogAction::$templateName
33 public $templateName = 'packageUninstallationStep';
36 * @see wcf\action\IAction::readParameters()
38 public function readParameters() {
39 AbstractDialogAction
::readParameters();
41 if (isset($_POST['node'])) $this->node
= StringUtil
::trim($_POST['node']);
43 if (isset($_POST['packageID'])) {
44 $this->packageID
= intval($_POST['packageID']);
47 if (isset($_POST['queueID'])) $this->queueID
= intval($_POST['queueID']);
48 $this->queue
= new PackageInstallationQueue($this->queueID
);
50 if (!$this->queue
->queueID
) {
51 throw new IllegalLinkException();
54 $this->installation
= new PackageUninstallationDispatcher($this->queue
);
59 * Prepares the uninstallation process.
61 protected function stepPrepare() {
62 $package = new Package($this->packageID
);
63 if (!$package->packageID
) {
64 throw new IllegalLinkException();
68 $processNo = PackageInstallationQueue
::getNewProcessNo();
71 $queue = PackageInstallationQueueEditor
::create(array(
72 'processNo' => $processNo,
73 'userID' => WCF
::getUser()->userID
,
74 'packageName' => $package->getName(),
75 'packageID' => $package->packageID
,
76 'action' => 'uninstall',
80 // initialize uninstallation
81 $this->installation
= new PackageUninstallationDispatcher($queue);
83 $this->installation
->nodeBuilder
->purgeNodes();
84 $this->installation
->nodeBuilder
->buildNodes();
86 WCF
::getTPL()->assign(array(
90 $queueID = $this->installation
->nodeBuilder
->getQueueByNode($queue->processNo
, $this->installation
->nodeBuilder
->getNextNode());
92 'template' => WCF
::getTPL()->fetch($this->templateName
),
93 'step' => 'uninstall',
94 'node' => $this->installation
->nodeBuilder
->getNextNode(),
95 'currentAction' => WCF
::getLanguage()->get('wcf.package.installation.step.uninstalling'),
102 * Uninstalls node components and returns next node.
104 * @param string $node
107 public function stepUninstall() {
108 $node = $this->installation
->uninstall($this->node
);
112 $this->installation
->nodeBuilder
->purgeNodes();
113 $this->finalize($queueID);
115 // redirect to application if not already within one
116 if (PACKAGE_ID
== 1) {
117 // select first installed application
118 $sql = "SELECT packageID
119 FROM wcf".WCF_N
."_package
121 AND isApplication = 1
122 ORDER BY installDate ASC";
123 $statement = WCF
::getDB()->prepareStatement($sql, 1);
124 $statement->execute();
125 $row = $statement->fetchArray();
126 $packageID = ($row === false) ?
1 : $row['packageID'];
129 $packageID = PACKAGE_ID
;
133 $sql = "SELECT domainName, domainPath
134 FROM wcf".WCF_N
."_application
135 WHERE packageID = ?";
136 $statement = WCF
::getDB()->prepareStatement($sql);
137 $statement->execute(array($packageID));
138 $row = $statement->fetchArray();
140 // build redirect location
141 $location = $row['domainName'] . $row['domainPath'] . 'acp/index.php/PackageList/' . SID_ARG_1ST
;
146 'redirectLocation' => $location,
152 // continue with next node
153 $queueID = $this->installation
->nodeBuilder
->getQueueByNode($this->installation
->queue
->processNo
, $this->installation
->nodeBuilder
->getNextNode($this->node
));
155 'step' => 'uninstall',
157 'progress' => $this->installation
->nodeBuilder
->calculateProgress($this->node
),
158 'queueID' => $queueID
163 * @see wcf\action\AbstractDialogAction::validateStep()
165 protected function validateStep() {
166 switch ($this->step
) {
173 die(print_r($_POST, true));
174 throw new IllegalLinkException();