Commit | Line | Data |
---|---|---|
11ade432 AE |
1 | <?php |
2 | namespace wcf\system\package\plugin; | |
04727c8b | 3 | use wcf\data\application\Application; |
11ade432 | 4 | use wcf\data\package\Package; |
11ade432 | 5 | use wcf\system\package\FilesFileHandler; |
870b0938 | 6 | use wcf\system\package\PackageArchive; |
ec1b1daf | 7 | use wcf\system\package\PackageInstallationDispatcher; |
2bc9f31d | 8 | use wcf\system\WCF; |
11ade432 AE |
9 | use wcf\util\StyleUtil; |
10 | ||
11 | /** | |
a17de04e | 12 | * Installs, updates and deletes files. |
9f959ced | 13 | * |
04727c8b | 14 | * @author Matthias Schmidt, Marcel Werk |
ca4ba303 | 15 | * @copyright 2001-2014 WoltLab GmbH |
11ade432 AE |
16 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
17 | * @package com.woltlab.wcf | |
18 | * @subpackage system.package.plugin | |
9f959ced | 19 | * @category Community Framework |
11ade432 | 20 | */ |
2f7488d7 | 21 | class FilePackageInstallationPlugin extends AbstractPackageInstallationPlugin { |
b5be6fb0 | 22 | /** |
0ad90fc3 | 23 | * @see \wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName |
9f959ced | 24 | */ |
11ade432 AE |
25 | public $tableName = 'package_installation_file_log'; |
26 | ||
27 | /** | |
0ad90fc3 | 28 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install() |
11ade432 AE |
29 | */ |
30 | public function install() { | |
31 | parent::install(); | |
32 | ||
04727c8b MS |
33 | $abbreviation = 'wcf'; |
34 | if (isset($this->instruction['attributes']['application'])) { | |
35 | $abbreviation = $this->instruction['attributes']['application']; | |
36 | } | |
37 | else if ($this->installation->getPackage()->isApplication) { | |
38 | $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package); | |
39 | } | |
40 | ||
11ade432 | 41 | // absolute path to package dir |
04727c8b | 42 | $packageDir = Application::getDirectory($abbreviation); |
11ade432 AE |
43 | |
44 | // extract files.tar to temp folder | |
45 | $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'files_'); | |
46 | ||
47 | // create file handler | |
04727c8b | 48 | $fileHandler = new FilesFileHandler($this->installation, $abbreviation); |
11ade432 AE |
49 | |
50 | // extract content of files.tar | |
51 | $fileInstaller = $this->installation->extractFiles($packageDir, $sourceFile, $fileHandler); | |
52 | ||
aac1247e | 53 | // if this a an application, write config.inc.php for this package |
bb84d276 | 54 | if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install' && $abbreviation != 'wcf') { |
11ade432 AE |
55 | // touch file |
56 | $fileInstaller->touchFile(PackageInstallationDispatcher::CONFIG_FILE); | |
57 | ||
58 | // create file | |
59 | Package::writeConfigFile($this->installation->getPackageID()); | |
60 | ||
61 | // log file | |
62 | $sql = "INSERT INTO wcf".WCF_N."_package_installation_file_log | |
04727c8b MS |
63 | (packageID, filename, application) |
64 | VALUES (?, ?, ?)"; | |
11ade432 | 65 | $statement = WCF::getDB()->prepareStatement($sql); |
04727c8b MS |
66 | $statement->execute(array( |
67 | $this->installation->getPackageID(), | |
68 | 'config.inc.php', | |
69 | Package::getAbbreviation($this->installation->getPackage()->package) | |
70 | )); | |
8f8d8a38 AE |
71 | |
72 | // load application | |
73 | WCF::loadRuntimeApplication($this->installation->getPackageID()); | |
11ade432 AE |
74 | } |
75 | ||
76 | // delete temporary sourceArchive | |
77 | @unlink($sourceFile); | |
78 | ||
79 | // update acp style file | |
80 | StyleUtil::updateStyleFile(); | |
81 | } | |
82 | ||
83 | /** | |
0ad90fc3 | 84 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::uninstall() |
11ade432 AE |
85 | */ |
86 | public function uninstall() { | |
04727c8b MS |
87 | // fetch files from log |
88 | $sql = "SELECT filename, application | |
11ade432 | 89 | FROM wcf".WCF_N."_package_installation_file_log |
39bea7dd | 90 | WHERE packageID = ?"; |
11ade432 AE |
91 | $statement = WCF::getDB()->prepareStatement($sql); |
92 | $statement->execute(array($this->installation->getPackageID())); | |
04727c8b MS |
93 | |
94 | $files = array(); | |
11ade432 | 95 | while ($row = $statement->fetchArray()) { |
04727c8b MS |
96 | if (!isset($files[$row['application']])) { |
97 | $files[$row['application']] = array(); | |
98 | } | |
99 | ||
100 | $files[$row['application']][] = $row['filename']; | |
11ade432 AE |
101 | } |
102 | ||
04727c8b MS |
103 | foreach ($files as $application => $filenames) { |
104 | $this->installation->deleteFiles(Application::getDirectory($application), $filenames); | |
11ade432 AE |
105 | |
106 | // delete log entries | |
107 | parent::uninstall(); | |
108 | } | |
109 | } | |
870b0938 AE |
110 | |
111 | /** | |
112 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::isValid() | |
113 | */ | |
114 | public static function isValid(PackageArchive $archive, $instruction) { | |
115 | if (preg_match('~\.(tar(\.gz)?|tgz)$~', $instruction)) { | |
116 | // check if file actually exists | |
117 | try { | |
118 | if ($archive->getTar()->getIndexByFilename($instruction) === false) { | |
119 | return false; | |
120 | } | |
121 | } | |
122 | catch (\SystemException $e) { | |
123 | return false; | |
124 | } | |
125 | ||
126 | return true; | |
127 | } | |
128 | ||
129 | return false; | |
130 | } | |
11ade432 | 131 | } |