Base for a static organization website

SqlLogPanel.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  12. */
  13. App::uses('DebugPanel', 'DebugKit.Lib');
  14. /**
  15. * Provides debug information on the SQL logs and provides links to an ajax explain interface.
  16. *
  17. */
  18. class SqlLogPanel extends DebugPanel {
  19. /**
  20. * Minimum number of Rows Per Millisecond that must be returned by a query before an explain
  21. * is done.
  22. *
  23. * @var integer
  24. */
  25. public $slowRate = 20;
  26. /**
  27. * Gets the connection names that should have logs + dumps generated.
  28. *
  29. * @param \Controller|string $controller
  30. * @return array
  31. */
  32. public function beforeRender(Controller $controller) {
  33. if (!class_exists('ConnectionManager')) {
  34. return array();
  35. }
  36. $connections = array();
  37. $dbConfigs = ConnectionManager::sourceList();
  38. foreach ($dbConfigs as $configName) {
  39. $driver = null;
  40. $db = ConnectionManager::getDataSource($configName);
  41. if (
  42. (empty($db->config['driver']) && empty($db->config['datasource'])) ||
  43. !method_exists($db, 'getLog')
  44. ) {
  45. continue;
  46. }
  47. if (isset($db->config['datasource'])) {
  48. $driver = $db->config['datasource'];
  49. }
  50. $explain = false;
  51. $isExplainable = (preg_match('/(Mysql|Postgres)$/', $driver));
  52. if ($isExplainable) {
  53. $explain = true;
  54. }
  55. $connections[$configName] = $explain;
  56. }
  57. return array('connections' => $connections, 'threshold' => $this->slowRate);
  58. }
  59. }