2 namespace wcf\system\package
;
3 use wcf\data\package\Package
;
4 use wcf\system\database\util\PreparedStatementConditionBuilder
;
5 use wcf\system\exception\SystemException
;
9 * File handler implementation for the installation of ACP template files.
11 * @author Alexander Ebert, Matthias Schmidt
12 * @copyright 2001-2018 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\Package
16 class ACPTemplatesFileHandler
extends PackageInstallationFileHandler
{
18 * template type supports template groups
21 protected $supportsTemplateGroups = false;
24 * name of the database table where the installed files are logged
27 protected $tableName = 'acp_template';
32 public function checkFiles(array $files) {
33 if ($this->packageInstallation
->getPackage()->package
!= 'com.woltlab.wcf') {
34 // check if files are existing already
36 foreach ($files as &$file) {
37 $file = substr($file, 0, -4);
41 // get by other packages registered files
42 $conditions = new PreparedStatementConditionBuilder();
43 $conditions->add('packageID <> ?', [$this->packageInstallation
->getPackageID()]);
44 $conditions->add('templateName IN (?)', [$files]);
45 $conditions->add('application = ?', [$this->application
]);
46 if ($this->supportsTemplateGroups
) {
47 $conditions->add("templateGroupID IS NULL");
50 $sql = "SELECT packageID, templateName
51 FROM wcf".WCF_N
."_".$this->tableName
."
53 $statement = WCF
::getDB()->prepareStatement($sql);
54 $statement->execute($conditions->getParameters());
55 $lockedFiles = $statement->fetchMap('templateName', 'packageID');
57 // check if acp templates from the package beeing
58 // installed are in conflict with already installed
60 if (!$this->packageInstallation
->getPackage()->isApplication
&& !empty($lockedFiles)) {
61 foreach ($files as $file) {
62 if (isset($lockedFiles[$file])) {
63 $owningPackage = new Package($lockedFiles[$file]);
65 throw new SystemException("A package can't overwrite templates from other packages. Only an update from the package which owns the template can do that. (Package '".$this->packageInstallation
->getPackage()->package
."' tries to overwrite template '".$file."', which is owned by package '".$owningPackage->package
."')");
76 public function logFiles(array $files) {
77 // remove file extension
78 foreach ($files as &$file) {
79 $file = substr($file, 0, -4);
83 // fetch already installed acp templates
84 $conditions = new PreparedStatementConditionBuilder();
85 $conditions->add('packageID = ?', [$this->packageInstallation
->getPackageID()]);
86 $conditions->add('templateName IN (?)', [$files]);
87 $conditions->add('application = ?', [$this->application
]);
89 $sql = "SELECT templateName
90 FROM wcf".WCF_N
."_".$this->tableName
."
92 $statement = WCF
::getDB()->prepareStatement($sql);
93 $statement->execute($conditions->getParameters());
95 while ($templateName = $statement->fetchColumn()) {
96 $index = array_search($templateName, $files);
98 if ($index !== false) {
99 unset($files[$index]);
103 if (!empty($files)) {
104 $sql = "INSERT INTO wcf".WCF_N
."_".$this->tableName
."
105 (packageID, templateName, application)
107 $statement = WCF
::getDB()->prepareStatement($sql);
109 foreach ($files as $file) {
110 $statement->execute([
111 $this->packageInstallation
->getPackageID(),