Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / package / plugin / ACPTemplatePackageInstallationPlugin.class.php
1 <?php
2 namespace wcf\system\package\plugin;
3 use wcf\data\application\Application;
4 use wcf\data\package\Package;
5 use wcf\system\package\ACPTemplatesFileHandler;
6 use wcf\system\WCF;
7
8 /**
9 * Installs, updates and deletes ACP templates.
10 *
11 * @author Alexander Ebert, Matthias Schmidt
12 * @copyright 2001-2014 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf
15 * @subpackage system.package.plugin
16 * @category Community Framework
17 */
18 class ACPTemplatePackageInstallationPlugin extends AbstractPackageInstallationPlugin {
19 /**
20 * @see \wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
21 */
22 public $tableName = 'acp_template';
23
24 /**
25 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install()
26 */
27 public function install() {
28 parent::install();
29
30 $abbreviation = 'wcf';
31 if (isset($this->instruction['attributes']['application'])) {
32 $abbreviation = $this->instruction['attributes']['application'];
33 }
34 else if ($this->installation->getPackage()->isApplication) {
35 $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package);
36 }
37
38 // absolute path to package dir
39 $packageDir = Application::getDirectory($abbreviation);
40
41 // extract files.tar to temp folder
42 $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'acptemplates_');
43
44 // create file handler
45 $fileHandler = new ACPTemplatesFileHandler($this->installation, $abbreviation);
46
47 // extract templates
48 $this->installation->extractFiles($packageDir.'acp/templates/', $sourceFile, $fileHandler);
49
50 // delete temporary sourceArchive
51 @unlink($sourceFile);
52 }
53
54 /**
55 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
56 */
57 public function uninstall() {
58 // fetch ACP templates from log
59 $sql = "SELECT templateName, application
60 FROM wcf".WCF_N."_acp_template
61 WHERE packageID = ?";
62 $statement = WCF::getDB()->prepareStatement($sql);
63 $statement->execute(array($this->installation->getPackageID()));
64
65 $templates = array();
66 while ($row = $statement->fetchArray()) {
67 if (!isset($templates[$row['application']])) {
68 $templates[$row['application']] = array();
69 }
70
71 $templates[$row['application']][] = 'acp/templates/'.$row['templateName'].'.tpl';
72 }
73
74 foreach ($templates as $application => $templateNames) {
75 $this->installation->deleteFiles(Application::getDirectory($application), $templateNames, false, $this->installation->getPackage()->isApplication);
76
77 // delete log entries
78 parent::uninstall();
79 }
80 }
81 }