PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/code/ryzom/tools/server/www/webtt/plugins/debug_kit/controllers/toolbar_access_controller.php

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 111 lines | 48 code | 6 blank | 57 comment | 7 complexity | 0d8924de0259009f7764cb670b4a617d MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * DebugKit ToolbarAccess Controller
  4. *
  5. * Allows retrieval of information from the debugKit internals.
  6. *
  7. * PHP versions 4 and 5
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  16. * @link http://cakephp.org
  17. * @package debug_kit
  18. * @subpackage debug_kit.controllers
  19. * @since DebugKit 1.1
  20. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  21. **/
  22. class ToolbarAccessController extends DebugKitAppController {
  23. /**
  24. * name
  25. *
  26. * @var string
  27. */
  28. var $name = 'ToolbarAccess';
  29. /**
  30. * Helpers
  31. *
  32. * @var array
  33. **/
  34. var $helpers = array(
  35. 'DebugKit.Toolbar' => array('output' => 'DebugKit.HtmlToolbar'),
  36. 'Javascript', 'Number', 'DebugKit.SimpleGraph'
  37. );
  38. /**
  39. * Components
  40. *
  41. * @var array
  42. **/
  43. var $components = array('RequestHandler', 'DebugKit.Toolbar');
  44. /**
  45. * Uses
  46. *
  47. * @var array
  48. **/
  49. var $uses = array('DebugKit.ToolbarAccess');
  50. /**
  51. * beforeFilter callback
  52. *
  53. * @return void
  54. **/
  55. function beforeFilter() {
  56. parent::beforeFilter();
  57. if (isset($this->Toolbar)) {
  58. $this->Toolbar->enabled = false;
  59. }
  60. $this->helpers['DebugKit.Toolbar']['cacheKey'] = $this->Toolbar->cacheKey;
  61. $this->helpers['DebugKit.Toolbar']['cacheConfig'] = 'debug_kit';
  62. }
  63. /**
  64. * Get a stored history state from the toolbar cache.
  65. *
  66. * @return void
  67. **/
  68. function history_state($key = null) {
  69. if (Configure::read('debug') == 0) {
  70. return $this->redirect($this->referer());
  71. }
  72. $oldState = $this->Toolbar->loadState($key);
  73. $this->set('toolbarState', $oldState);
  74. $this->set('debugKitInHistoryMode', true);
  75. }
  76. /**
  77. * Run SQL explain/profiling on queries. Checks the hash + the hashed queries,
  78. * if there is mismatch a 404 will be rendered. If debug == 0 a 404 will also be
  79. * rendered. No explain will be run if a 404 is made.
  80. *
  81. * @return void
  82. */
  83. function sql_explain() {
  84. if (
  85. !$this->RequestHandler->isPost() ||
  86. empty($this->data['log']['sql']) ||
  87. empty($this->data['log']['ds']) ||
  88. empty($this->data['log']['hash']) ||
  89. Configure::read('debug') == 0
  90. ) {
  91. $this->cakeError('error404', array(array(
  92. 'message' => 'Invalid parameters'
  93. )));
  94. }
  95. App::import('Core', 'Security');
  96. $hash = Security::hash($this->data['log']['sql'] . $this->data['log']['ds'], null, true);
  97. if ($hash !== $this->data['log']['hash']) {
  98. $this->cakeError('error404', array(array(
  99. 'message' => 'Invalid parameters'
  100. )));
  101. }
  102. $result = $this->ToolbarAccess->explainQuery($this->data['log']['ds'], $this->data['log']['sql']);
  103. $this->set(compact('result'));
  104. }
  105. }