/
query_log.php
82 lines (69 loc) · 2.29 KB
/
query_log.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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\System\Optimization;
use Concrete\Core\Legacy\Loader;
use Concrete\Core\Logging\Query\Logger;
use Concrete\Core\Logging\Query\LogList;
use Concrete\Core\Page\Controller\DashboardPageController;
class QueryLog extends DashboardPageController
{
public function view()
{
$l = new LogList();
$pagination = $l->getPagination();
$pagination->setMaxPerPage(10);
$entries = $pagination->getCurrentPageResults();
$this->set('list', $l);
$this->set('entries', $entries);
$this->set('total', Logger::getTotalLogged());
$this->set('pagination', $pagination);
}
public function inspect($query)
{
$this->set('query', h($query));
$this->set('parameters', Logger::getParametersForQuery($query));
$this->setThemeViewTemplate('dialog.php');
}
public function clear()
{
if (Loader::helper('validation/token')->validate('clear')) {
$l = new Logger();
$l->clearQueryLog();
$this->redirect('/dashboard/system/optimization/query_log', 'cleared');
}
}
public function cleared()
{
$this->set('message', t('Database query log cleared.'));
$this->view();
}
public function csv()
{
if (!Loader::helper('validation/token')->validate('csv')) {
$this->redirect('/dashboard/system/optimization/query_log');
} else {
$l = new LogList();
$entries = $l->get(0);
$fileName = "Database Query Log Results";
header("Content-Type: text/csv");
header("Cache-control: private");
header("Pragma: public");
$date = date('Ymd');
header("Content-Disposition: attachment; filename=" . $fileName . "_form_data_{$date}.csv");
$fp = fopen('php://output', 'w');
// write the columns
$row = array(
t('Times Run'),
t('Query'),
);
fputcsv($fp, $row);
foreach ($entries as $ent) {
fputcsv($fp, array(
$ent['queryTotal'],
$ent['query'],
));
}
fclose($fp);
die;
}
}
}