This repository was archived by the owner on Oct 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAPI.php
More file actions
executable file
·145 lines (118 loc) · 3.73 KB
/
API.php
File metadata and controls
executable file
·145 lines (118 loc) · 3.73 KB
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
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\DBHealth;
use Piwik\Db;
use Piwik\Log;
use Piwik\Piwik;
use Piwik\View;
use Piwik\Access;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\BaseFilter;
use Piwik\Plugin\ControllerAdmin;
use Piwik\DataTable\Row;
/**
* API for plugin DBHealth
*
* @method static \Piwik\Plugins\DBHealth\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* Return Database Table Status data
*
* @return DataTable
*/
function getProblematicSegments() {
Piwik::checkUserHasSuperUserAccess();
$dataTable = new DataTable();
$query = "SELECT name,idsegment,definition,login,enable_only_idsite,ts_created,ts_last_edit FROM `matomo_segment` where definition like '%@%' and deleted not like '1' ";
$result = $this->getDb()->fetchAssoc($query);
foreach ($result as $item) {
$dataTable->addRowsFromSimpleArray(array(
array('Name' => $item['name'],
'Idsegment' => $item['idsegment'],
'Definition' => $item['definition'],
'Used on siteId (0=all)' => $item['enable_only_idsite'],
'Created by' => $item['login'],
'Creation date' => $item['ts_created'],
'Last updated' => $item['ts_last_edit']
)
));
}
return $dataTable;
}
/**
* Return Database Status variables
*
* @return DataTable
*/
function getMysqlStatusData()
{
Piwik::checkUserHasSuperUserAccess();
$dataTable = new DataTable();
$query = "SHOW STATUS";
$result = $this->getDb()->fetchAssoc($query);
foreach ($result as $item) {
$dataTable->addRowsFromSimpleArray(array(
array('Name' => $item['Variable_name'], 'Value' => $item['Value'])
));
}
return $dataTable;
}
/**
* Return Database Table Status data
*
* @return DataTable
*/
function getMysqlTableStatus() {
Piwik::checkUserHasSuperUserAccess();
$dataTable = new DataTable();
$query = "SHOW TABLE STATUS";
$result = $this->getDb()->fetchAssoc($query);
foreach ($result as $item) {
$dataTable->addRowsFromSimpleArray(array(
array('Name' => $item['Name'],
'Collation' => $item['Collation'],
'Engine' => $item['Engine'],
'Rows' => $item['Rows'],
'Avg_row_length' => $item['Avg_row_length'],
'Data_length' => $item['Data_length'],
'Max_data_length' => $item['Max_data_length'],
'Index_length' => $item['Index_length'],
'Data_free' => $item['Data_free'],
'Checksum' => $item['Checksum']
)
));
}
return $dataTable;
}
/**
* Return Database Settings Variable data
*
* @return DataTable
*/
function getMysqlVariableData()
{
Piwik::checkUserHasSuperUserAccess();
$dataTable = new DataTable();
$query = "SHOW VARIABLES";
$result = $this->getDb()->fetchAssoc($query);
foreach ($result as $item) {
$dataTable->addRowsFromSimpleArray(array(
array('Name' => $item['Variable_name'], 'Value' => $item['Value'])
));
}
return $dataTable;
}
private function getDb()
{
return Db::get();
}
}