-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.xml
More file actions
271 lines (253 loc) · 9.62 KB
/
install.xml
File metadata and controls
271 lines (253 loc) · 9.62 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<name>
<![CDATA[ocXRay — Debug Profiler]]>
</name>
<version>3.1.0</version>
<link>https://t.me/evgeniistarychenko</link>
<author>
<![CDATA[Yevhenii Starychenko <evgeniistarychenko@gmail.com>]]>
</author>
<code>ocXRay</code>
<description>
<![CDATA[SQL query profiler & controller action debugger for OpenCart 3.x]]>
</description>
<!-- Op 1: Instrument SQL queries -->
<file path="system/library/db/mysqli.php">
<operation>
<search trim="true">
<![CDATA[$query = $this->connection->query($sql);]]>
</search>
<add position="replace" trim="false">
<![CDATA[if (file_exists(dirname(DIR_SYSTEM) . '/ocxray_enabled')) {
global $debugModelQueries;
global $debugCurrentActionRoute;
$startTime = microtime(true);
$query = $this->connection->query($sql);
$executeTimeQuery = microtime(true) - $startTime;
$debugBacktrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
$debugModelQueries[] = [
'class' => (!empty($debugBacktrace[2]['class'])) ? $debugBacktrace[2]['class'] : '',
'method' => (!empty($debugBacktrace[2]['function'])) ? $debugBacktrace[2]['function'] : '',
'query' => $sql,
'time' => $executeTimeQuery,
'start' => $startTime,
'file' => (!empty($debugBacktrace[2]['file'])) ? $debugBacktrace[2]['file'] : $debugBacktrace[1]['file'],
'class:method' => (!empty($debugBacktrace[2]['class'])) ? $debugBacktrace[2]['class'] . '->' . $debugBacktrace[2]['function'] : '',
'route' => $debugCurrentActionRoute ?? '',
];
} else {
$query = $this->connection->query($sql);
}]]>
</add>
</operation>
</file>
<!-- Op 2: Instrument controller actions -->
<file path="system/engine/action.php">
<operation>
<search trim="true">
<![CDATA[return call_user_func_array(array($controller, $this->method), $args);]]>
</search>
<add position="replace" trim="false">
<![CDATA[if (file_exists(dirname(DIR_SYSTEM) . '/ocxray_enabled')) {
global $debugControllerActions;
global $debugCurrentActionViewTime;
global $debugCurrentActionRoute;
$debugSavedViewTime = $debugCurrentActionViewTime ?? 0;
$debugCurrentActionViewTime = 0;
$debugSavedRoute = $debugCurrentActionRoute ?? '';
$debugCurrentActionRoute = $this->id;
$time = microtime(true);
$call_func = call_user_func_array(array($controller, $this->method), $args);
$totalTime = microtime(true) - $time;
$debugControllerActions[] = [
'class' => get_class($controller),
'method' => $this->method,
'route' => $this->id,
'time' => $totalTime,
'start' => $time,
'viewTime' => $debugCurrentActionViewTime,
];
$debugCurrentActionViewTime = $debugSavedViewTime;
$debugCurrentActionRoute = $debugSavedRoute;
return $call_func;
} else {
return call_user_func_array(array($controller, $this->method), $args);
}]]>
</add>
</operation>
</file>
<!-- Op 3: Auto-include debug panel in response output (before compression) -->
<!-- response.php is loaded via modification() (autoloader in startup.php), -->
<!-- so this patch works on all OpenCart 3.x versions including 3.0.4.x. -->
<!-- The panel HTML is appended to $this->output BEFORE gzip compression, -->
<!-- so it works correctly even when config_compression is enabled. -->
<file path="system/library/response.php">
<operation>
<search trim="true">
<![CDATA[$output = $this->level ? $this->compress($this->output, $this->level) : $this->output;]]>
</search>
<add position="before" trim="false"><![CDATA[
if (file_exists(dirname(DIR_SYSTEM) . '/ocxray_enabled')
&& is_file(dirname(DIR_SYSTEM) . '/debug_after_index.php')
) {
ob_start();
require(dirname(DIR_SYSTEM) . '/debug_after_index.php');
$this->output .= ob_get_clean();
}
]]>
</add>
</operation>
<!-- Op 8: Load xdump.php early (before class declaration) -->
<operation error="skip">
<search trim="true">
<![CDATA[class Response {]]>
</search>
<add position="before" trim="false"><![CDATA[
if (file_exists(dirname(DIR_SYSTEM) . '/ocxray_enabled')
&& is_file(dirname(DIR_SYSTEM) . '/xdump.php')
) {
require_once(dirname(DIR_SYSTEM) . '/xdump.php');
}
]]>
</add>
</operation>
</file>
<!-- Op 9-10: Enable Twig debug mode and DebugExtension -->
<file path="system/library/template/twig.php">
<!-- Op 9: Enable debug in Twig config -->
<operation error="skip">
<search trim="true">
<![CDATA[$twig = new \Twig\Environment($loader, $config);]]>
</search>
<add position="before" trim="false"><![CDATA[
if (file_exists(dirname(DIR_SYSTEM) . '/ocxray_enabled')) {
$config['debug'] = true;
}
]]>
</add>
</operation>
<!-- Op 10: Register DebugExtension -->
<operation error="skip">
<search trim="true">
<![CDATA[$twig = new \Twig\Environment($loader, $config);]]>
</search>
<add position="after" trim="false"><![CDATA[
if (file_exists(dirname(DIR_SYSTEM) . '/ocxray_enabled')
&& class_exists('\Twig\Extension\DebugExtension')
) {
$twig->addExtension(new \Twig\Extension\DebugExtension());
}
]]>
</add>
</operation>
</file>
<!-- Ops 11-12: Instrument template rendering in Loader::view() -->
<file path="system/engine/loader.php">
<!-- Op 11: Start view timing before template render -->
<operation error="skip">
<search trim="true">
<![CDATA[$output = $template->render($this->registry->get('config')->get('template_directory') . $route, $code);]]>
</search>
<add position="before" trim="false"><![CDATA[
$debugViewStart = null;
if (file_exists(dirname(DIR_SYSTEM) . '/ocxray_enabled')) {
$debugViewStart = microtime(true);
}
]]>
</add>
</operation>
<!-- Op 12: End view timing after template render -->
<operation error="skip">
<search trim="true">
<![CDATA[$output = $template->render($this->registry->get('config')->get('template_directory') . $route, $code);]]>
</search>
<add position="after" trim="false"><![CDATA[
if ($debugViewStart !== null) {
global $debugCurrentActionViewTime;
global $debugViewRenders;
$debugViewTime = microtime(true) - $debugViewStart;
$debugCurrentActionViewTime = ($debugCurrentActionViewTime ?? 0) + $debugViewTime;
$debugViewRenders[] = [
'template' => $trigger,
'time' => $debugViewTime,
'start' => $debugViewStart,
];
}
]]>
</add>
</operation>
</file>
<!-- Op 4: Write/delete flag file on admin settings save -->
<file path="admin/controller/setting/setting.php">
<operation>
<search trim="true">
<![CDATA[$this->model_setting_setting->editSetting('config', $this->request->post);]]>
</search>
<add position="after" trim="false"><![CDATA[
$ocxrayFlagFile = dirname(DIR_APPLICATION) . '/ocxray_enabled';
if (!empty($this->request->post['config_ocxray'])) {
@file_put_contents($ocxrayFlagFile, '1');
} else {
@unlink($ocxrayFlagFile);
}]]>
</add>
</operation>
</file>
<!-- Op 5: Pass config_ocxray to admin settings template -->
<file path="admin/controller/setting/setting.php">
<operation>
<search trim="true">
<![CDATA[$data['config_compression'] = $this->config->get('config_compression');]]>
</search>
<add position="after" trim="false"><![CDATA[
$data['config_ocxray'] = file_exists(dirname(DIR_APPLICATION) . '/ocxray_enabled') ? 1 : 0;]]>
</add>
</operation>
</file>
<!-- Op 6: Add toggle UI to admin settings template (before Maintenance Mode) -->
<file path="admin/view/template/setting/setting.twig">
<operation>
<search trim="true">
<![CDATA[{{ help_maintenance }}">{{ entry_maintenance }}]]>
</search>
<add position="before" offset="1" trim="false"><![CDATA[
<div class="form-group">
<label class="col-sm-2 control-label"><span data-toggle="tooltip" title="{{ help_ocxray }}">{{ entry_ocxray }}</span></label>
<div class="col-sm-10">
<label class="radio-inline">
{% if config_ocxray %}
<input type="radio" name="config_ocxray" value="1" checked="checked" />
{{ text_yes }}
{% else %}
<input type="radio" name="config_ocxray" value="1" />
{{ text_yes }}
{% endif %}
</label>
<label class="radio-inline">
{% if not config_ocxray %}
<input type="radio" name="config_ocxray" value="0" checked="checked" />
{{ text_no }}
{% else %}
<input type="radio" name="config_ocxray" value="0" />
{{ text_no }}
{% endif %}
</label>
</div>
</div>]]>
</add>
</operation>
</file>
<!-- Op 7: Add language strings for ocXRay toggle -->
<file path="admin/language/*/setting/setting.php">
<operation>
<search trim="true">
<![CDATA[$_['entry_maintenance']]]>
</search>
<add position="before" trim="false"><![CDATA[$_['entry_ocxray'] = 'ocXRay Debug Panel';
$_['help_ocxray'] = 'Enable SQL query profiler and controller action debugger. Do NOT enable in production!';
]]>
</add>
</operation>
</file>
</modification>