Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 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
 * @since         DebugKit 1.1
12
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
13
 */
14
 
15
App::uses('Security', 'Utility');
16
App::uses('DebugKitAppController', 'DebugKit.Controller');
17
 
18
/**
19
 * DebugKit ToolbarAccess Controller
20
 *
21
 * Allows retrieval of information from the debugKit internals.
22
 *
23
 * @since         DebugKit 1.1
24
 */
25
class ToolbarAccessController extends DebugKitAppController {
26
 
27
/**
28
 * name
29
 *
30
 * @var string
31
 */
32
	public $name = 'ToolbarAccess';
33
 
34
/**
35
 * Helpers
36
 *
37
 * @var array
38
 */
39
	public $helpers = array(
40
		'DebugKit.Toolbar' => array('output' => 'DebugKit.HtmlToolbar'),
41
		'Js', 'Number', 'DebugKit.SimpleGraph'
42
	);
43
 
44
/**
45
 * Components
46
 *
47
 * @var array
48
 */
49
	public $components = array('RequestHandler', 'DebugKit.Toolbar');
50
 
51
/**
52
 * Uses
53
 *
54
 * @var array
55
 */
56
	public $uses = array('DebugKit.ToolbarAccess');
57
 
58
/**
59
 * beforeFilter callback
60
 *
61
 * @return void
62
 */
63
	public function beforeFilter() {
64
		parent::beforeFilter();
65
		if (isset($this->Toolbar)) {
66
			$this->Components->disable('Toolbar');
67
		}
68
		$this->helpers['DebugKit.Toolbar']['cacheKey'] = $this->Toolbar->cacheKey;
69
		$this->helpers['DebugKit.Toolbar']['cacheConfig'] = 'debug_kit';
70
 
71
		if (isset($this->Auth) && method_exists($this->Auth, 'mapActions')) {
72
			$this->Auth->mapActions(array(
73
				'read' => array('history_state', 'sql_explain')
74
			));
75
		}
76
	}
77
 
78
/**
79
 * Get a stored history state from the toolbar cache.
80
 *
81
 * @param null $key
82
 * @return void
83
 */
84
	public function history_state($key = null) {
85
		if (Configure::read('debug') == 0) {
86
			return $this->redirect($this->referer());
87
		}
88
		$oldState = $this->Toolbar->loadState($key);
89
		$this->set('toolbarState', $oldState);
90
		$this->set('debugKitInHistoryMode', true);
91
		$this->viewClass = null;
92
		$this->layout = null;
93
	}
94
 
95
/**
96
 * Run SQL explain/profiling on queries. Checks the hash + the hashed queries,
97
 * if there is mismatch a 404 will be rendered. If debug == 0 a 404 will also be
98
 * rendered. No explain will be run if a 404 is made.
99
 *
100
 * @throws BadRequestException
101
 * @return void
102
 */
103
	public function sql_explain() {
104
		if (
105
			!$this->request->is('post') ||
106
			empty($this->request->data['log']['sql']) ||
107
			empty($this->request->data['log']['ds']) ||
108
			empty($this->request->data['log']['hash']) ||
109
			Configure::read('debug') == 0
110
		) {
111
			throw new BadRequestException('Invalid parameters');
112
		}
113
		$hash = Security::hash($this->request->data['log']['sql'] . $this->request->data['log']['ds'], 'sha1', true);
114
		if ($hash !== $this->request->data['log']['hash']) {
115
			throw new BadRequestException('Invalid parameters');
116
		}
117
		$result = $this->ToolbarAccess->explainQuery($this->request->data['log']['ds'], $this->request->data['log']['sql']);
118
		$this->set(compact('result'));
119
	}
120
 
121
}