Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / package / plugin / TemplatePackageInstallationPlugin.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\TemplatesFileHandler;
6 use wcf\system\WCF;
7
8 /**
9 * Installs, updates and deletes 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 TemplatePackageInstallationPlugin extends AbstractPackageInstallationPlugin {
19 /**
20 * @see \wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
21 */
22 public $tableName = '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'], 'templates_');
43
44 // create file handler
45 $fileHandler = new TemplatesFileHandler($this->installation, $abbreviation);
46
47 $this->installation->extractFiles($packageDir.'templates/', $sourceFile, $fileHandler);
48
49 // delete temporary sourceArchive
50 @unlink($sourceFile);
51 }
52
53 /**
54 * Uninstalls the templates of this package.
55 */
56 public function uninstall() {
57 // fetch templates from log
58 $sql = "SELECT template.templateName, template.application,
59 template_group.templateGroupFolderName
60 FROM wcf".WCF_N."_template template
61 LEFT JOIN wcf".WCF_N."_template_group template_group
62 ON (template_group.templateGroupID = template.templateGroupID)
63 WHERE packageID = ?";
64 $statement = WCF::getDB()->prepareStatement($sql);
65 $statement->execute(array($this->installation->getPackageID()));
66
67 $templates = array();
68 while ($row = $statement->fetchArray()) {
69 if (!isset($templates[$row['application']])) {
70 $templates[$row['application']] = array();
71 }
72
73 $templates[$row['application']][] = 'templates/'.$row['templateGroupFolderName'].$row['templateName'].'.tpl';
74 }
75
76 foreach ($templates as $application => $templateNames) {
77 $this->installation->deleteFiles(Application::getDirectory($application), $templateNames, false, $this->installation->getPackage()->isApplication);
78
79 // delete log entries
80 parent::uninstall();
81 }
82 }
83 }