2 namespace wcf\system\package\plugin
;
3 use wcf\data\application\Application
;
4 use wcf\data\package\Package
;
5 use wcf\system\package\PackageArchive
;
6 use wcf\system\package\TemplatesFileHandler
;
10 * Installs, updates and deletes templates.
12 * @author Alexander Ebert, Matthias Schmidt
13 * @copyright 2001-2014 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.package.plugin
17 * @category Community Framework
19 class TemplatePackageInstallationPlugin
extends AbstractPackageInstallationPlugin
{
21 * @see \wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
23 public $tableName = 'template';
26 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install()
28 public function install() {
31 $abbreviation = 'wcf';
32 if (isset($this->instruction
['attributes']['application'])) {
33 $abbreviation = $this->instruction
['attributes']['application'];
35 else if ($this->installation
->getPackage()->isApplication
) {
36 $abbreviation = Package
::getAbbreviation($this->installation
->getPackage()->package
);
39 // absolute path to package dir
40 $packageDir = Application
::getDirectory($abbreviation);
42 // extract files.tar to temp folder
43 $sourceFile = $this->installation
->getArchive()->extractTar($this->instruction
['value'], 'templates_');
45 // create file handler
46 $fileHandler = new TemplatesFileHandler($this->installation
, $abbreviation);
48 $this->installation
->extractFiles($packageDir.'templates/', $sourceFile, $fileHandler);
50 // delete temporary sourceArchive
55 * Uninstalls the templates of this package.
57 public function uninstall() {
58 // fetch templates from log
59 $sql = "SELECT template.templateName, template.application,
60 template_group.templateGroupFolderName
61 FROM wcf".WCF_N
."_template template
62 LEFT JOIN wcf".WCF_N
."_template_group template_group
63 ON (template_group.templateGroupID = template.templateGroupID)
65 $statement = WCF
::getDB()->prepareStatement($sql);
66 $statement->execute(array($this->installation
->getPackageID()));
69 while ($row = $statement->fetchArray()) {
70 if (!isset($templates[$row['application']])) {
71 $templates[$row['application']] = array();
74 $templates[$row['application']][] = 'templates/'.$row['templateGroupFolderName'].$row['templateName'].'.tpl';
77 foreach ($templates as $application => $templateNames) {
78 $this->installation
->deleteFiles(Application
::getDirectory($application), $templateNames, false, $this->installation
->getPackage()->isApplication
);
86 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::isValid()
88 public static function isValid(PackageArchive
$archive, $instruction) {
89 if (preg_match('~\.(tar(\.gz)?|tgz)$~', $instruction)) {
90 // check if file actually exists
92 if ($archive->getTar()->getIndexByFilename($instruction) === false) {
96 catch (\SystemException
$e) {