* Handles the whole uninstallation process.
*
* @author Alexander Ebert
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.package
* @category Community Framework
*/
class PackageUninstallationDispatcher extends PackageInstallationDispatcher {
+ /**
+ * is true if the package's uninstall script has been executed or if no
+ * such script exists
+ * @var boolean
+ */
+ protected $didExecuteUninstallScript = false;
+
/**
* Creates a new instance of PackageUninstallationDispatcher.
*
- * @param \wcf\data\package\installation\queue\PackageInstallationQueue $queue
+ * @param PackageInstallationQueue $queue
*/
public function __construct(PackageInstallationQueue $queue) {
$this->queue = $queue;
break;
case 'pip':
+ // the file pip is always executed last, thus, just before it,
+ // execute the uninstall script
+ if ($nodeData['pluginName'] == 'file' && !$this->didExecuteUninstallScript) {
+ $this->executeUninstallScript();
+
+ $this->didExecuteUninstallScript = true;
+ }
+
$this->executePIP($nodeData);
break;
}
}
/**
- * @see \wcf\system\package\PackageInstallationDispatcher::executePIP()
+ * @inheritDoc
*/
protected function executePIP(array $nodeData) {
$pip = new $nodeData['className']($this);
$pip->uninstall();
}
+ /**
+ * Executes the package's uninstall script (if existing).
+ *
+ * @since 2.2
+ */
+ protected function executeUninstallScript() {
+ // check if uninstall script file for the uninstalled package exists
+ $uninstallScript = WCF_DIR.'acp/uninstall/'.$this->package->package.'.php';
+ if (file_exists($uninstallScript)) {
+ include($uninstallScript);
+ }
+ }
+
/**
* Uninstalls current package.
*
* @param array $nodeData
*/
protected function uninstallPackage(array $nodeData) {
- PackageEditor::deleteAll(array($this->queue->packageID));
+ PackageEditor::deleteAll([$this->queue->packageID]);
// remove localized package infos
// todo: license/readme
$sql = "DELETE FROM wcf".WCF_N."_language_item
WHERE languageItem IN (?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute(array(
+ $statement->execute([
'wcf.acp.package.packageName.package'.$this->queue->packageID,
'wcf.acp.package.packageDescription.package'.$this->queue->packageID
- ));
+ ]);
// reset package cache
PackageCacheBuilder::getInstance()->reset();
throw new IllegalLinkException();
}
- $dependentPackages = array();
+ $dependentPackages = [];
$uninstallAvailable = true;
if ($package->isRequired()) {
// get packages that requires this package
* @param Package $package
* @param array $packages
*/
- public static function addQueueEntries(Package $package, $packages = array()) {
+ public static function addQueueEntries(Package $package, $packages = []) {
// get new process no
$processNo = PackageInstallationQueue::getNewProcessNo();
// add dependent packages to queue
- $statementParameters = array();
+ $statementParameters = [];
foreach ($packages as $dependentPackage) {
- $statementParameters[] = array(
+ $statementParameters[] = [
'packageName' => $dependentPackage['packageName'],
'packageID' => $dependentPackage['packageID']
- );
+ ];
}
// add uninstalling package to queue
- $statementParameters[] = array(
+ $statementParameters[] = [
'packageName' => $package->getName(),
'packageID' => $package->packageID
- );
+ ];
// insert queue entry (entries)
$sql = "INSERT INTO wcf".WCF_N."_package_installation_queue
VALUES (?, ?, ?, ?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
foreach ($statementParameters as $parameter) {
- $statement->execute(array(
+ $statement->execute([
$processNo,
WCF::getUser()->userID,
$parameter['packageName'],
$parameter['packageID'],
'uninstall'
- ));
+ ]);
}
self::openQueue(0, $processNo);