Refactor PhpMyAdmin\Server\Status\Monitor methods
Replaces static methods with instance methods. Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
d0c1876552
commit
03896a7a0a
@ -28,17 +28,17 @@ class Monitor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForMonitor(Data $serverStatusData)
|
||||
public function getHtmlForMonitor(Data $serverStatusData)
|
||||
{
|
||||
$retval = self::getHtmlForTabLinks();
|
||||
$retval = $this->getHtmlForTabLinks();
|
||||
|
||||
$retval .= self::getHtmlForSettingsDialog();
|
||||
$retval .= $this->getHtmlForSettingsDialog();
|
||||
|
||||
$retval .= self::getHtmlForInstructionsDialog();
|
||||
$retval .= $this->getHtmlForInstructionsDialog();
|
||||
|
||||
$retval .= self::getHtmlForAddChartDialog();
|
||||
$retval .= $this->getHtmlForAddChartDialog();
|
||||
|
||||
$retval .= self::getHtmlForAnalyseDialog();
|
||||
$retval .= $this->getHtmlForAnalyseDialog();
|
||||
|
||||
$retval .= '<table class="clearfloat tdblock" id="chartGrid"></table>';
|
||||
$retval .= '<div id="logTable">';
|
||||
@ -67,7 +67,7 @@ class Monitor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForAnalyseDialog()
|
||||
public function getHtmlForAnalyseDialog()
|
||||
{
|
||||
$retval = '<div id="logAnalyseDialog" title="';
|
||||
$retval .= __('Log statistics') . '" class="hide">';
|
||||
@ -111,7 +111,7 @@ class Monitor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForInstructionsDialog()
|
||||
public function getHtmlForInstructionsDialog()
|
||||
{
|
||||
$retval = '<div id="monitorInstructionsDialog" title="';
|
||||
$retval .= __('Monitor Instructions') . '" class="hide">';
|
||||
@ -172,7 +172,7 @@ class Monitor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForAddChartDialog()
|
||||
public function getHtmlForAddChartDialog()
|
||||
{
|
||||
$retval = '<div id="addChartDialog" title="'
|
||||
. __('Add chart') . '" class="hide">';
|
||||
@ -254,7 +254,7 @@ class Monitor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForTabLinks()
|
||||
public function getHtmlForTabLinks()
|
||||
{
|
||||
$retval = '<div class="tabLinks">';
|
||||
$retval .= '<a href="#pauseCharts">';
|
||||
@ -279,7 +279,7 @@ class Monitor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForSettingsDialog()
|
||||
public function getHtmlForSettingsDialog()
|
||||
{
|
||||
$retval = '<div class="popupContent settingsPopup">';
|
||||
$retval .= '<a href="#addNewChart">';
|
||||
@ -345,7 +345,7 @@ class Monitor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForClientSideDataAndLinks(Data $serverStatusData)
|
||||
public function getHtmlForClientSideDataAndLinks(Data $serverStatusData)
|
||||
{
|
||||
/**
|
||||
* Define some data needed on the client side
|
||||
@ -377,7 +377,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForChartingData()
|
||||
public function getJsonForChartingData()
|
||||
{
|
||||
$ret = json_decode($_REQUEST['requiredData'], true);
|
||||
$statusVars = array();
|
||||
@ -385,7 +385,7 @@ class Monitor
|
||||
$sysinfo = $cpuload = $memory = 0;
|
||||
|
||||
/* Accumulate all required variables and data */
|
||||
list($serverVars, $statusVars, $ret) = self::getJsonForChartingDataGet(
|
||||
list($serverVars, $statusVars, $ret) = $this->getJsonForChartingDataGet(
|
||||
$ret, $serverVars, $statusVars, $sysinfo, $cpuload, $memory
|
||||
);
|
||||
|
||||
@ -414,7 +414,7 @@ class Monitor
|
||||
}
|
||||
|
||||
// ...and now assign them
|
||||
$ret = self::getJsonForChartingDataSet($ret, $statusVarValues, $serverVarValues);
|
||||
$ret = $this->getJsonForChartingDataSet($ret, $statusVarValues, $serverVarValues);
|
||||
|
||||
$ret['x'] = microtime(true) * 1000;
|
||||
return $ret;
|
||||
@ -429,7 +429,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForChartingDataSet(array $ret, array $statusVarValues, array $serverVarValues)
|
||||
public function getJsonForChartingDataSet(array $ret, array $statusVarValues, array $serverVarValues)
|
||||
{
|
||||
foreach ($ret as $chart_id => $chartNodes) {
|
||||
foreach ($chartNodes as $node_id => $nodeDataPoints) {
|
||||
@ -462,7 +462,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForChartingDataGet(
|
||||
public function getJsonForChartingDataGet(
|
||||
array $ret, array $serverVars, array $statusVars, $sysinfo, $cpuload, $memory
|
||||
) {
|
||||
// For each chart
|
||||
@ -472,7 +472,7 @@ class Monitor
|
||||
// For each data point in the series (usually just 1)
|
||||
foreach ($nodeDataPoints as $point_id => $dataPoint) {
|
||||
list($serverVars, $statusVars, $ret[$chart_id][$node_id][$point_id])
|
||||
= self::getJsonForChartingDataSwitch(
|
||||
= $this->getJsonForChartingDataSwitch(
|
||||
$dataPoint['type'], $dataPoint['name'], $serverVars,
|
||||
$statusVars, $ret[$chart_id][$node_id][$point_id],
|
||||
$sysinfo, $cpuload, $memory
|
||||
@ -497,7 +497,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForChartingDataSwitch(
|
||||
public function getJsonForChartingDataSwitch(
|
||||
$type, $pName, array $serverVars, array $statusVars, array $ret,
|
||||
$sysinfo, $cpuload, $memory
|
||||
) {
|
||||
@ -564,7 +564,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForLogDataTypeSlow($start, $end)
|
||||
public function getJsonForLogDataTypeSlow($start, $end)
|
||||
{
|
||||
$query = 'SELECT start_time, user_host, ';
|
||||
$query .= 'Sec_to_Time(Sum(Time_to_Sec(query_time))) as query_time, ';
|
||||
@ -630,7 +630,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForLogDataTypeGeneral($start, $end)
|
||||
public function getJsonForLogDataTypeGeneral($start, $end)
|
||||
{
|
||||
$limitTypes = '';
|
||||
if (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes']) {
|
||||
@ -683,7 +683,7 @@ class Monitor
|
||||
// there's been other queries
|
||||
$temp = $return['rows'][$insertTablesFirst]['argument'];
|
||||
$return['rows'][$insertTablesFirst]['argument']
|
||||
.= self::getSuspensionPoints(
|
||||
.= $this->getSuspensionPoints(
|
||||
$temp[strlen($temp) - 1]
|
||||
);
|
||||
|
||||
@ -737,7 +737,7 @@ class Monitor
|
||||
*
|
||||
* @return null|string Return suspension points if needed
|
||||
*/
|
||||
public static function getSuspensionPoints($lastChar)
|
||||
public function getSuspensionPoints($lastChar)
|
||||
{
|
||||
if ($lastChar != '.') {
|
||||
return '<br/>...';
|
||||
@ -751,7 +751,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForLoggingVars()
|
||||
public function getJsonForLoggingVars()
|
||||
{
|
||||
if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
|
||||
$value = $GLOBALS['dbi']->escapeString($_REQUEST['varValue']);
|
||||
@ -781,7 +781,7 @@ class Monitor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getJsonForQueryAnalyzer()
|
||||
public function getJsonForQueryAnalyzer()
|
||||
{
|
||||
$return = array();
|
||||
|
||||
|
||||
@ -16,6 +16,9 @@ require_once 'libraries/replication.inc.php';
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
$statusMonitor = new Monitor();
|
||||
$statusData = new Data();
|
||||
|
||||
/**
|
||||
* Ajax request
|
||||
*/
|
||||
@ -27,7 +30,7 @@ if ($response->isAjax()) {
|
||||
if (isset($_REQUEST['chart_data'])) {
|
||||
switch($_REQUEST['type']) {
|
||||
case 'chartgrid': // Data for the monitor
|
||||
$ret = Monitor::getJsonForChartingData();
|
||||
$ret = $statusMonitor->getJsonForChartingData();
|
||||
$response->addJSON('message', $ret);
|
||||
exit;
|
||||
}
|
||||
@ -39,26 +42,26 @@ if ($response->isAjax()) {
|
||||
$end = intval($_REQUEST['time_end']);
|
||||
|
||||
if ($_REQUEST['type'] == 'slow') {
|
||||
$return = Monitor::getJsonForLogDataTypeSlow($start, $end);
|
||||
$return = $statusMonitor->getJsonForLogDataTypeSlow($start, $end);
|
||||
$response->addJSON('message', $return);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_REQUEST['type'] == 'general') {
|
||||
$return = Monitor::getJsonForLogDataTypeGeneral($start, $end);
|
||||
$return = $statusMonitor->getJsonForLogDataTypeGeneral($start, $end);
|
||||
$response->addJSON('message', $return);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['logging_vars'])) {
|
||||
$loggingVars = Monitor::getJsonForLoggingVars();
|
||||
$loggingVars = $statusMonitor->getJsonForLoggingVars();
|
||||
$response->addJSON('message', $loggingVars);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['query_analyzer'])) {
|
||||
$return = Monitor::getJsonForQueryAnalyzer();
|
||||
$return = $statusMonitor->getJsonForQueryAnalyzer();
|
||||
$response->addJSON('message', $return);
|
||||
exit;
|
||||
}
|
||||
@ -85,18 +88,12 @@ $scripts->addFile('jqplot/plugins/jqplot.byteFormatter.js');
|
||||
$scripts->addFile('server_status_monitor.js');
|
||||
$scripts->addFile('server_status_sorter.js');
|
||||
|
||||
|
||||
/**
|
||||
* start output
|
||||
*/
|
||||
$serverStatusData = new Data();
|
||||
|
||||
/**
|
||||
* Output
|
||||
*/
|
||||
$response->addHTML('<div>');
|
||||
$response->addHTML($serverStatusData->getMenuHtml());
|
||||
$response->addHTML(Monitor::getHtmlForMonitor($serverStatusData));
|
||||
$response->addHTML(Monitor::getHtmlForClientSideDataAndLinks($serverStatusData));
|
||||
$response->addHTML($statusData->getMenuHtml());
|
||||
$response->addHTML($statusMonitor->getHtmlForMonitor($statusData));
|
||||
$response->addHTML($statusMonitor->getHtmlForClientSideDataAndLinks($statusData));
|
||||
$response->addHTML('</div>');
|
||||
exit;
|
||||
|
||||
@ -22,18 +22,21 @@ use PHPUnit\Framework\TestCase;
|
||||
class MonitorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
*
|
||||
* @return void
|
||||
* @var Data
|
||||
*/
|
||||
public $serverStatusData;
|
||||
private $statusData;
|
||||
|
||||
/**
|
||||
* @var Monitor
|
||||
*/
|
||||
private $statusMonitor;
|
||||
|
||||
/**
|
||||
* Test for setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
//$_REQUEST
|
||||
$_REQUEST['log'] = "index1";
|
||||
@ -71,7 +74,7 @@ class MonitorTest extends TestCase
|
||||
"Com_empty_query" => "0",
|
||||
);
|
||||
|
||||
$server_variables= array(
|
||||
$server_variables = array(
|
||||
"auto_increment_increment" => "1",
|
||||
"auto_increment_offset" => "1",
|
||||
"automatic_sp_privileges" => "ON",
|
||||
@ -112,11 +115,12 @@ class MonitorTest extends TestCase
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->serverStatusData = new Data();
|
||||
$this->statusMonitor = new Monitor();
|
||||
$this->statusData = new Data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monitor::getHtmlForMonitor
|
||||
* Test for getHtmlForMonitor
|
||||
*
|
||||
* @return void
|
||||
* @group medium
|
||||
@ -124,9 +128,9 @@ class MonitorTest extends TestCase
|
||||
public function testPMAGetHtmlForMonitor()
|
||||
{
|
||||
//Call the test function
|
||||
$html = Monitor::getHtmlForMonitor($this->serverStatusData);
|
||||
$html = $this->statusMonitor->getHtmlForMonitor($this->statusData);
|
||||
|
||||
//validate 1: Monitor::getHtmlForTabLinks
|
||||
//validate 1: getHtmlForTabLinks
|
||||
$this->assertContains(
|
||||
'<div class="tabLinks">',
|
||||
$html
|
||||
@ -143,7 +147,7 @@ class MonitorTest extends TestCase
|
||||
__('Done dragging (rearranging) charts'),
|
||||
$html
|
||||
);
|
||||
//validate 2: Monitor::getHtmlForSettingsDialog
|
||||
//validate 2: getHtmlForSettingsDialog
|
||||
$this->assertContains(
|
||||
'<div class="popupContent settingsPopup">',
|
||||
$html
|
||||
@ -160,7 +164,7 @@ class MonitorTest extends TestCase
|
||||
'<option>3</option>',
|
||||
$html
|
||||
);
|
||||
//validate 3: Monitor::getHtmlForInstructionsDialog
|
||||
//validate 3: getHtmlForInstructionsDialog
|
||||
$this->assertContains(
|
||||
__('Monitor Instructions'),
|
||||
$html
|
||||
@ -169,7 +173,7 @@ class MonitorTest extends TestCase
|
||||
'monitorInstructionsDialog',
|
||||
$html
|
||||
);
|
||||
//validate 4: Monitor::getHtmlForAddChartDialog
|
||||
//validate 4: getHtmlForAddChartDialog
|
||||
$this->assertContains(
|
||||
'<div id="addChartDialog"',
|
||||
$html
|
||||
@ -189,16 +193,16 @@ class MonitorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monitor::getHtmlForClientSideDataAndLinks
|
||||
* Test for getHtmlForClientSideDataAndLinks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMAGetHtmlForClientSideDataAndLinks()
|
||||
{
|
||||
//Call the test function
|
||||
$html = Monitor::getHtmlForClientSideDataAndLinks($this->serverStatusData);
|
||||
$html = $this->statusMonitor->getHtmlForClientSideDataAndLinks($this->statusData);
|
||||
|
||||
//validate 1: Monitor::getHtmlForClientSideDataAndLinks
|
||||
//validate 1: getHtmlForClientSideDataAndLinks
|
||||
$from = '<form id="js_data" class="hide">'
|
||||
. '<input type="hidden" name="server_time"';
|
||||
$this->assertContains(
|
||||
@ -221,7 +225,7 @@ class MonitorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monitor::getJsonForLogDataTypeSlow
|
||||
* Test for getJsonForLogDataTypeSlow
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -254,7 +258,7 @@ class MonitorTest extends TestCase
|
||||
//Call the test function
|
||||
$start = 0;
|
||||
$end = 10;
|
||||
$ret = Monitor::getJsonForLogDataTypeSlow($start, $end);
|
||||
$ret = $this->statusMonitor->getJsonForLogDataTypeSlow($start, $end);
|
||||
|
||||
$result_rows = array(
|
||||
array('sql_text' => 'insert sql_text', '#' => 11),
|
||||
@ -276,7 +280,7 @@ class MonitorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monitor::getJsonForLogDataTypeGeneral
|
||||
* Test for getJsonForLogDataTypeGeneral
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -313,7 +317,7 @@ class MonitorTest extends TestCase
|
||||
//Call the test function
|
||||
$start = 0;
|
||||
$end = 10;
|
||||
$ret = Monitor::getJsonForLogDataTypeGeneral($start, $end);
|
||||
$ret = $this->statusMonitor->getJsonForLogDataTypeGeneral($start, $end);
|
||||
|
||||
$result_rows = array(
|
||||
$value,
|
||||
@ -336,7 +340,7 @@ class MonitorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monitor::getJsonForLoggingVars
|
||||
* Test for getJsonForLoggingVars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -361,7 +365,7 @@ class MonitorTest extends TestCase
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Call the test function
|
||||
$ret = Monitor::getJsonForLoggingVars();
|
||||
$ret = $this->statusMonitor->getJsonForLoggingVars();
|
||||
|
||||
//validate that, the result is the same as fetchResult
|
||||
$this->assertEquals(
|
||||
@ -371,7 +375,7 @@ class MonitorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monitor::getJsonForQueryAnalyzer
|
||||
* Test for getJsonForQueryAnalyzer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -402,7 +406,7 @@ class MonitorTest extends TestCase
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Call the test function
|
||||
$ret = Monitor::getJsonForQueryAnalyzer();
|
||||
$ret = $this->statusMonitor->getJsonForQueryAnalyzer();
|
||||
|
||||
$this->assertEquals(
|
||||
'cached_affected_rows',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user