2069b5ebc5d3a0f87979bf5cb13aff11a14a5472
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / Classes / Controller / ModuleController.php
1 <?php
2 namespace TYPO3\CMS\Dbal\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18
19 /**
20 * Script class; Backend module for DBAL extension
21 */
22 class ModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
23
24 /**
25 * @var string
26 */
27 protected $thisScript;
28
29 /**
30 * The name of the module
31 *
32 * @var string
33 */
34 protected $moduleName = 'tools_txdbalM1';
35
36 /**
37 * Initializes this module.
38 *
39 * @return void
40 */
41 public function init() {
42 $this->MCONF = array(
43 'name' => $this->moduleName,
44 );
45 $this->getLanguageService()->includeLLFile('EXT:dbal/Resources/Private/Language/locallang.xlf');
46 parent::init();
47 }
48
49 /**
50 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
51 *
52 * @return void
53 */
54 public function menuConfig() {
55 $languageService = $this->getLanguageService();
56 $this->MOD_MENU = array(
57 'function' => array(
58 0 => $languageService->getLL('Debug_log'),
59 'info' => $languageService->getLL('Cached_info'),
60 'sqlcheck' => $languageService->getLL('SQL_check')
61 )
62 );
63 parent::menuConfig();
64 }
65
66 /**
67 * Main function of the module. Write the content to $this->content
68 *
69 * @return void
70 */
71 public function main() {
72 $languageService = $this->getLanguageService();
73 $this->thisScript = BackendUtility::getModuleUrl($this->MCONF['name']);
74 // Clean up settings:
75 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $this->MCONF['name']);
76 // Draw the header
77 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
78 $this->doc->backPath = $GLOBALS['BACK_PATH'];
79 $this->doc->form = '<form action="" method="post">';
80 // DBAL page title:
81 $this->content .= $this->doc->startPage($languageService->getLL('title'));
82 $this->content .= $this->doc->header($languageService->getLL('title'));
83 $this->content .= $this->doc->spacer(5);
84 $this->content .= $this->doc->section('', $this->doc->funcMenu('', BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'])));
85 // Debug log:
86 switch ($this->MOD_SETTINGS['function']) {
87 case 'info':
88 $this->content .= $this->doc->section($languageService->getLL('Cached_info'), $this->printCachedInfo());
89 break;
90 case 'sqlcheck':
91 $this->content .= $this->doc->section($languageService->getLL('SQL_check'), $this->printSqlCheck());
92 break;
93 case 0:
94 $this->content .= $this->doc->section($languageService->getLL('Debug_log'), $this->printLogMgm());
95 break;
96 }
97 // ShortCut
98 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
99 $this->content .= $this->doc->spacer(20) . $this->doc->section('', $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']));
100 }
101 $this->content .= $this->doc->spacer(10);
102 }
103
104 /**
105 * Prints out the module HTML
106 *
107 * @return string HTML output
108 */
109 public function printContent() {
110 $this->content .= $this->doc->endPage();
111 echo $this->content;
112 }
113
114 /**
115 * Displays a form to check DBAL SQL methods and parse raw SQL.
116 *
117 * @return string HTML output
118 */
119 protected function printSqlCheck() {
120 $input = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_dbal');
121 $out = '
122 <form name="sql_check" action="' . $this->thisScript . '" method="post" enctype="multipart/form-data">
123 <script type="text/javascript">
124 /*<![CDATA[*/
125 function updateQryForm(s) {
126 document.getElementById(\'tx-dbal-result\').style.display = \'none\';
127 switch(s) {
128 case \'SELECT\':
129 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
130 document.getElementById(\'tx-dbal-qryfields\').style.display = \'table-row\';
131 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
132 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
133 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
134 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
135 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
136 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
137 document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
138 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
139 break;
140 case \'INSERT\':
141 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
142 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
143 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'table-row\';
144 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
145 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
146 document.getElementById(\'tx-dbal-qryinto\').style.display = \'table-row\';
147 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
148 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
149 document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
150 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
151 break;
152 case \'UPDATE\':
153 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\';
154 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
155 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
156 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'table-row\';
157 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
158 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
159 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\';
160 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
161 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
162 document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
163 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
164 break;
165 case \'DELETE\':
166 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
167 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
168 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
169 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
170 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
171 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
172 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
173 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
174 document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
175 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
176 break;
177 }
178 }
179 /*]]>*/
180 </script>
181 <table>
182 <tr class="tableheader bgColor5"><th colspan="2">Easy SQL check</th></tr>
183 <tr><td colspan="2">
184 <select name="tx_dbal[QUERY]"size="1" onchange="updateQryForm(this.options[this.selectedIndex].value)">
185 <option value="SELECT" ' . ($input['QUERY'] === 'SELECT' ? 'selected="selected"' : '') . '>SELECT</option>
186 <option value="INSERT" ' . ($input['QUERY'] === 'INSERT' ? 'selected="selected"' : '') . '>INSERT</option>
187 <option value="UPDATE" ' . ($input['QUERY'] === 'UPDATE' ? 'selected="selected"' : '') . '>UPDATE</option>
188 <option value="DELETE" ' . ($input['QUERY'] === 'DELETE' ? 'selected="selected"' : '') . '>DELETE</option>
189 </select>
190 </td></tr>
191 <tr id="tx-dbal-qryupdate" style="display:none;"><td></td><td><input name="tx_dbal[UPDATE]" value="' . $input['UPDATE'] . '" type="text" size="30" maxsize="100" /></td></tr>
192 <tr id="tx-dbal-qryfields"><td></td><td><input name="tx_dbal[FIELDS]" value="' . $input['FIELDS'] . '" type="text" size="30" maxsize="100" /></td></tr>
193 <tr id="tx-dbal-qryinsertvalues" style="display:none;"><td></td><td><textarea name="tx_dbal[INSERTVALUES]" cols="30" rows="4">' . $input['INSERTVALUES'] . '</textarea></td></tr>
194 <tr id="tx-dbal-qryupdatevalues" style="display:none;"><th>SET</th><td><textarea name="tx_dbal[UPDATEVALUES]" cols="30" rows="4">' . $input['UPDATEVALUES'] . '</textarea></td></tr>
195 <tr id="tx-dbal-qryfrom"><th>FROM</th><td><input name="tx_dbal[FROM]" value="' . $input['FROM'] . '" type="text" size="30" maxsize="100" /></td></tr>
196 <tr id="tx-dbal-qryinto" style="display:none;"><th>INTO</th><td><input name="tx_dbal[INTO]" value="' . $input['INTO'] . '" type="text" size="30" maxsize="100" /></td></tr>
197 <tr id="tx-dbal-qrywhere"><th>WHERE</th><td><input name="tx_dbal[WHERE]" value="' . $input['WHERE'] . '" type="text" size="30" maxsize="100" /></td></tr>
198 <tr id="tx-dbal-qrygroup"><th>GROUP BY</th><td><input name="tx_dbal[GROUP]" value="' . $input['GROUP'] . '" type="text" size="30" maxsize="100" /></td></tr>
199 <tr id="tx-dbal-qryorder"><th>ORDER BY</th><td><input name="tx_dbal[ORDER]" value="' . $input['ORDER'] . '" type="text" size="30" maxsize="100" /></td></tr>
200 <tr id="tx-dbal-qrylimit"><th>LIMIT</th><td><input name="tx_dbal[LIMIT]" value="' . $input['LIMIT'] . '" type="text" size="30" maxsize="100" /></td></tr>
201 <tr>
202 <td></td>
203 <td style="text-align:right;">
204 <input class="btn btn-default" type="submit" value="CHECK" />
205 </td>
206 </tr>
207 <script type="text/javascript">
208 /*<![CDATA[*/
209 updateQryForm(\'' . $input['QUERY'] . '\');
210 /*]]>*/
211 </script>
212 ';
213 $out .= '<tr id="tx-dbal-result" class="bgColor4"><th>Result:</th><td>';
214 switch ($input['QUERY']) {
215 case 'SELECT':
216 $qry = $GLOBALS['TYPO3_DB']->SELECTquery($input['FIELDS'], $input['FROM'], $input['WHERE'], $input['GROUP'], $input['ORDER'], $input['LIMIT']);
217 break;
218 case 'INSERT':
219 $qry = $GLOBALS['TYPO3_DB']->INSERTquery($input['INTO'], $this->createFieldsValuesArray($input['INSERTVALUES']));
220 break;
221 case 'UPDATE':
222 $qry = $GLOBALS['TYPO3_DB']->UPDATEquery($input['UPDATE'], $input['WHERE'], $this->createFieldsValuesArray($input['UPDATEVALUES']));
223 break;
224 case 'DELETE':
225 $qry = $GLOBALS['TYPO3_DB']->DELETEquery($input['FROM'], $input['WHERE']);
226 break;
227 }
228 $out .= '<pre>' . htmlspecialchars($qry) . '</pre></td></tr>';
229 $out .= '
230 <tr class="tableheader bgColor5">
231 <th colspan="2">RAW SQL check</th>
232 </tr>
233 <tr>
234 <td colspan="2" style="text-align:right;">
235 <textarea name="tx_dbal[RAWSQL]" cols="60" rows="5">' . $input['RAWSQL'] . '</textarea>
236 <br />
237 <input class="btn btn-default" type="submit" value="CHECK" />
238 </td>
239 </tr>';
240 if (!empty($input['RAWSQL'])) {
241 $out .= '<tr class="bgColor4">';
242 $parseResult = $GLOBALS['TYPO3_DB']->SQLparser->parseSQL($input['RAWSQL']);
243 if (is_array($parseResult)) {
244 $newQuery = $GLOBALS['TYPO3_DB']->SQLparser->compileSQL($parseResult);
245 $testResult = $GLOBALS['TYPO3_DB']->SQLparser->debug_parseSQLpartCompare($input['RAWSQL'], $newQuery);
246 if (!is_array($testResult)) {
247 $out .= '<td colspan="2">' . $newQuery;
248 } else {
249 $out .= '<td colspan="2">' . htmlspecialchars($testResult[0]) . '</td></tr>
250 <tr><th>Error:</th><td style="border:2px solid #f00;">Input query did not match the parsed and recompiled query exactly (not observing whitespace):<br />' . htmlspecialchars($testResult[1]);
251 }
252 } else {
253 $out .= '<th>Result:</th><td style="border:2px solid #f00;">' . $parseResult;
254 }
255 $out .= '</td></tr>';
256 }
257 $out .= '</table></form>';
258 return $out;
259 }
260
261 /**
262 * Parses a very simple text format into an array.
263 *
264 * Each line is seen as a key/value pair that is exploded at =. This is used
265 * in the simple SQL check to input values for INSERT and UPDATE statements.
266 *
267 * @param string $in String to parse into key/value array.
268 * @return array Array created from the input string.
269 */
270 protected function createFieldsValuesArray($in) {
271 $ret = array();
272 $in = explode(LF, $in);
273 foreach ($in as $v) {
274 $fv = explode('=', $v);
275 $ret[$fv[0]] = $fv[1];
276 }
277 return $ret;
278 }
279
280 /**
281 * Prints out the cached information about the database.
282 *
283 * The DBAL caches a lot of information, e.g. about auto increment fields,
284 * field types and primary keys. This method formats all this into a HTML
285 * table to display in the BE.
286 *
287 * @return string HTML output
288 */
289 protected function printCachedInfo() {
290 // Get cmd:
291 if ((string)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cmd') === 'clear') {
292 $GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
293 $GLOBALS['TYPO3_DB']->cacheFieldInfo();
294 }
295 $out = '<a name="autoincrement"></a><h2>auto_increment</h2>';
296 $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field</th></tr>';
297 ksort($GLOBALS['TYPO3_DB']->cache_autoIncFields);
298 foreach ($GLOBALS['TYPO3_DB']->cache_autoIncFields as $table => $field) {
299 $out .= '<tr>';
300 $out .= '<td>' . $table . '</td>';
301 $out .= '<td>' . $field . '</td>';
302 $out .= '</tr>';
303 }
304 $out .= '</tbody></table>';
305 $out .= $this->doc->spacer(5);
306 $out .= '<a name="primarykeys"></a><h2>Primary keys</h2>';
307 $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field(s)</th></tr>';
308 ksort($GLOBALS['TYPO3_DB']->cache_primaryKeys);
309 foreach ($GLOBALS['TYPO3_DB']->cache_primaryKeys as $table => $field) {
310 $out .= '<tr>';
311 $out .= '<td>' . $table . '</td>';
312 $out .= '<td>' . $field . '</td>';
313 $out .= '</tr>';
314 }
315 $out .= '</tbody></table>';
316 $out .= $this->doc->spacer(5);
317 $out .= '<a name="fieldtypes"></a><h2>Field types</h2>';
318 $out .= '<table border="1" cellspacing="0"><tbody><tr><th colspan="5">Table</th></tr><tr><th>Field</th><th>Type</th><th><a href="#metatypes">Metatype</a></th><th>NOT NULL</th><th>Default</th></th></tr>';
319 ksort($GLOBALS['TYPO3_DB']->cache_fieldType);
320 foreach ($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fields) {
321 $out .= '<th colspan="5">' . $table . '</th>';
322 foreach ($fields as $field => $data) {
323 $out .= '<tr>';
324 $out .= '<td>' . $field . '</td>';
325 $out .= '<td>' . $data['type'] . '</td>';
326 $out .= '<td>' . $data['metaType'] . '</td>';
327 $out .= '<td>' . ($data['notnull'] ? 'NOT NULL' : '') . '</td>';
328 $out .= '<td>' . $data['default'] . '</td>';
329 $out .= '</tr>';
330 }
331 }
332 $out .= '</tbody></table>';
333 $out .= $this->doc->spacer(5);
334 $out .= '<a name="metatypes"></a><h2>Metatype explanation</h2>';
335 $out .= '<pre>
336 C: Varchar, capped to 255 characters.
337 X: Larger varchar, capped to 4000 characters (to be compatible with Oracle).
338 XL: For Oracle, returns CLOB, otherwise the largest varchar size.
339
340 C2: Multibyte varchar
341 X2: Multibyte varchar (largest size)
342
343 B: BLOB (binary large object)
344
345 D: Date (some databases do not support this, and we return a datetime type)
346 T: Datetime or Timestamp
347 L: Integer field suitable for storing booleans (0 or 1)
348 I: Integer (mapped to I4)
349 I1: 1-byte integer
350 I2: 2-byte integer
351 I4: 4-byte integer
352 I8: 8-byte integer
353 F: Floating point number
354 N: Numeric or decimal number</pre>';
355 $menu = '<a href="' . $this->thisScript . '&amp;cmd=clear">CLEAR DATA</a><hr />';
356 $menu .= '<a href="#autoincrement">auto_increment</a> | <a href="#primarykeys">Primary keys</a> | <a href="#fieldtypes">Field types</a> | <a href="#metatypes">Metatype explanation</a><hr />';
357 return $menu . $out;
358 }
359
360 /**
361 * Printing the debug-log from the DBAL extension
362 *
363 * To enabled debugging, you will have to enabled it in the configuration!
364 *
365 * @return string HTML content
366 */
367 protected function printLogMgm() {
368 // Disable debugging in any case...
369 $GLOBALS['TYPO3_DB']->debug = FALSE;
370 // Get cmd:
371 $cmd = (string)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cmd');
372 switch ($cmd) {
373 case 'flush':
374 $res = $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_dbal_debuglog');
375 $res = $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_dbal_debuglog_where');
376 $outStr = 'Log FLUSHED!';
377 break;
378 case 'joins':
379 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('table_join,exec_time,query,script', 'tx_dbal_debuglog', 'table_join!=\'\'', 'table_join,script,exec_time,query');
380 // Init vars in which to pick up the query result:
381 $tableIndex = array();
382 $tRows = array();
383 $tRows[] = '
384 <tr>
385 <td>Execution time</td>
386 <td>Table joins</td>
387 <td>Script</td>
388 <td>Query</td>
389 </tr>';
390 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
391 $tableArray = $GLOBALS['TYPO3_DB']->SQLparser->parseFromTables($row['table_join']);
392 // Create table name index:
393 foreach ($tableArray as $a) {
394 foreach ($tableArray as $b) {
395 if ($b['table'] != $a['table']) {
396 $tableIndex[$a['table']][$b['table']] = 1;
397 }
398 }
399 }
400 // Create output row
401 $tRows[] = '
402 <tr>
403 <td>' . htmlspecialchars($row['exec_time']) . '</td>
404 <td>' . htmlspecialchars($row['table_join']) . '</td>
405 <td>' . htmlspecialchars($row['script']) . '</td>
406 <td>' . htmlspecialchars($row['query']) . '</td>
407 </tr>';
408 }
409 // Printing direct joins:
410 $outStr .= '<h4>Direct joins:</h4>' . \TYPO3\CMS\Core\Utility\DebugUtility::viewArray($tableIndex);
411 // Printing total dependencies:
412 foreach ($tableIndex as $priTable => $a) {
413 foreach ($tableIndex as $tableN => $v) {
414 foreach ($v as $tableP => $vv) {
415 if ($tableP == $priTable) {
416 $tableIndex[$priTable] = array_merge($v, $a);
417 }
418 }
419 }
420 }
421 $outStr .= '<h4>Total dependencies:</h4>' . \TYPO3\CMS\Core\Utility\DebugUtility::viewArray($tableIndex);
422 // Printing data rows:
423 $outStr .= '
424 <table border="1" cellspacing="0">' . implode('', $tRows) . '
425 </table>';
426 break;
427 case 'errors':
428 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('serdata,exec_time,query,script', 'tx_dbal_debuglog', 'errorFlag>0', '', 'tstamp DESC');
429 // Init vars in which to pick up the query result:
430 $tRows = array();
431 $tRows[] = '
432 <tr>
433 <td>Execution time</td>
434 <td>Error data</td>
435 <td>Script</td>
436 <td>Query</td>
437 </tr>';
438 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
439 // Create output row
440 $tRows[] = '
441 <tr>
442 <td>' . htmlspecialchars($row['exec_time']) . '</td>
443 <td>' . \TYPO3\CMS\Core\Utility\DebugUtility::viewArray(unserialize($row['serdata'])) . '</td>
444 <td>' . htmlspecialchars($row['script']) . '</td>
445 <td>' . htmlspecialchars($row['query']) . '</td>
446 </tr>';
447 }
448 // Printing data rows:
449 $outStr .= '
450 <table border="1" cellspacing="0">' . implode('', $tRows) . '
451 </table>';
452 break;
453 case 'parsing':
454 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('query,serdata', 'tx_dbal_debuglog', 'errorFlag&2=2');
455 $tRows = array();
456 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
457 // Create output row
458 $tRows[] = '
459 <tr>
460 <td>' . htmlspecialchars($row['query']) . '</td>
461 </tr>';
462 }
463 // Printing data rows:
464 $outStr .= '
465 <table border="1" cellspacing="0">' . implode('', $tRows) . '
466 </table>';
467 break;
468 case 'where':
469 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script,tablename,whereclause', 'tx_dbal_debuglog_where', '', '', 'tstamp DESC');
470 $tRows = array();
471 $tRows[] = '
472 <tr>
473 <td>Time</td>
474 <td>Script</td>
475 <td>Table</td>
476 <td>WHERE clause</td>
477 </tr>';
478 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
479 $tRows[] = '
480 <tr>
481 <td>' . BackendUtility::datetime($row['tstamp']) . '</td>
482 <td>' . htmlspecialchars($row['script']) . '</td>
483 <td>' . htmlspecialchars($row['tablename']) . '</td>
484 <td>' . str_replace(array('\'\'', '""', 'IS NULL', 'IS NOT NULL'), array('<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">\'\'</span>', '<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">""</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NULL</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NOT NULL</span>'), htmlspecialchars($row['whereclause'])) . '</td>
485 </tr>';
486 }
487 $outStr = '
488 <table border="1" cellspacing="0">' . implode('', $tRows) . '
489 </table>';
490 break;
491 default:
492 // Look for request to view specific script exec:
493 $specTime = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('specTime');
494 if ($specTime) {
495 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('exec_time,errorFlag,table_join,serdata,query', 'tx_dbal_debuglog', 'tstamp=' . (int)$specTime);
496 $tRows = array();
497 $tRows[] = '
498 <tr>
499 <td>Execution time</td>
500 <td>Error</td>
501 <td>Table joins</td>
502 <td>Data</td>
503 <td>Query</td>
504 </tr>';
505 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
506 $tRows[] = '
507 <tr>
508 <td>' . htmlspecialchars($row['exec_time']) . '</td>
509 <td>' . ($row['errorFlag'] ? 1 : 0) . '</td>
510 <td>' . htmlspecialchars($row['table_join']) . '</td>
511 <td>' . \TYPO3\CMS\Core\Utility\DebugUtility::viewArray(unserialize($row['serdata'])) . '</td>
512 <td>' . str_replace(array('\'\'', '""', 'IS NULL', 'IS NOT NULL'), array('<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">\'\'</span>', '<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">""</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NULL</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NOT NULL</span>'), htmlspecialchars($row['query'])) . '</td>
513 </tr>';
514 }
515 } else {
516 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script, SUM(exec_time) as calc_sum, count(*) AS qrycount, MAX(errorFlag) as error', 'tx_dbal_debuglog', '', 'tstamp,script', 'tstamp DESC');
517 $tRows = array();
518 $tRows[] = '
519 <tr>
520 <td>Time</td>
521 <td># of queries</td>
522 <td>Error</td>
523 <td>Time (ms)</td>
524 <td>Script</td>
525 </tr>';
526 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
527 $tRows[] = '
528 <tr>
529 <td>' . BackendUtility::datetime($row['tstamp']) . '</td>
530 <td>' . htmlspecialchars($row['qrycount']) . '</td>
531 <td>' . ($row['error'] ? '<strong style="color:#f00">ERR</strong>' : '') . '</td>
532 <td>' . htmlspecialchars($row['calc_sum']) . '</td>
533 <td><a href="' . $this->thisScript . '&amp;specTime=' . (int)$row['tstamp'] . '">' . htmlspecialchars($row['script']) . '</a></td>
534 </tr>';
535 }
536 }
537 $outStr = '
538 <table border="1" cellspacing="0">' . implode('', $tRows) . '
539 </table>';
540 }
541 $menu = '
542 <a href="' . $this->thisScript . '&amp;cmd=flush">FLUSH LOG</a> -
543 <a href="' . $this->thisScript . '&amp;cmd=joins">JOINS</a> -
544 <a href="' . $this->thisScript . '&amp;cmd=errors">ERRORS</a> -
545 <a href="' . $this->thisScript . '&amp;cmd=parsing">PARSING</a> -
546 <a href="' . $this->thisScript . '">LOG</a> -
547 <a href="' . $this->thisScript . '&amp;cmd=where">WHERE</a> -
548
549 <a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript()) . '" target="tx_debuglog">[New window]</a>
550 <hr />
551 ';
552 return $menu . $outStr;
553 }
554
555 /**
556 * Returns the language service.
557 *
558 * @return \TYPO3\CMS\Lang\LanguageService
559 */
560 protected function getLanguageService() {
561 return $GLOBALS['LANG'];
562 }
563
564 }