forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.php
171 lines (135 loc) · 6.44 KB
/
stats.php
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Global Search Engine for Moodle
*
* @package search
* @category core
* @subpackage search_engine
* @author Michael Champanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 1.8
* @date 2008/03/31
* @version prepared for 2.0
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
* Prints some basic statistics about the current index.
* Does some diagnostics if you are logged in as an administrator.
*
*/
/**
* includes and requires
*/
require_once('../config.php');
require_once($CFG->dirroot.'/search/lib.php');
/// checks global search is enabled
if ($CFG->forcelogin) {
require_login();
}
if (empty($CFG->enableglobalsearch)) {
print_error('globalsearchdisabled', 'search');
}
/// check for php5, but don't die yet
require_once($CFG->dirroot.'/search/indexlib.php');
$indexinfo = new IndexInfo();
$site = get_site();
$strsearch = get_string('search', 'search');
$strquery = get_string('statistics', 'search');
$site = get_site();
$PAGE->set_url('/search/stats.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->navbar->add($strsearch, new moodle_url('/search/index.php'));
$PAGE->navbar->add($strquery, new moodle_url('/search/stats.php'));
$PAGE->set_title($strsearch);
$PAGE->set_heading($site->fullname);
echo $OUTPUT->header();
/// keep things pretty, even if php5 isn't available
echo $OUTPUT->box_start();
echo $OUTPUT->heading($strquery);
echo $OUTPUT->box_start();
$databasestr = get_string('database', 'search');
$documentsinindexstr = get_string('documentsinindex', 'search');
$deletionsinindexstr = get_string('deletionsinindex', 'search');
$documentsindatabasestr = get_string('documentsindatabase', 'search');
$databasestatestr = get_string('databasestate', 'search');
/// this table is only for admins, shows index directory size and location
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
$datadirectorystr = get_string('datadirectory', 'search');
$inindexdirectorystr = get_string('filesinindexdirectory', 'search');
$totalsizestr = get_string('totalsize', 'search');
$errorsstr = get_string('errors', 'search');
$solutionsstr = get_string('solutions', 'search');
$checkdirstr = get_string('checkdir', 'search');
$checkdbstr = get_string('checkdb', 'search');
$checkdiradvicestr = get_string('checkdiradvice', 'search');
$checkdbadvicestr = get_string('checkdbadvice', 'search');
$runindexerteststr = get_string('runindexertest', 'search');
$runindexerstr = get_string('runindexer', 'search');
$admin_table = new html_table();
$admin_table->tablealign = 'center';
$admin_table->align = array ('right', 'left');
$admin_table->wrap = array ('nowrap', 'nowrap');
$admin_table->cellpadding = 5;
$admin_table->cellspacing = 0;
$admin_table->width = '500';
$admin_table->data[] = array("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path.'</strong></em>');
$admin_table->data[] = array($inindexdirectorystr, $indexinfo->filecount);
$admin_table->data[] = array($totalsizestr, $indexinfo->size);
if ($indexinfo->time > 0) {
$admin_table->data[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time));
}
else {
$admin_table->data[] = array(get_string('createdon', 'search'), '-');
}
if (!$indexinfo->valid($errors)) {
$admin_table->data[] = array("<strong>{$errorsstr}</strong>", ' ');
foreach ($errors as $key => $value) {
$admin_table->data[] = array($key.' ... ', $value);
}
}
echo html_writer::table($admin_table);
$spacer = array('height'=>20, 'br'=>true);
echo $OUTPUT->spacer($spacer); // should be done with CSS instead
echo $OUTPUT->heading($solutionsstr);
unset($admin_table->data);
if (isset($errors['dir'])) {
$admin_table->data[] = array($checkdirstr, $checkdiradvicestr);
}
if (isset($errors['db'])) {
$admin_table->data[] = array($checkdbstr, $checkdbadvicestr);
}
$admin_table->data[] = array($runindexerteststr, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
$admin_table->data[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
echo html_writer::table($admin_table);
echo $OUTPUT->spacer($spacer) . '<br />';
}
/// this is the standard summary table for normal users, shows document counts
$table = new html_table();
$table->tablealign = 'center';
$table->align = array ('right', 'left');
$table->wrap = array ('nowrap', 'nowrap');
$table->cellpadding = 5;
$table->cellspacing = 0;
$table->width = '500';
$table->data[] = array("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}".SEARCH_DATABASE_TABLE.'</strong></em>');
/// add extra fields if we're admin
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
//don't want to confuse users if the two totals don't match (hint: they should)
$table->data[] = array($documentsinindexstr, $indexinfo->indexcount);
//*cough* they should match if deletions were actually removed from the index,
//as it turns out, they're only marked as deleted and not returned in search results
$table->data[] = array($deletionsinindexstr, (int)$indexinfo->indexcount - (int)$indexinfo->dbcount);
}
$table->data[] = array($documentsindatabasestr, $indexinfo->dbcount);
foreach($indexinfo->types as $type) {
if ($type->type == 'mod'){
$table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $type->name)."'", $type->records);
} else if ($type->type == 'block') {
$table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('pluginname', $type->name)."'", $type->records);
} else {
$table->data[] = array(get_string('documentsfor', 'search') . " '".get_string($type->name)."'", $type->records);
}
}
echo $OUTPUT->heading($databasestatestr);
echo html_writer::table($table);
echo $OUTPUT->box_end();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
?>