Set default captcha type to none
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / package / TemplatesFileHandler.class.php
... / ...
CommitLineData
1<?php
2
3namespace wcf\system\package;
4
5use wcf\system\database\util\PreparedStatementConditionBuilder;
6use wcf\system\WCF;
7
8/**
9 * File handler implementation for the installation of template files.
10 *
11 * @author Marcel Werk
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 */
15class TemplatesFileHandler extends ACPTemplatesFileHandler
16{
17 /**
18 * @inheritDoc
19 */
20 protected $supportsTemplateGroups = true;
21
22 /**
23 * @inheritDoc
24 */
25 protected $tableName = 'template';
26
27 /**
28 * @inheritDoc
29 */
30 public function logFiles(array $files)
31 {
32 $packageID = $this->packageInstallation->getPackageID();
33
34 // remove file extension
35 foreach ($files as &$file) {
36 $file = \substr($file, 0, -4);
37 }
38 unset($file);
39
40 // get existing templates
41 $updateTemplateIDs = [];
42 $sql = "SELECT templateName, templateID
43 FROM wcf" . WCF_N . "_template
44 WHERE packageID = ?
45 AND application = ?
46 AND templateGroupID IS NULL";
47 $statement = WCF::getDB()->prepareStatement($sql);
48 $statement->execute([$packageID, $this->application]);
49 $existingTemplates = $statement->fetchMap('templateName', 'templateID');
50
51 // save new templates
52 $sql = "INSERT INTO wcf" . WCF_N . "_template
53 (packageID, templateName, lastModificationTime, application)
54 VALUES (?, ?, ?, ?)";
55 $statement = WCF::getDB()->prepareStatement($sql);
56 foreach ($files as $file) {
57 if (isset($existingTemplates[$file])) {
58 $updateTemplateIDs[] = $existingTemplates[$file];
59 continue;
60 }
61
62 $statement->execute([
63 $packageID,
64 $file,
65 TIME_NOW,
66 $this->application,
67 ]);
68 }
69
70 if (!empty($updateTemplateIDs)) {
71 // update old templates
72 $conditionBuilder = new PreparedStatementConditionBuilder();
73 $conditionBuilder->add('templateID IN (?)', [$updateTemplateIDs]);
74
75 $sql = "UPDATE wcf" . WCF_N . "_template
76 SET lastModificationTime = ?
77 " . $conditionBuilder;
78 $statement = WCF::getDB()->prepareStatement($sql);
79 $statement->execute(\array_merge([TIME_NOW], $conditionBuilder->getParameters()));
80 }
81 }
82}