Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / package / plugin / FilePackageInstallationPlugin.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\FilesFileHandler;
6 use wcf\system\package\PackageInstallationDispatcher;
7 use wcf\system\WCF;
8 use wcf\util\StyleUtil;
9
10 /**
11 * Installs, updates and deletes files.
12 *
13 * @author Matthias Schmidt, Marcel Werk
14 * @copyright 2001-2014 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage system.package.plugin
18 * @category Community Framework
19 */
20 class FilePackageInstallationPlugin extends AbstractPackageInstallationPlugin {
21 /**
22 * @see \wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
23 */
24 public $tableName = 'package_installation_file_log';
25
26 /**
27 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install()
28 */
29 public function install() {
30 parent::install();
31
32 $abbreviation = 'wcf';
33 if (isset($this->instruction['attributes']['application'])) {
34 $abbreviation = $this->instruction['attributes']['application'];
35 }
36 else if ($this->installation->getPackage()->isApplication) {
37 $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package);
38 }
39
40 // absolute path to package dir
41 $packageDir = Application::getDirectory($abbreviation);
42
43 // extract files.tar to temp folder
44 $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'files_');
45
46 // create file handler
47 $fileHandler = new FilesFileHandler($this->installation, $abbreviation);
48
49 // extract content of files.tar
50 $fileInstaller = $this->installation->extractFiles($packageDir, $sourceFile, $fileHandler);
51
52 // if this a an application, write config.inc.php for this package
53 if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install' && $abbreviation != 'wcf') {
54 // touch file
55 $fileInstaller->touchFile(PackageInstallationDispatcher::CONFIG_FILE);
56
57 // create file
58 Package::writeConfigFile($this->installation->getPackageID());
59
60 // log file
61 $sql = "INSERT INTO wcf".WCF_N."_package_installation_file_log
62 (packageID, filename, application)
63 VALUES (?, ?, ?)";
64 $statement = WCF::getDB()->prepareStatement($sql);
65 $statement->execute(array(
66 $this->installation->getPackageID(),
67 'config.inc.php',
68 Package::getAbbreviation($this->installation->getPackage()->package)
69 ));
70
71 // load application
72 WCF::loadRuntimeApplication($this->installation->getPackageID());
73 }
74
75 // delete temporary sourceArchive
76 @unlink($sourceFile);
77
78 // update acp style file
79 StyleUtil::updateStyleFile();
80 }
81
82 /**
83 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
84 */
85 public function uninstall() {
86 // fetch files from log
87 $sql = "SELECT filename, application
88 FROM wcf".WCF_N."_package_installation_file_log
89 WHERE packageID = ?";
90 $statement = WCF::getDB()->prepareStatement($sql);
91 $statement->execute(array($this->installation->getPackageID()));
92
93 $files = array();
94 while ($row = $statement->fetchArray()) {
95 if (!isset($files[$row['application']])) {
96 $files[$row['application']] = array();
97 }
98
99 $files[$row['application']][] = $row['filename'];
100 }
101
102 foreach ($files as $application => $filenames) {
103 $this->installation->deleteFiles(Application::getDirectory($application), $filenames);
104
105 // delete log entries
106 parent::uninstall();
107 }
108 }
109 }