-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger.admin.inc
127 lines (117 loc) · 4.65 KB
/
debugger.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @file
* Form with Settings
*
*/
/**
* Menu callback for the settings form.
*/
function debugger_admin_form() {
$form['debugger'] = array(
'#type' => 'fieldset',
'#title' => t('General Drupal debugger settings.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['debugger']['debugger_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable debugger'),
'#description' => t('Be careful, it could diametrically decrease your website performance.'),
'#default_value' => variable_get('debugger_enable', FALSE),
);
$form['debugger']['debugger_enable_error_handler'] = array(
'#type' => 'checkbox',
'#title' => t('Track number of errors.'),
'#description' => t('Replace Drupal error handler to monitor notices, warnings and errors.'),
'#default_value' => variable_get('debugger_enable_error_handler', TRUE),
'#disabled' => !variable_get('debugger_enable', FALSE),
);
$form['debugger']['debugger_enable_sql_queries'] = array(
'#type' => 'checkbox',
'#title' => t('Track database queries.'),
'#description' => t('Debug database queries and check execution times and which module run it.'),
'#default_value' => variable_get('debugger_enable_sql_queries', FALSE),
'#disabled' => !variable_get('debugger_enable', FALSE),
);
$form['debugger']['debugger_enable_admin'] = array(
'#type' => 'checkbox',
'#title' => t('Enable debugger on admin pages'),
'#description' => t('Run debugger on admin pages. Note: If you enable this and something goes wrong, you could have problem disabling this module. Please test it on normal pages, before enabling it.'),
'#default_value' => variable_get('debugger_enable_admin', FALSE),
'#disabled' => !variable_get('debugger_enable', FALSE),
);
$form['debugger']['debugger_enable_cli'] = array(
'#type' => 'checkbox',
'#title' => t('Enable debugger for CLI interface.'),
'#description' => t('Run debugger in CLI interface (such as drush).'),
'#default_value' => variable_get('debugger_enable_cli', FALSE),
'#disabled' => !variable_get('debugger_enable', FALSE),
);
$form['debugger']['debugger_auto_disable'] = array(
'#type' => 'checkbox',
'#title' => t('Auto disable debugger on fatal errors.'),
'#description' => t('When page will crash or timeout accured, debugger will be disabled for stability reasons. You have to enable it manually again.'),
'#default_value' => variable_get('debugger_auto_disable', TRUE),
'#disabled' => !variable_get('debugger_enable', FALSE),
);
$form['debugger_advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced Drupal debugger settings.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['debugger_advanced']['debugger_precision_time'] = array(
'#type' => 'textfield',
'#title' => t('Precision time'),
'#description' => t('All functions executed below that time are ignored from tracing. Be careful, it could diametrically decrease your website performance.'),
'#default_value' => variable_get('debugger_precision_time', D_MIN_TIMER),
'#size' => '8',
'#field_suffix' => 'ms',
);
$form['debugger_data'] = array(
'#type' => 'fieldset',
'#title' => t('Operations on stored data.'),
'#collapsible' => TRUE,
);
$form['debugger_data']['debugger_clear_all_data'] = array(
'#type' => 'submit',
'#value' => t('Clear all data generated by debugger.'),
'#submit' => array('debugger_clear_all_data_submit'),
'#suffix' => '<br>' . print_r(debugger_db_tables('debugger_%%', 'SELECT COUNT(*) FROM {}'),true),
);
return system_settings_form($form);
}
/**
* Submit callback; clear system caches.
*
* @ingroup forms
*/
function debugger_clear_all_data_submit($form, &$form_state = array()) {
debugger_api_clear_data();
drupal_set_message(t('Debugger data has been cleared.'));
$form_state['redirect'] = 'admin/config/development/debugger';
drupal_goto($form_state['redirect']);
}
/**
* Get a list of tables in the db. Make additional operation for each of it if necessary.
*/
function debugger_db_tables($which = '*', $op = NULL) {
global $db_type;
$res = array();
switch ($db_type) {
case 'mysql':
case 'mysqli':
// get auto_increment values and names of all tables
$query = "show tables" . ($which != '*' ? " LIKE '%s'" : '');
$tables = db_query($query, $which);
while ($table = db_fetch_array($tables)) {
$tname = current($table);
$res[$tname] = $op ? db_query(str_replace('{}', "{{$tname}}", $op))->fetchField() : $tname;
}
case 'pgsql':
default:
/* TODO: database not supported */
}
return $res;
}