cfae0270a6476f350ac1fbb55febf5435155da0f
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\data\devtools\missing\language\item;
4
5 use wcf\data\AbstractDatabaseObjectAction;
6 use wcf\data\IDeleteAction;
7 use wcf\system\exception\IllegalLinkException;
8 use wcf\system\WCF;
9 use wcf\util\JSON;
10
11 /**
12 * Executes missing language item log entry-related actions.
13 *
14 * @author Matthias Schmidt
15 * @copyright 2001-2020 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Devtools\Missing\Language\Item
18 * @since 5.3
19 *
20 * @method DevtoolsMissingLanguageItemEditor[] getObjects()
21 * @method DevtoolsMissingLanguageItemEditor getSingleObject()
22 */
23 class DevtoolsMissingLanguageItemAction extends AbstractDatabaseObjectAction implements IDeleteAction
24 {
25 /**
26 * @inheritDoc
27 */
28 protected $permissionsDelete = ['admin.configuration.package.canInstallPackage'];
29
30 /**
31 * Logs a missing language item.
32 */
33 public function logLanguageItem()
34 {
35 $stackTraceData = \wcf\functions\exception\sanitizeStacktrace(new \Exception(), true);
36 // Remove stack entries related to logging.
37 \array_shift($stackTraceData);
38 \array_shift($stackTraceData);
39 \array_shift($stackTraceData);
40 $stackTrace = JSON::encode($stackTraceData);
41
42 $sql = "INSERT INTO wcf" . WCF_N . "_devtools_missing_language_item
43 (languageID, languageItem, lastTime, stackTrace)
44 VALUES (?, ?, ?, ?)
45 ON DUPLICATE KEY UPDATE lastTime = ?,
46 stackTrace = ?";
47 $statement = WCF::getDB()->prepareStatement($sql);
48 $statement->execute([
49 $this->parameters['language']->languageID,
50 $this->parameters['languageItem'],
51 TIME_NOW,
52 $stackTrace,
53
54 TIME_NOW,
55 $stackTrace,
56 ]);
57 }
58
59 /**
60 * @inheritDoc
61 */
62 public function validateDelete()
63 {
64 if (!ENABLE_DEVELOPER_TOOLS || !LOG_MISSING_LANGUAGE_ITEMS) {
65 throw new IllegalLinkException();
66 }
67
68 parent::validateDelete();
69 }
70
71 /**
72 * Validates the `clearLog` action.
73 */
74 public function validateClearLog()
75 {
76 if (!ENABLE_DEVELOPER_TOOLS || !LOG_MISSING_LANGUAGE_ITEMS) {
77 throw new IllegalLinkException();
78 }
79
80 WCF::getSession()->checkPermissions(['admin.configuration.package.canInstallPackage']);
81 }
82
83 /**
84 * Removes all entries from the missing language item log.
85 */
86 public function clearLog()
87 {
88 $sql = "DELETE FROM wcf" . WCF_N . "_devtools_missing_language_item";
89 $statement = WCF::getDB()->prepareStatement($sql);
90 $statement->execute();
91 }
92
93 /**
94 * Validates the `clearExistingLog` action.
95 *
96 * @since 5.4
97 */
98 public function validateClearExistingLog(): void
99 {
100 if (!ENABLE_DEVELOPER_TOOLS || !LOG_MISSING_LANGUAGE_ITEMS) {
101 throw new IllegalLinkException();
102 }
103
104 WCF::getSession()->checkPermissions(['admin.configuration.package.canInstallPackage']);
105 }
106
107 /**
108 * Removes the entries from the missing language item log for which a language item exists now.
109 *
110 * @since 5.4
111 */
112 public function clearExistingLog(): void
113 {
114 $sql = "DELETE devtools_missing_language_item
115 FROM wcf" . WCF_N . "_devtools_missing_language_item devtools_missing_language_item
116 INNER JOIN wcf" . WCF_N . "_language_item language_item
117 ON (
118 language_item.languageItem = devtools_missing_language_item.languageItem
119 AND language_item.languageID = devtools_missing_language_item.languageID
120 )";
121 $statement = WCF::getDB()->prepareStatement($sql);
122 $statement->execute();
123 }
124 }