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\PackageArchive
;
7 use wcf\system\package\PackageInstallationDispatcher
;
9 use wcf\util\StyleUtil
;
12 * Installs, updates and deletes files.
14 * @author Matthias Schmidt, Marcel Werk
15 * @copyright 2001-2014 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package com.woltlab.wcf
18 * @subpackage system.package.plugin
19 * @category Community Framework
21 class FilePackageInstallationPlugin
extends AbstractPackageInstallationPlugin
{
23 * @see \wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
25 public $tableName = 'package_installation_file_log';
28 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install()
30 public function install() {
33 $abbreviation = 'wcf';
34 if (isset($this->instruction
['attributes']['application'])) {
35 $abbreviation = $this->instruction
['attributes']['application'];
37 else if ($this->installation
->getPackage()->isApplication
) {
38 $abbreviation = Package
::getAbbreviation($this->installation
->getPackage()->package
);
41 // absolute path to package dir
42 $packageDir = Application
::getDirectory($abbreviation);
44 // extract files.tar to temp folder
45 $sourceFile = $this->installation
->getArchive()->extractTar($this->instruction
['value'], 'files_');
47 // create file handler
48 $fileHandler = new FilesFileHandler($this->installation
, $abbreviation);
50 // extract content of files.tar
51 $fileInstaller = $this->installation
->extractFiles($packageDir, $sourceFile, $fileHandler);
53 // if this a an application, write config.inc.php for this package
54 if ($this->installation
->getPackage()->isApplication
== 1 && $this->installation
->getPackage()->package
!= 'com.woltlab.wcf' && $this->installation
->getAction() == 'install' && $abbreviation != 'wcf') {
56 $fileInstaller->touchFile(PackageInstallationDispatcher
::CONFIG_FILE
);
59 Package
::writeConfigFile($this->installation
->getPackageID());
62 $sql = "INSERT INTO wcf".WCF_N
."_package_installation_file_log
63 (packageID, filename, application)
65 $statement = WCF
::getDB()->prepareStatement($sql);
66 $statement->execute(array(
67 $this->installation
->getPackageID(),
69 Package
::getAbbreviation($this->installation
->getPackage()->package
)
73 WCF
::loadRuntimeApplication($this->installation
->getPackageID());
76 // delete temporary sourceArchive
79 // update acp style file
80 StyleUtil
::updateStyleFile();
84 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
86 public function uninstall() {
87 // fetch files from log
88 $sql = "SELECT filename, application
89 FROM wcf".WCF_N
."_package_installation_file_log
91 $statement = WCF
::getDB()->prepareStatement($sql);
92 $statement->execute(array($this->installation
->getPackageID()));
95 while ($row = $statement->fetchArray()) {
96 if (!isset($files[$row['application']])) {
97 $files[$row['application']] = array();
100 $files[$row['application']][] = $row['filename'];
103 foreach ($files as $application => $filenames) {
104 $this->installation
->deleteFiles(Application
::getDirectory($application), $filenames);
106 // delete log entries
112 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::isValid()
114 public static function isValid(PackageArchive
$archive, $instruction) {
115 if (preg_match('~\.(tar(\.gz)?|tgz)$~', $instruction)) {
116 // check if file actually exists
118 if ($archive->getTar()->getIndexByFilename($instruction) === false) {
122 catch (\SystemException
$e) {