AdminDebug   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 7
ccs 0
cts 36
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A trackStats() 0 3 1
A action_index() 0 2 1
A action_viewquery() 0 42 5
1
<?php
2
3
/**
4
 * Functions concerned with viewing queries, and is used for debugging.
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * This file contains code covered by:
11
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
12
 *
13
 * @version 2.0 Beta 1
14
 *
15
 */
16
17
namespace ElkArte\AdminController;
18
19
use ElkArte\AbstractController;
20
use ElkArte\Debug;
21
use ElkArte\Exceptions\Exception;
22
23
/**
24
 * Admin class for interfacing with the debug function viewquery
25
 */
26
class AdminDebug extends AbstractController
27
{
28
	/**
29
	 * {@inheritDoc}
30
	 */
31
	public function trackStats($action = '')
32
	{
33
		return false;
34
	}
35
36
	/**
37
	 * Main dispatcher.
38
	 *
39
	 * @see AbstractController::action_index()
40
	 */
41
	public function action_index()
42
	{
43
		// what to do first... viewquery! What, it'll work or it won't.
44
		// $this->action_viewquery();
45
	}
46
47
	/**
48
	 * Show the database queries for debugging
49
	 *
50
	 * What this does:
51
	 *
52
	 * - Toggles the session variable 'view_queries'.
53
	 * - Views a list of queries and analyzes them.
54
	 * - Requires the admin_forum permission.
55
	 * - Is accessed via ?action=viewquery.
56
	 * - Strings in this function have not been internationalized.
57
	 */
58
	public function action_viewquery(): void
59
	{
60
		global $context, $db_show_debug;
61
62
		// We should have debug mode enabled, as well as something to display!
63
		if ($db_show_debug !== true || !isset($_SESSION['debug']))
64
		{
65
			throw new Exception('no_access', false);
66
		}
67
68
		// Don't allow except for administrators.
69
		isAllowedTo('admin_forum');
70
71
		$debug = Debug::instance();
72
73
		// If we're just hiding/showing, do it now.
74
		if ($this->_req->compareQuery('sa', 'hide', 'trim|strval'))
75
		{
76
			$debug->toggleViewQueries();
77
78
			if (str_contains($_SESSION['old_url'], 'action=viewquery'))
79
			{
80
				redirectexit();
81
			}
82
			else
83
			{
84
				redirectexit($_SESSION['old_url']);
85
			}
86
		}
87
88
		// Looking at a specific query?
89
		$query_id = $this->_req->getQuery('qq', 'intval', 0);
90
		--$query_id;
91
92
		// Just to stay on the safe side, better remove any layer and add back only html
93
		$layers = theme()->getLayers();
94
		$layers->removeAll();
95
		$layers->add('html');
96
		theme()->getTemplates()->load('Admin');
97
98
		$context['sub_template'] = 'viewquery';
99
		$context['queries_data'] = $debug->viewQueries($query_id);
100
	}
101
}
102