Base for a static organization website

sql_log_panel.ctp 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * SQL Log Panel Element
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @since DebugKit 0.1
  16. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  17. */
  18. $headers = array('Query', 'Affected', 'Num. rows', 'Took (ms)', 'Actions');
  19. if (isset($debugKitInHistoryMode)) {
  20. $content = $this->Toolbar->readCache('sql_log', $this->request->params['pass'][0]);
  21. }
  22. ?>
  23. <h2><?php echo __d('debug_kit', 'Sql Logs')?></h2>
  24. <?php if (!empty($content)) : ?>
  25. <?php foreach ($content['connections'] as $dbName => $explain): ?>
  26. <div class="sql-log-panel-query-log">
  27. <h4><?php echo $dbName ?></h4>
  28. <?php
  29. if (!isset($debugKitInHistoryMode)):
  30. $queryLog = $this->Toolbar->getQueryLogs($dbName, array(
  31. 'explain' => $explain, 'threshold' => $content['threshold']
  32. ));
  33. else:
  34. $queryLog = $content[$dbName];
  35. endif;
  36. if (empty($queryLog['queries'])):
  37. if (Configure::read('debug') < 2):
  38. echo ' ' . __d('debug_kit', 'No query logs when debug < 2.');
  39. else:
  40. echo ' ' . __d('debug_kit', 'No query logs.');
  41. endif;
  42. else:
  43. $hashes = array();
  44. $duplicate = 0;
  45. foreach ($queryLog['queries'] as $key => $val) {
  46. $hash = sha1($val['query']);
  47. if (!isset($hashes[$hash]) || $hashes[$hash] !== $val['affected']) {
  48. $hashes[$hash] = $val['affected'];
  49. continue;
  50. }
  51. $duplicate++;
  52. $queryLog['queries'][$key]['query'] = '<span class="alert-duplicate">' . $val['query'] . '</span>';
  53. }
  54. echo '<h5>';
  55. echo __d(
  56. 'debug_kit',
  57. 'Total Time: %s ms <br />Total Queries: %s queries',
  58. $queryLog['time'],
  59. $queryLog['count']
  60. );
  61. echo '</h5>';
  62. echo $this->Toolbar->table($queryLog['queries'], $headers, array('title' => 'SQL Log ' . $dbName));
  63. if ($duplicate) {
  64. echo '<p class="alert alert-warning">' . __d('debug_kit', '%s duplicate queries run.', $duplicate) . '</p>';
  65. }
  66. ?>
  67. <h4><?php echo __d('debug_kit', 'Query Explain:'); ?></h4>
  68. <div id="sql-log-explain-<?php echo $dbName ?>">
  69. <a id="debug-kit-explain-<?php echo $dbName ?>"> </a>
  70. <p><?php echo __d('debug_kit', 'Click an "Explain" link above, to see the query explanation.'); ?></p>
  71. </div>
  72. <?php endif; ?>
  73. </div>
  74. <?php endforeach; ?>
  75. <?php else:
  76. echo $this->Toolbar->message('Warning', __d('debug_kit', 'No active database connections'));
  77. endif;