-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathDevtoolsMissingLanguageItemAction.class.php
More file actions
158 lines (140 loc) · 5.04 KB
/
DevtoolsMissingLanguageItemAction.class.php
File metadata and controls
158 lines (140 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
namespace wcf\data\devtools\missing\language\item;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IDeleteAction;
use wcf\system\exception\IllegalLinkException;
use wcf\system\WCF;
use wcf\util\StringUtil;
/**
* Executes missing language item log entry-related actions.
*
* @author Matthias Schmidt
* @copyright 2001-2020 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 5.3
*
* @extends AbstractDatabaseObjectAction<DevtoolsMissingLanguageItem, DevtoolsMissingLanguageItemEditor>
*/
class DevtoolsMissingLanguageItemAction extends AbstractDatabaseObjectAction implements IDeleteAction
{
/**
* @inheritDoc
*/
protected $permissionsDelete = ['admin.configuration.package.canInstallPackage'];
/**
* Logs a missing language item.
*
* @return void
*/
public function logLanguageItem()
{
$stackTraceData = \array_map(static function ($item) {
$item['args'] = \implode(', ', \array_map(static function ($item) {
switch (\gettype($item)) {
case 'integer':
case 'double':
return $item;
case 'NULL':
return 'null';
case 'string':
return "'" . StringUtil::encodeHTML(\addcslashes(StringUtil::truncate($item), "\\'\n\r\t")) . "'";
case 'boolean':
return $item ? 'true' : 'false';
case 'array':
$keys = \array_keys($item);
if (\count($keys) > 5) {
return "[ " . \count($keys) . " items ]";
}
return '[ ' . \implode(', ', \array_map(static function ($item) {
return $item . ' => ';
}, $keys)) . ']';
case 'object':
if ($item instanceof \UnitEnum) {
return $item::class . '::' . $item->name;
}
return $item::class;
case 'resource':
return 'resource(' . \get_resource_type($item) . ')';
case 'resource (closed)':
return 'resource (closed)';
}
}, $item['args']));
return $item;
}, \wcf\functions\exception\sanitizeStacktrace(new \Exception(), true));
$stackTrace = \json_encode($stackTraceData, \JSON_THROW_ON_ERROR);
$sql = "INSERT INTO wcf1_devtools_missing_language_item
(languageID, languageItem, lastTime, stackTrace)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE lastTime = ?,
stackTrace = ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$this->parameters['language']->languageID,
$this->parameters['languageItem'],
TIME_NOW,
$stackTrace,
TIME_NOW,
$stackTrace,
]);
}
/**
* @inheritDoc
*/
public function validateDelete()
{
if (!ENABLE_DEVELOPER_TOOLS) {
throw new IllegalLinkException();
}
parent::validateDelete();
}
/**
* Validates the `clearLog` action.
*
* @return void
*/
public function validateClearLog()
{
if (!ENABLE_DEVELOPER_TOOLS) {
throw new IllegalLinkException();
}
WCF::getSession()->checkPermissions(['admin.configuration.package.canInstallPackage']);
}
/**
* Removes all entries from the missing language item log.
*
* @return void
*/
public function clearLog()
{
$sql = "DELETE FROM wcf1_devtools_missing_language_item";
$statement = WCF::getDB()->prepare($sql);
$statement->execute();
}
/**
* Validates the `clearExistingLog` action.
*
* @since 5.4
*/
public function validateClearExistingLog(): void
{
if (!ENABLE_DEVELOPER_TOOLS) {
throw new IllegalLinkException();
}
WCF::getSession()->checkPermissions(['admin.configuration.package.canInstallPackage']);
}
/**
* Removes the entries from the missing language item log for which a language item exists now.
*
* @since 5.4
*/
public function clearExistingLog(): void
{
$sql = "DELETE devtools_missing_language_item
FROM wcf1_devtools_missing_language_item devtools_missing_language_item
INNER JOIN wcf1_language_item language_item
ON language_item.languageItem = devtools_missing_language_item.languageItem
AND language_item.languageID = devtools_missing_language_item.languageID";
$statement = WCF::getDB()->prepare($sql);
$statement->execute();
}
}