Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2021-09-10 23:55:05 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2021-09-10 23:55:05 +0300
commit83091680cc9cab37ffcf29ed839f5f126527643e (patch)
tree346e4b640335056e5ae26e969ac4312a9b1cd561
parent38fda677bdfbfbe4314b2853b852a67598b7f2f2 (diff)
Extract actions from controllers to new controllers
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r--libraries/classes/Controllers/Server/Status/Monitor/ChartingDataController.php57
-rw-r--r--libraries/classes/Controllers/Server/Status/Monitor/GeneralLogController.php65
-rw-r--r--libraries/classes/Controllers/Server/Status/Monitor/LogVarsController.php61
-rw-r--r--libraries/classes/Controllers/Server/Status/Monitor/QueryAnalyzerController.php61
-rw-r--r--libraries/classes/Controllers/Server/Status/Monitor/SlowLogController.php61
-rw-r--r--libraries/classes/Controllers/Server/Status/MonitorController.php140
-rw-r--r--libraries/classes/Controllers/Server/Status/Processes/KillController.php64
-rw-r--r--libraries/classes/Controllers/Server/Status/Processes/RefreshController.php44
-rw-r--r--libraries/classes/Controllers/Server/Status/ProcessesController.php58
-rw-r--r--libraries/classes/Controllers/Server/UserGroupsController.php73
-rw-r--r--libraries/classes/Controllers/Server/UserGroupsFormController.php104
-rw-r--r--libraries/classes/Controllers/Server/Variables/GetVariableController.php66
-rw-r--r--libraries/classes/Controllers/Server/Variables/SetVariableController.php153
-rw-r--r--libraries/classes/Controllers/Server/VariablesController.php120
-rw-r--r--libraries/classes/Controllers/ThemeSetController.php47
-rw-r--r--libraries/classes/Controllers/ThemesController.php25
-rw-r--r--libraries/routes.php33
-rw-r--r--libraries/services_controllers.php102
-rw-r--r--phpstan-baseline.neon9
-rw-r--r--psalm-baseline.xml84
-rw-r--r--test/classes/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php96
-rw-r--r--test/classes/Controllers/Server/Status/Monitor/LogVarsControllerTest.php71
-rw-r--r--test/classes/Controllers/Server/Status/Monitor/QueryAnalyzerControllerTest.php86
-rw-r--r--test/classes/Controllers/Server/Status/Monitor/SlowLogControllerTest.php88
-rw-r--r--test/classes/Controllers/Server/Status/MonitorControllerTest.php193
-rw-r--r--test/classes/Controllers/Server/Status/Processes/RefreshControllerTest.php135
-rw-r--r--test/classes/Controllers/Server/Status/ProcessesControllerTest.php104
-rw-r--r--test/classes/Controllers/Server/VariablesControllerTest.php2
28 files changed, 1454 insertions, 748 deletions
diff --git a/libraries/classes/Controllers/Server/Status/Monitor/ChartingDataController.php b/libraries/classes/Controllers/Server/Status/Monitor/ChartingDataController.php
new file mode 100644
index 0000000000..50235fd2fb
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Status/Monitor/ChartingDataController.php
@@ -0,0 +1,57 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Url;
+
+final class ChartingDataController extends AbstractController
+{
+ /** @var Monitor */
+ private $monitor;
+
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param Data $data
+ * @param Monitor $monitor
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $data, $monitor, $dbi)
+ {
+ parent::__construct($response, $template, $data);
+ $this->monitor = $monitor;
+ $this->dbi = $dbi;
+ }
+
+ public function __invoke(): void
+ {
+ global $errorUrl;
+
+ $params = ['requiredData' => $_POST['requiredData'] ?? null];
+ $errorUrl = Url::getFromRoute('/');
+
+ if ($this->dbi->isSuperUser()) {
+ $this->dbi->selectDb('mysql');
+ }
+
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $this->response->addJSON([
+ 'message' => $this->monitor->getJsonForChartingData(
+ $params['requiredData'] ?? ''
+ ),
+ ]);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Status/Monitor/GeneralLogController.php b/libraries/classes/Controllers/Server/Status/Monitor/GeneralLogController.php
new file mode 100644
index 0000000000..4406e78dcd
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Status/Monitor/GeneralLogController.php
@@ -0,0 +1,65 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Url;
+
+final class GeneralLogController extends AbstractController
+{
+ /** @var Monitor */
+ private $monitor;
+
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param Data $data
+ * @param Monitor $monitor
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $data, $monitor, $dbi)
+ {
+ parent::__construct($response, $template, $data);
+ $this->monitor = $monitor;
+ $this->dbi = $dbi;
+ }
+
+ public function __invoke(): void
+ {
+ global $errorUrl;
+
+ $params = [
+ 'time_start' => $_POST['time_start'] ?? null,
+ 'time_end' => $_POST['time_end'] ?? null,
+ 'limitTypes' => $_POST['limitTypes'] ?? null,
+ 'removeVariables' => $_POST['removeVariables'] ?? null,
+ ];
+ $errorUrl = Url::getFromRoute('/');
+
+ if ($this->dbi->isSuperUser()) {
+ $this->dbi->selectDb('mysql');
+ }
+
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $this->response->addJSON([
+ 'message' => $this->monitor->getJsonForLogDataTypeGeneral(
+ (int) $params['time_start'],
+ (int) $params['time_end'],
+ (bool) $params['limitTypes'],
+ (bool) $params['removeVariables']
+ ),
+ ]);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Status/Monitor/LogVarsController.php b/libraries/classes/Controllers/Server/Status/Monitor/LogVarsController.php
new file mode 100644
index 0000000000..0e8dd1e6e2
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Status/Monitor/LogVarsController.php
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Url;
+
+final class LogVarsController extends AbstractController
+{
+ /** @var Monitor */
+ private $monitor;
+
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param Data $data
+ * @param Monitor $monitor
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $data, $monitor, $dbi)
+ {
+ parent::__construct($response, $template, $data);
+ $this->monitor = $monitor;
+ $this->dbi = $dbi;
+ }
+
+ public function __invoke(): void
+ {
+ global $errorUrl;
+
+ $params = [
+ 'varName' => $_POST['varName'] ?? null,
+ 'varValue' => $_POST['varValue'] ?? null,
+ ];
+ $errorUrl = Url::getFromRoute('/');
+
+ if ($this->dbi->isSuperUser()) {
+ $this->dbi->selectDb('mysql');
+ }
+
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $this->response->addJSON([
+ 'message' => $this->monitor->getJsonForLoggingVars(
+ $params['varName'],
+ $params['varValue']
+ ),
+ ]);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Status/Monitor/QueryAnalyzerController.php b/libraries/classes/Controllers/Server/Status/Monitor/QueryAnalyzerController.php
new file mode 100644
index 0000000000..dec930a15d
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Status/Monitor/QueryAnalyzerController.php
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Url;
+
+final class QueryAnalyzerController extends AbstractController
+{
+ /** @var Monitor */
+ private $monitor;
+
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param Data $data
+ * @param Monitor $monitor
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $data, $monitor, $dbi)
+ {
+ parent::__construct($response, $template, $data);
+ $this->monitor = $monitor;
+ $this->dbi = $dbi;
+ }
+
+ public function __invoke(): void
+ {
+ global $errorUrl;
+
+ $params = [
+ 'database' => $_POST['database'] ?? null,
+ 'query' => $_POST['query'] ?? null,
+ ];
+ $errorUrl = Url::getFromRoute('/');
+
+ if ($this->dbi->isSuperUser()) {
+ $this->dbi->selectDb('mysql');
+ }
+
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $this->response->addJSON([
+ 'message' => $this->monitor->getJsonForQueryAnalyzer(
+ $params['database'] ?? '',
+ $params['query'] ?? ''
+ ),
+ ]);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Status/Monitor/SlowLogController.php b/libraries/classes/Controllers/Server/Status/Monitor/SlowLogController.php
new file mode 100644
index 0000000000..37906eadfa
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Status/Monitor/SlowLogController.php
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Url;
+
+final class SlowLogController extends AbstractController
+{
+ /** @var Monitor */
+ private $monitor;
+
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param Data $data
+ * @param Monitor $monitor
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $data, $monitor, $dbi)
+ {
+ parent::__construct($response, $template, $data);
+ $this->monitor = $monitor;
+ $this->dbi = $dbi;
+ }
+
+ public function __invoke(): void
+ {
+ global $errorUrl;
+
+ $params = [
+ 'time_start' => $_POST['time_start'] ?? null,
+ 'time_end' => $_POST['time_end'] ?? null,
+ ];
+ $errorUrl = Url::getFromRoute('/');
+
+ if ($this->dbi->isSuperUser()) {
+ $this->dbi->selectDb('mysql');
+ }
+
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $this->response->addJSON([
+ 'message' => $this->monitor->getJsonForLogDataTypeSlow(
+ (int) $params['time_start'],
+ (int) $params['time_end']
+ ),
+ ]);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Status/MonitorController.php b/libraries/classes/Controllers/Server/Status/MonitorController.php
index a3ad391127..940e02b54b 100644
--- a/libraries/classes/Controllers/Server/Status/MonitorController.php
+++ b/libraries/classes/Controllers/Server/Status/MonitorController.php
@@ -7,7 +7,6 @@ namespace PhpMyAdmin\Controllers\Server\Status;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Server\Status\Data;
-use PhpMyAdmin\Server\Status\Monitor;
use PhpMyAdmin\Server\SysInfo\SysInfo;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
@@ -17,26 +16,21 @@ use function microtime;
class MonitorController extends AbstractController
{
- /** @var Monitor */
- private $monitor;
-
/** @var DatabaseInterface */
private $dbi;
/**
* @param ResponseRenderer $response
* @param Data $data
- * @param Monitor $monitor
* @param DatabaseInterface $dbi
*/
- public function __construct($response, Template $template, $data, $monitor, $dbi)
+ public function __construct($response, Template $template, $data, $dbi)
{
parent::__construct($response, $template, $data);
- $this->monitor = $monitor;
$this->dbi = $dbi;
}
- public function index(): void
+ public function __invoke(): void
{
global $errorUrl;
@@ -83,134 +77,4 @@ class MonitorController extends AbstractController
'form' => $form,
]);
}
-
- public function chartingData(): void
- {
- global $errorUrl;
-
- $params = ['requiredData' => $_POST['requiredData'] ?? null];
- $errorUrl = Url::getFromRoute('/');
-
- if ($this->dbi->isSuperUser()) {
- $this->dbi->selectDb('mysql');
- }
-
- if (! $this->response->isAjax()) {
- return;
- }
-
- $this->response->addJSON([
- 'message' => $this->monitor->getJsonForChartingData(
- $params['requiredData'] ?? ''
- ),
- ]);
- }
-
- public function logDataTypeSlow(): void
- {
- global $errorUrl;
-
- $params = [
- 'time_start' => $_POST['time_start'] ?? null,
- 'time_end' => $_POST['time_end'] ?? null,
- ];
- $errorUrl = Url::getFromRoute('/');
-
- if ($this->dbi->isSuperUser()) {
- $this->dbi->selectDb('mysql');
- }
-
- if (! $this->response->isAjax()) {
- return;
- }
-
- $this->response->addJSON([
- 'message' => $this->monitor->getJsonForLogDataTypeSlow(
- (int) $params['time_start'],
- (int) $params['time_end']
- ),
- ]);
- }
-
- public function logDataTypeGeneral(): void
- {
- global $errorUrl;
-
- $params = [
- 'time_start' => $_POST['time_start'] ?? null,
- 'time_end' => $_POST['time_end'] ?? null,
- 'limitTypes' => $_POST['limitTypes'] ?? null,
- 'removeVariables' => $_POST['removeVariables'] ?? null,
- ];
- $errorUrl = Url::getFromRoute('/');
-
- if ($this->dbi->isSuperUser()) {
- $this->dbi->selectDb('mysql');
- }
-
- if (! $this->response->isAjax()) {
- return;
- }
-
- $this->response->addJSON([
- 'message' => $this->monitor->getJsonForLogDataTypeGeneral(
- (int) $params['time_start'],
- (int) $params['time_end'],
- (bool) $params['limitTypes'],
- (bool) $params['removeVariables']
- ),
- ]);
- }
-
- public function loggingVars(): void
- {
- global $errorUrl;
-
- $params = [
- 'varName' => $_POST['varName'] ?? null,
- 'varValue' => $_POST['varValue'] ?? null,
- ];
- $errorUrl = Url::getFromRoute('/');
-
- if ($this->dbi->isSuperUser()) {
- $this->dbi->selectDb('mysql');
- }
-
- if (! $this->response->isAjax()) {
- return;
- }
-
- $this->response->addJSON([
- 'message' => $this->monitor->getJsonForLoggingVars(
- $params['varName'],
- $params['varValue']
- ),
- ]);
- }
-
- public function queryAnalyzer(): void
- {
- global $errorUrl;
-
- $params = [
- 'database' => $_POST['database'] ?? null,
- 'query' => $_POST['query'] ?? null,
- ];
- $errorUrl = Url::getFromRoute('/');
-
- if ($this->dbi->isSuperUser()) {
- $this->dbi->selectDb('mysql');
- }
-
- if (! $this->response->isAjax()) {
- return;
- }
-
- $this->response->addJSON([
- 'message' => $this->monitor->getJsonForQueryAnalyzer(
- $params['database'] ?? '',
- $params['query'] ?? ''
- ),
- ]);
- }
}
diff --git a/libraries/classes/Controllers/Server/Status/Processes/KillController.php b/libraries/classes/Controllers/Server/Status/Processes/KillController.php
new file mode 100644
index 0000000000..36eacfc4a0
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Status/Processes/KillController.php
@@ -0,0 +1,64 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Status\Processes;
+
+use PhpMyAdmin\Controllers\Server\Status\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Message;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Template;
+
+use function __;
+
+final class KillController extends AbstractController
+{
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param Data $data
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $data, $dbi)
+ {
+ parent::__construct($response, $template, $data);
+ $this->dbi = $dbi;
+ }
+
+ /**
+ * @param array $params Request parameters
+ */
+ public function __invoke(ServerRequest $request, array $params): void
+ {
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $kill = (int) $params['id'];
+ $query = $this->dbi->getKillQuery($kill);
+
+ if ($this->dbi->tryQuery($query)) {
+ $message = Message::success(
+ __('Thread %s was successfully killed.')
+ );
+ $this->response->setRequestStatus(true);
+ } else {
+ $message = Message::error(
+ __(
+ 'phpMyAdmin was unable to kill thread %s.'
+ . ' It probably has already been closed.'
+ )
+ );
+ $this->response->setRequestStatus(false);
+ }
+
+ $message->addParam($kill);
+
+ $this->response->addJSON(['message' => $message]);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Status/Processes/RefreshController.php b/libraries/classes/Controllers/Server/Status/Processes/RefreshController.php
new file mode 100644
index 0000000000..d42198b19e
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Status/Processes/RefreshController.php
@@ -0,0 +1,44 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Status\Processes;
+
+use PhpMyAdmin\Controllers\Server\Status\AbstractController;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Processes;
+use PhpMyAdmin\Template;
+
+final class RefreshController extends AbstractController
+{
+ /** @var Processes */
+ private $processes;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param Data $data
+ */
+ public function __construct($response, Template $template, $data, Processes $processes)
+ {
+ parent::__construct($response, $template, $data);
+ $this->processes = $processes;
+ }
+
+ public function __invoke(): void
+ {
+ $params = [
+ 'showExecuting' => $_POST['showExecuting'] ?? null,
+ 'full' => $_POST['full'] ?? null,
+ 'column_name' => $_POST['column_name'] ?? null,
+ 'order_by_field' => $_POST['order_by_field'] ?? null,
+ 'sort_order' => $_POST['sort_order'] ?? null,
+ ];
+
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $this->render('server/status/processes/list', $this->processes->getList($params));
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Status/ProcessesController.php b/libraries/classes/Controllers/Server/Status/ProcessesController.php
index 00e1fb1a60..0f6ee43ff3 100644
--- a/libraries/classes/Controllers/Server/Status/ProcessesController.php
+++ b/libraries/classes/Controllers/Server/Status/ProcessesController.php
@@ -5,16 +5,12 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Server\Status;
use PhpMyAdmin\DatabaseInterface;
-use PhpMyAdmin\Http\ServerRequest;
-use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Server\Status\Processes;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
-use function __;
-
class ProcessesController extends AbstractController
{
/** @var DatabaseInterface */
@@ -35,7 +31,7 @@ class ProcessesController extends AbstractController
$this->processes = $processes;
}
- public function index(): void
+ public function __invoke(): void
{
global $errorUrl;
@@ -75,56 +71,4 @@ class ProcessesController extends AbstractController
'server_process_list' => $listHtml,
]);
}
-
- /**
- * Only sends the process list table
- */
- public function refresh(): void
- {
- $params = [
- 'showExecuting' => $_POST['showExecuting'] ?? null,
- 'full' => $_POST['full'] ?? null,
- 'column_name' => $_POST['column_name'] ?? null,
- 'order_by_field' => $_POST['order_by_field'] ?? null,
- 'sort_order' => $_POST['sort_order'] ?? null,
- ];
-
- if (! $this->response->isAjax()) {
- return;
- }
-
- $this->render('server/status/processes/list', $this->processes->getList($params));
- }
-
- /**
- * @param array $params Request parameters
- */
- public function kill(ServerRequest $request, array $params): void
- {
- if (! $this->response->isAjax()) {
- return;
- }
-
- $kill = (int) $params['id'];
- $query = $this->dbi->getKillQuery($kill);
-
- if ($this->dbi->tryQuery($query)) {
- $message = Message::success(
- __('Thread %s was successfully killed.')
- );
- $this->response->setRequestStatus(true);
- } else {
- $message = Message::error(
- __(
- 'phpMyAdmin was unable to kill thread %s.'
- . ' It probably has already been closed.'
- )
- );
- $this->response->setRequestStatus(false);
- }
-
- $message->addParam($kill);
-
- $this->response->addJSON(['message' => $message]);
- }
}
diff --git a/libraries/classes/Controllers/Server/UserGroupsController.php b/libraries/classes/Controllers/Server/UserGroupsController.php
index da345690d0..0db59b9538 100644
--- a/libraries/classes/Controllers/Server/UserGroupsController.php
+++ b/libraries/classes/Controllers/Server/UserGroupsController.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Server;
-use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Message;
@@ -12,11 +11,8 @@ use PhpMyAdmin\Relation;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Server\UserGroups;
use PhpMyAdmin\Template;
-use PhpMyAdmin\Util;
use function __;
-use function sprintf;
-use function strlen;
/**
* Displays the 'User groups' sub page under 'Users' page.
@@ -40,7 +36,7 @@ class UserGroupsController extends AbstractController
$this->dbi = $dbi;
}
- public function index(): void
+ public function __invoke(): void
{
$cfgRelation = $this->relation->getRelationsParam();
if (! $cfgRelation['menuswork']) {
@@ -105,71 +101,4 @@ class UserGroupsController extends AbstractController
$this->response->addHTML('</div>');
}
-
- public function editUserGroupModalForm(): void
- {
- $this->response->setAjax(true);
-
- if (! isset($_GET['username']) || strlen((string) $_GET['username']) === 0) {
- $this->response->setRequestStatus(false);
- $this->response->setHttpResponseCode(400);
- $this->response->addJSON('message', __('Missing parameter:') . ' username');
-
- return;
- }
-
- $username = $_GET['username'];
-
- $checkUserPrivileges = new CheckUserPrivileges($this->dbi);
- $checkUserPrivileges->getPrivileges();
-
- $cfgRelation = $this->relation->getRelationsParam();
-
- if (! $cfgRelation['menuswork']) {
- $this->response->setRequestStatus(false);
- $this->response->setHttpResponseCode(400);
- $this->response->addJSON('message', __('User groups management is not enabled.'));
-
- return;
- }
-
- $form = $this->getHtmlToChooseUserGroup($username, $cfgRelation);
-
- $this->response->addJSON('message', $form);
- }
-
- /**
- * Displays a dropdown to select the user group with menu items configured to each of them.
- *
- * @param array<string, mixed> $cfgRelation
- */
- private function getHtmlToChooseUserGroup(string $username, array $cfgRelation): string
- {
- $groupTable = Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['usergroups']);
- $userTable = Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['users']);
-
- $sqlQuery = sprintf(
- 'SELECT `usergroup` FROM %s WHERE `username` = \'%s\'',
- $userTable,
- $this->dbi->escapeString($username)
- );
- $userGroup = $this->dbi->fetchValue($sqlQuery, 0, 0, DatabaseInterface::CONNECT_CONTROL);
-
- $allUserGroups = [];
- $sqlQuery = 'SELECT DISTINCT `usergroup` FROM ' . $groupTable;
- $result = $this->relation->queryAsControlUser($sqlQuery, false);
- if ($result) {
- while ($row = $this->dbi->fetchRow($result)) {
- $allUserGroups[$row[0]] = $row[0];
- }
- }
-
- $this->dbi->freeResult($result);
-
- return $this->template->render('server/privileges/choose_user_group', [
- 'all_user_groups' => $allUserGroups,
- 'user_group' => $userGroup,
- 'params' => ['username' => $username],
- ]);
- }
}
diff --git a/libraries/classes/Controllers/Server/UserGroupsFormController.php b/libraries/classes/Controllers/Server/UserGroupsFormController.php
new file mode 100644
index 0000000000..216fa4eddd
--- /dev/null
+++ b/libraries/classes/Controllers/Server/UserGroupsFormController.php
@@ -0,0 +1,104 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server;
+
+use PhpMyAdmin\CheckUserPrivileges;
+use PhpMyAdmin\Controllers\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Relation;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Util;
+
+use function __;
+use function sprintf;
+use function strlen;
+
+final class UserGroupsFormController extends AbstractController
+{
+ /** @var Relation */
+ private $relation;
+
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, Relation $relation, $dbi)
+ {
+ parent::__construct($response, $template);
+ $this->relation = $relation;
+ $this->dbi = $dbi;
+ }
+
+ public function __invoke(): void
+ {
+ $this->response->setAjax(true);
+
+ if (! isset($_GET['username']) || strlen((string) $_GET['username']) === 0) {
+ $this->response->setRequestStatus(false);
+ $this->response->setHttpResponseCode(400);
+ $this->response->addJSON('message', __('Missing parameter:') . ' username');
+
+ return;
+ }
+
+ $username = $_GET['username'];
+
+ $checkUserPrivileges = new CheckUserPrivileges($this->dbi);
+ $checkUserPrivileges->getPrivileges();
+
+ $cfgRelation = $this->relation->getRelationsParam();
+
+ if (! $cfgRelation['menuswork']) {
+ $this->response->setRequestStatus(false);
+ $this->response->setHttpResponseCode(400);
+ $this->response->addJSON('message', __('User groups management is not enabled.'));
+
+ return;
+ }
+
+ $form = $this->getHtmlToChooseUserGroup($username, $cfgRelation);
+
+ $this->response->addJSON('message', $form);
+ }
+
+ /**
+ * Displays a dropdown to select the user group with menu items configured to each of them.
+ *
+ * @param array<string, mixed> $cfgRelation
+ */
+ private function getHtmlToChooseUserGroup(string $username, array $cfgRelation): string
+ {
+ $groupTable = Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['usergroups']);
+ $userTable = Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation['users']);
+
+ $sqlQuery = sprintf(
+ 'SELECT `usergroup` FROM %s WHERE `username` = \'%s\'',
+ $userTable,
+ $this->dbi->escapeString($username)
+ );
+ $userGroup = $this->dbi->fetchValue($sqlQuery, 0, 0, DatabaseInterface::CONNECT_CONTROL);
+
+ $allUserGroups = [];
+ $sqlQuery = 'SELECT DISTINCT `usergroup` FROM ' . $groupTable;
+ $result = $this->relation->queryAsControlUser($sqlQuery, false);
+ if ($result) {
+ while ($row = $this->dbi->fetchRow($result)) {
+ $allUserGroups[$row[0]] = $row[0];
+ }
+ }
+
+ $this->dbi->freeResult($result);
+
+ return $this->template->render('server/privileges/choose_user_group', [
+ 'all_user_groups' => $allUserGroups,
+ 'user_group' => $userGroup,
+ 'params' => ['username' => $username],
+ ]);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Variables/GetVariableController.php b/libraries/classes/Controllers/Server/Variables/GetVariableController.php
new file mode 100644
index 0000000000..afdfc013b3
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Variables/GetVariableController.php
@@ -0,0 +1,66 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Variables;
+
+use PhpMyAdmin\Controllers\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Providers\ServerVariables\ServerVariablesProvider;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Util;
+
+use function header;
+use function implode;
+
+final class GetVariableController extends AbstractController
+{
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $dbi)
+ {
+ parent::__construct($response, $template);
+ $this->dbi = $dbi;
+ }
+
+ /**
+ * @param array $params Request parameters
+ */
+ public function __invoke(ServerRequest $request, array $params): void
+ {
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ // Send with correct charset
+ header('Content-Type: text/html; charset=UTF-8');
+ // Do not use double quotes inside the query to avoid a problem
+ // when server is running in ANSI_QUOTES sql_mode
+ $varValue = $this->dbi->fetchSingleRow(
+ 'SHOW GLOBAL VARIABLES WHERE Variable_name=\''
+ . $this->dbi->escapeString($params['name']) . '\';',
+ 'NUM'
+ );
+
+ $json = [
+ 'message' => $varValue[1],
+ ];
+
+ $variableType = ServerVariablesProvider::getImplementation()->getVariableType($params['name']);
+
+ if ($variableType === 'byte') {
+ /** @var string[] $bytes */
+ $bytes = Util::formatByteDown($varValue[1], 3, 3);
+ $json['message'] = implode(' ', $bytes);
+ }
+
+ $this->response->addJSON($json);
+ }
+}
diff --git a/libraries/classes/Controllers/Server/Variables/SetVariableController.php b/libraries/classes/Controllers/Server/Variables/SetVariableController.php
new file mode 100644
index 0000000000..3945a6920d
--- /dev/null
+++ b/libraries/classes/Controllers/Server/Variables/SetVariableController.php
@@ -0,0 +1,153 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Server\Variables;
+
+use PhpMyAdmin\Controllers\AbstractController;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Providers\ServerVariables\ServerVariablesProvider;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Util;
+
+use function __;
+use function htmlspecialchars;
+use function implode;
+use function is_numeric;
+use function mb_strtolower;
+use function pow;
+use function preg_match;
+use function trim;
+
+final class SetVariableController extends AbstractController
+{
+ /** @var DatabaseInterface */
+ private $dbi;
+
+ /**
+ * @param ResponseRenderer $response
+ * @param DatabaseInterface $dbi
+ */
+ public function __construct($response, Template $template, $dbi)
+ {
+ parent::__construct($response, $template);
+ $this->dbi = $dbi;
+ }
+
+ /**
+ * Handle the AJAX request for setting value for a single variable
+ *
+ * @param array $vars Request parameters
+ */
+ public function __invoke(ServerRequest $request, array $vars): void
+ {
+ if (! $this->response->isAjax()) {
+ return;
+ }
+
+ $value = (string) $request->getParsedBodyParam('varValue');
+ $variableName = (string) $vars['name'];
+ $matches = [];
+ $variableType = ServerVariablesProvider::getImplementation()->getVariableType($variableName);
+
+ if (
+ $variableType === 'byte' && preg_match(
+ '/^\s*(\d+(\.\d+)?)\s*(mb|kb|mib|kib|gb|gib)\s*$/i',
+ $value,
+ $matches
+ )
+ ) {
+ $exp = [
+ 'kb' => 1,
+ 'kib' => 1,
+ 'mb' => 2,
+ 'mib' => 2,
+ 'gb' => 3,
+ 'gib' => 3,
+ ];
+ $value = (float) $matches[1] * pow(
+ 1024,
+ $exp[mb_strtolower($matches[3])]
+ );
+ } else {
+ $value = $this->dbi->escapeString($value);
+ }
+
+ if (! is_numeric($value)) {
+ $value = "'" . $value . "'";
+ }
+
+ $json = [];
+ if (
+ ! preg_match('/[^a-zA-Z0-9_]+/', $variableName)
+ && $this->dbi->query(
+ 'SET GLOBAL ' . $variableName . ' = ' . $value
+ )
+ ) {
+ // Some values are rounded down etc.
+ $varValue = $this->dbi->fetchSingleRow(
+ 'SHOW GLOBAL VARIABLES WHERE Variable_name="'
+ . $this->dbi->escapeString($variableName)
+ . '";',
+ 'NUM'
+ );
+ [$formattedValue, $isHtmlFormatted] = $this->formatVariable(
+ $variableName,
+ $varValue[1]
+ );
+
+ if ($isHtmlFormatted === false) {
+ $json['variable'] = htmlspecialchars($formattedValue);
+ } else {
+ $json['variable'] = $formattedValue;
+ }
+ } else {
+ $this->response->setRequestStatus(false);
+ $json['error'] = __('Setting variable failed');
+ }
+
+ $this->response->addJSON($json);
+ }
+
+ /**
+ * Format Variable
+ *
+ * @param string $name variable name
+ * @param int|string $value variable value
+ *
+ * @return array formatted string and bool if string is HTML formatted
+ */
+ private function formatVariable($name, $value): array
+ {
+ $isHtmlFormatted = false;
+ $formattedValue = $value;
+
+ if (is_numeric($value)) {
+ $variableType = ServerVariablesProvider::getImplementation()->getVariableType($name);
+
+ if ($variableType === 'byte') {
+ $isHtmlFormatted = true;
+ /** @var string[] $bytes */
+ $bytes = Util::formatByteDown($value, 3, 3);
+ $formattedValue = trim(
+ $this->template->render(
+ 'server/variables/format_variable',
+ [
+ 'valueTitle' => Util::formatNumber($value, 0),
+ 'value' => implode(' ', $bytes),
+ ]
+ )
+ );
+ } else {
+ $formattedValue = Util::formatNumber($value, 0);
+ }
+ }
+
+ return [
+ $formattedValue,
+ $isHtmlFormatted,
+ ];
+ }
+}
diff --git a/libraries/classes/Controllers/Server/VariablesController.php b/libraries/classes/Controllers/Server/VariablesController.php
index b54e7095b3..f0d584b6ad 100644
--- a/libraries/classes/Controllers/Server/VariablesController.php
+++ b/libraries/classes/Controllers/Server/VariablesController.php
@@ -7,22 +7,15 @@ namespace PhpMyAdmin\Controllers\Server;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
-use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Providers\ServerVariables\ServerVariablesProvider;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
-use function __;
-use function header;
-use function htmlspecialchars;
use function implode;
use function in_array;
use function is_numeric;
-use function mb_strtolower;
-use function pow;
-use function preg_match;
use function str_replace;
use function strtolower;
use function trim;
@@ -45,7 +38,7 @@ class VariablesController extends AbstractController
$this->dbi = $dbi;
}
- public function index(): void
+ public function __invoke(): void
{
global $errorUrl;
@@ -113,117 +106,6 @@ class VariablesController extends AbstractController
}
/**
- * Handle the AJAX request for a single variable value
- *
- * @param array $params Request parameters
- */
- public function getValue(ServerRequest $request, array $params): void
- {
- if (! $this->response->isAjax()) {
- return;
- }
-
- // Send with correct charset
- header('Content-Type: text/html; charset=UTF-8');
- // Do not use double quotes inside the query to avoid a problem
- // when server is running in ANSI_QUOTES sql_mode
- $varValue = $this->dbi->fetchSingleRow(
- 'SHOW GLOBAL VARIABLES WHERE Variable_name=\''
- . $this->dbi->escapeString($params['name']) . '\';',
- 'NUM'
- );
-
- $json = [
- 'message' => $varValue[1],
- ];
-
- $variableType = ServerVariablesProvider::getImplementation()->getVariableType($params['name']);
-
- if ($variableType === 'byte') {
- /** @var string[] $bytes */
- $bytes = Util::formatByteDown($varValue[1], 3, 3);
- $json['message'] = implode(' ', $bytes);
- }
-
- $this->response->addJSON($json);
- }
-
- /**
- * Handle the AJAX request for setting value for a single variable
- *
- * @param array $vars Request parameters
- */
- public function setValue(ServerRequest $request, array $vars): void
- {
- if (! $this->response->isAjax()) {
- return;
- }
-
- $value = (string) $request->getParsedBodyParam('varValue');
- $variableName = (string) $vars['name'];
- $matches = [];
- $variableType = ServerVariablesProvider::getImplementation()->getVariableType($variableName);
-
- if (
- $variableType === 'byte' && preg_match(
- '/^\s*(\d+(\.\d+)?)\s*(mb|kb|mib|kib|gb|gib)\s*$/i',
- $value,
- $matches
- )
- ) {
- $exp = [
- 'kb' => 1,
- 'kib' => 1,
- 'mb' => 2,
- 'mib' => 2,
- 'gb' => 3,
- 'gib' => 3,
- ];
- $value = (float) $matches[1] * pow(
- 1024,
- $exp[mb_strtolower($matches[3])]
- );
- } else {
- $value = $this->dbi->escapeString($value);
- }
-
- if (! is_numeric($value)) {
- $value = "'" . $value . "'";
- }
-
- $json = [];
- if (
- ! preg_match('/[^a-zA-Z0-9_]+/', $variableName)
- && $this->dbi->query(
- 'SET GLOBAL ' . $variableName . ' = ' . $value
- )
- ) {
- // Some values are rounded down etc.
- $varValue = $this->dbi->fetchSingleRow(
- 'SHOW GLOBAL VARIABLES WHERE Variable_name="'
- . $this->dbi->escapeString($variableName)
- . '";',
- 'NUM'
- );
- [$formattedValue, $isHtmlFormatted] = $this->formatVariable(
- $variableName,
- $varValue[1]
- );
-
- if ($isHtmlFormatted === false) {
- $json['variable'] = htmlspecialchars($formattedValue);
- } else {
- $json['variable'] = $formattedValue;
- }
- } else {
- $this->response->setRequestStatus(false);
- $json['error'] = __('Setting variable failed');
- }
-
- $this->response->addJSON($json);
- }
-
- /**
* Format Variable
*
* @param string $name variable name
diff --git a/libraries/classes/Controllers/ThemeSetController.php b/libraries/classes/Controllers/ThemeSetController.php
new file mode 100644
index 0000000000..6615971ff2
--- /dev/null
+++ b/libraries/classes/Controllers/ThemeSetController.php
@@ -0,0 +1,47 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers;
+
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\ThemeManager;
+use PhpMyAdmin\Url;
+use PhpMyAdmin\UserPreferences;
+
+final class ThemeSetController extends AbstractController
+{
+ /** @var ThemeManager */
+ private $themeManager;
+
+ /**
+ * @param ResponseRenderer $response
+ */
+ public function __construct($response, Template $template, ThemeManager $themeManager)
+ {
+ parent::__construct($response, $template);
+ $this->themeManager = $themeManager;
+ }
+
+ public function __invoke(): void
+ {
+ global $cfg;
+
+ if (! $cfg['ThemeManager'] || ! isset($_POST['set_theme'])) {
+ $this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
+
+ return;
+ }
+
+ $this->themeManager->setActiveTheme($_POST['set_theme']);
+ $this->themeManager->setThemeCookie();
+
+ $userPreferences = new UserPreferences();
+ $preferences = $userPreferences->load();
+ $preferences['config_data']['ThemeDefault'] = $_POST['set_theme'];
+ $userPreferences->save($preferences['config_data']);
+
+ $this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
+ }
+}
diff --git a/libraries/classes/Controllers/ThemesController.php b/libraries/classes/Controllers/ThemesController.php
index cd768d85ef..1b6b92a2dc 100644
--- a/libraries/classes/Controllers/ThemesController.php
+++ b/libraries/classes/Controllers/ThemesController.php
@@ -7,8 +7,6 @@ namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\ThemeManager;
-use PhpMyAdmin\Url;
-use PhpMyAdmin\UserPreferences;
class ThemesController extends AbstractController
{
@@ -24,32 +22,11 @@ class ThemesController extends AbstractController
$this->themeManager = $themeManager;
}
- public function index(): void
+ public function __invoke(): void
{
$themes = $this->themeManager->getThemesArray();
$themesList = $this->template->render('home/themes', ['themes' => $themes]);
$this->response->setAjax(true);
$this->response->addJSON('themes', $themesList);
}
-
- public function setTheme(): void
- {
- global $cfg;
-
- if (! $cfg['ThemeManager'] || ! isset($_POST['set_theme'])) {
- $this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
-
- return;
- }
-
- $this->themeManager->setActiveTheme($_POST['set_theme']);
- $this->themeManager->setThemeCookie();
-
- $userPreferences = new UserPreferences();
- $preferences = $userPreferences->load();
- $preferences['config_data']['ThemeDefault'] = $_POST['set_theme'];
- $userPreferences->save($preferences['config_data']);
-
- $this->response->header('Location: index.php?route=/' . Url::getCommonRaw([], '&'));
- }
}
diff --git a/libraries/routes.php b/libraries/routes.php
index 895b3bf86e..331b76769c 100644
--- a/libraries/routes.php
+++ b/libraries/routes.php
@@ -32,6 +32,7 @@ use PhpMyAdmin\Controllers\SqlController;
use PhpMyAdmin\Controllers\Table;
use PhpMyAdmin\Controllers\TableController;
use PhpMyAdmin\Controllers\ThemesController;
+use PhpMyAdmin\Controllers\ThemeSetController;
use PhpMyAdmin\Controllers\Transformation;
use PhpMyAdmin\Controllers\UserPasswordController;
use PhpMyAdmin\Controllers\VersionCheckController;
@@ -165,29 +166,29 @@ return static function (RouteCollector $routes): void {
$routes->get('', Server\Status\StatusController::class);
$routes->get('/advisor', Server\Status\AdvisorController::class);
$routes->addGroup('/monitor', static function (RouteCollector $routes): void {
- $routes->get('', [Server\Status\MonitorController::class, 'index']);
- $routes->post('/chart', [Server\Status\MonitorController::class, 'chartingData']);
- $routes->post('/slow-log', [Server\Status\MonitorController::class, 'logDataTypeSlow']);
- $routes->post('/general-log', [Server\Status\MonitorController::class, 'logDataTypeGeneral']);
- $routes->post('/log-vars', [Server\Status\MonitorController::class, 'loggingVars']);
- $routes->post('/query', [Server\Status\MonitorController::class, 'queryAnalyzer']);
+ $routes->get('', Server\Status\MonitorController::class);
+ $routes->post('/chart', Server\Status\Monitor\ChartingDataController::class);
+ $routes->post('/slow-log', Server\Status\Monitor\SlowLogController::class);
+ $routes->post('/general-log', Server\Status\Monitor\GeneralLogController::class);
+ $routes->post('/log-vars', Server\Status\Monitor\LogVarsController::class);
+ $routes->post('/query', Server\Status\Monitor\QueryAnalyzerController::class);
});
$routes->addGroup('/processes', static function (RouteCollector $routes): void {
- $routes->addRoute(['GET', 'POST'], '', [Server\Status\ProcessesController::class, 'index']);
- $routes->post('/refresh', [Server\Status\ProcessesController::class, 'refresh']);
- $routes->post('/kill/{id:\d+}', [Server\Status\ProcessesController::class, 'kill']);
+ $routes->addRoute(['GET', 'POST'], '', Server\Status\ProcessesController::class);
+ $routes->post('/refresh', Server\Status\Processes\RefreshController::class);
+ $routes->post('/kill/{id:\d+}', Server\Status\Processes\KillController::class);
});
$routes->get('/queries', Server\Status\QueriesController::class);
$routes->addRoute(['GET', 'POST'], '/variables', Server\Status\VariablesController::class);
});
$routes->addGroup('/user-groups', static function (RouteCollector $routes): void {
- $routes->addRoute(['GET', 'POST'], '', [Server\UserGroupsController::class, 'index']);
- $routes->get('/edit-form', [Server\UserGroupsController::class, 'editUserGroupModalForm']);
+ $routes->addRoute(['GET', 'POST'], '', Server\UserGroupsController::class);
+ $routes->get('/edit-form', Server\UserGroupsFormController::class);
});
$routes->addGroup('/variables', static function (RouteCollector $routes): void {
- $routes->get('', [Server\VariablesController::class, 'index']);
- $routes->get('/get/{name}', [Server\VariablesController::class, 'getValue']);
- $routes->post('/set/{name}', [Server\VariablesController::class, 'setValue']);
+ $routes->get('', Server\VariablesController::class);
+ $routes->get('/get/{name}', Server\Variables\GetVariableController::class);
+ $routes->post('/set/{name}', Server\Variables\SetVariableController::class);
});
});
$routes->addGroup('/sql', static function (RouteCollector $routes): void {
@@ -267,8 +268,8 @@ return static function (RouteCollector $routes): void {
});
$routes->post('/tables', TableController::class);
$routes->addGroup('/themes', static function (RouteCollector $routes): void {
- $routes->get('', [ThemesController::class, 'index']);
- $routes->post('/set', [ThemesController::class, 'setTheme']);
+ $routes->get('', ThemesController::class);
+ $routes->post('/set', ThemeSetController::class);
});
$routes->addGroup('/transformation', static function (RouteCollector $routes): void {
$routes->addRoute(['GET', 'POST'], '/overview', Transformation\OverviewController::class);
diff --git a/libraries/services_controllers.php b/libraries/services_controllers.php
index 4b6bfee1e8..a77639250b 100644
--- a/libraries/services_controllers.php
+++ b/libraries/services_controllers.php
@@ -32,6 +32,7 @@ use PhpMyAdmin\Controllers\SqlController;
use PhpMyAdmin\Controllers\Table;
use PhpMyAdmin\Controllers\TableController;
use PhpMyAdmin\Controllers\ThemesController;
+use PhpMyAdmin\Controllers\ThemeSetController;
use PhpMyAdmin\Controllers\Transformation;
use PhpMyAdmin\Controllers\UserPasswordController;
use PhpMyAdmin\Controllers\VersionCheckController;
@@ -859,6 +860,15 @@ return [
'$dbi' => '@dbi',
],
],
+ Server\UserGroupsFormController::class => [
+ 'class' => Server\UserGroupsFormController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$relation' => '@relation',
+ '$dbi' => '@dbi',
+ ],
+ ],
Server\Status\AdvisorController::class => [
'class' => Server\Status\AdvisorController::class,
'arguments' => [
@@ -868,6 +878,56 @@ return [
'$advisor' => '@advisor',
],
],
+ Server\Status\Monitor\ChartingDataController::class => [
+ 'class' => Server\Status\Monitor\ChartingDataController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$data' => '@status_data',
+ '$monitor' => '@status_monitor',
+ '$dbi' => '@dbi',
+ ],
+ ],
+ Server\Status\Monitor\GeneralLogController::class => [
+ 'class' => Server\Status\Monitor\GeneralLogController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$data' => '@status_data',
+ '$monitor' => '@status_monitor',
+ '$dbi' => '@dbi',
+ ],
+ ],
+ Server\Status\Monitor\LogVarsController::class => [
+ 'class' => Server\Status\Monitor\LogVarsController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$data' => '@status_data',
+ '$monitor' => '@status_monitor',
+ '$dbi' => '@dbi',
+ ],
+ ],
+ Server\Status\Monitor\QueryAnalyzerController::class => [
+ 'class' => Server\Status\Monitor\QueryAnalyzerController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$data' => '@status_data',
+ '$monitor' => '@status_monitor',
+ '$dbi' => '@dbi',
+ ],
+ ],
+ Server\Status\Monitor\SlowLogController::class => [
+ 'class' => Server\Status\Monitor\SlowLogController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$data' => '@status_data',
+ '$monitor' => '@status_monitor',
+ '$dbi' => '@dbi',
+ ],
+ ],
Server\Status\MonitorController::class => [
'class' => Server\Status\MonitorController::class,
'arguments' => [
@@ -878,6 +938,24 @@ return [
'$dbi' => '@dbi',
],
],
+ Server\Status\Processes\KillController::class => [
+ 'class' => Server\Status\Processes\KillController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$data' => '@status_data',
+ '$dbi' => '@dbi',
+ ],
+ ],
+ Server\Status\Processes\RefreshController::class => [
+ 'class' => Server\Status\Processes\RefreshController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$data' => '@status_data',
+ '$processes' => '@status_processes',
+ ],
+ ],
Server\Status\ProcessesController::class => [
'class' => Server\Status\ProcessesController::class,
'arguments' => [
@@ -916,6 +994,22 @@ return [
'$dbi' => '@dbi',
],
],
+ Server\Variables\GetVariableController::class => [
+ 'class' => Server\Variables\GetVariableController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$dbi' => '@dbi',
+ ],
+ ],
+ Server\Variables\SetVariableController::class => [
+ 'class' => Server\Variables\SetVariableController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$dbi' => '@dbi',
+ ],
+ ],
Server\VariablesController::class => [
'class' => Server\VariablesController::class,
'arguments' => [
@@ -1388,6 +1482,14 @@ return [
'$themeManager' => '@theme_manager',
],
],
+ ThemeSetController::class => [
+ 'class' => ThemeSetController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$themeManager' => '@theme_manager',
+ ],
+ ],
Transformation\OverviewController::class => [
'class' => Transformation\OverviewController::class,
'arguments' => [
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 4631822c98..c966ba0234 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -142,8 +142,13 @@ parameters:
-
message: "#^Offset 1 does not exist on array\\|null\\.$#"
- count: 3
- path: libraries/classes/Controllers/Server/VariablesController.php
+ count: 2
+ path: libraries/classes/Controllers/Server/Variables/GetVariableController.php
+
+ -
+ message: "#^Offset 1 does not exist on array\\|null\\.$#"
+ count: 1
+ path: libraries/classes/Controllers/Server/Variables/SetVariableController.php
-
message: "#^Parameter \\#1 \\$server of method PhpMyAdmin\\\\Config\\\\ConfigFile\\:\\:getServerDSN\\(\\) expects int, int\\|null given\\.$#"
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 5dc7408881..651d24f9eb 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -2776,15 +2776,23 @@
<code>$replicaInfo['status']</code>
</MixedArgument>
</file>
- <file src="libraries/classes/Controllers/Server/Status/MonitorController.php">
- <MixedArgument occurrences="5">
- <code>$params['database'] ?? ''</code>
- <code>$params['query'] ?? ''</code>
+ <file src="libraries/classes/Controllers/Server/Status/Monitor/ChartingDataController.php">
+ <MixedArgument occurrences="1">
<code>$params['requiredData'] ?? ''</code>
+ </MixedArgument>
+ </file>
+ <file src="libraries/classes/Controllers/Server/Status/Monitor/LogVarsController.php">
+ <MixedArgument occurrences="2">
<code>$params['varName']</code>
<code>$params['varValue']</code>
</MixedArgument>
</file>
+ <file src="libraries/classes/Controllers/Server/Status/Monitor/QueryAnalyzerController.php">
+ <MixedArgument occurrences="2">
+ <code>$params['database'] ?? ''</code>
+ <code>$params['query'] ?? ''</code>
+ </MixedArgument>
+ </file>
<file src="libraries/classes/Controllers/Server/Status/QueriesController.php">
<MixedArgumentTypeCoercion occurrences="1">
<code>$key</code>
@@ -2877,12 +2885,16 @@
</UnusedVariable>
</file>
<file src="libraries/classes/Controllers/Server/UserGroupsController.php">
- <MixedArgument occurrences="12">
+ <MixedArgument occurrences="5">
<code>$_POST['userGroup']</code>
<code>$_POST['userGroup']</code>
<code>$_POST['userGroup']</code>
<code>$_POST['userGroup']</code>
<code>$_POST['userGroup']</code>
+ </MixedArgument>
+ </file>
+ <file src="libraries/classes/Controllers/Server/UserGroupsFormController.php">
+ <MixedArgument occurrences="7">
<code>$cfgRelation['db']</code>
<code>$cfgRelation['db']</code>
<code>$cfgRelation['usergroups']</code>
@@ -2910,17 +2922,37 @@
<code>Util::backquote($cfgRelation['users'])</code>
</MixedOperand>
</file>
- <file src="libraries/classes/Controllers/Server/VariablesController.php">
- <MixedArgument occurrences="9">
- <code>$formattedValue</code>
+ <file src="libraries/classes/Controllers/Server/Variables/GetVariableController.php">
+ <MixedArgument occurrences="3">
<code>$params['name']</code>
<code>$params['name']</code>
+ <code>$varValue[1]</code>
+ </MixedArgument>
+ <PossiblyNullArrayAccess occurrences="1">
+ <code>$varValue[1]</code>
+ </PossiblyNullArrayAccess>
+ </file>
+ <file src="libraries/classes/Controllers/Server/Variables/SetVariableController.php">
+ <MixedArgument occurrences="2">
+ <code>$formattedValue</code>
+ <code>$varValue[1]</code>
+ </MixedArgument>
+ <MixedAssignment occurrences="1">
+ <code>$json['variable']</code>
+ </MixedAssignment>
+ <PossiblyNullArgument occurrences="1">
+ <code>$varValue[1]</code>
+ </PossiblyNullArgument>
+ <PossiblyNullArrayAccess occurrences="1">
+ <code>$varValue[1]</code>
+ </PossiblyNullArrayAccess>
+ </file>
+ <file src="libraries/classes/Controllers/Server/VariablesController.php">
+ <MixedArgument occurrences="4">
<code>$serverVarsResult</code>
<code>$serverVarsResult</code>
<code>$serverVarsSession[$name]</code>
<code>$value</code>
- <code>$varValue[1]</code>
- <code>$varValue[1]</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="5">
<code>$name</code>
@@ -2932,20 +2964,12 @@
<MixedArrayOffset occurrences="1">
<code>$serverVarsSession[$arr[0]]</code>
</MixedArrayOffset>
- <MixedAssignment occurrences="5">
+ <MixedAssignment occurrences="4">
<code>$filterValue</code>
- <code>$json['variable']</code>
<code>$serverVarsResult</code>
<code>$serverVarsSession[$arr[0]]</code>
<code>$value</code>
</MixedAssignment>
- <PossiblyNullArgument occurrences="1">
- <code>$varValue[1]</code>
- </PossiblyNullArgument>
- <PossiblyNullArrayAccess occurrences="2">
- <code>$varValue[1]</code>
- <code>$varValue[1]</code>
- </PossiblyNullArrayAccess>
</file>
<file src="libraries/classes/Controllers/Setup/FormController.php">
<UndefinedClass occurrences="1">
@@ -4426,7 +4450,7 @@
<code>$_POST['db']</code>
</MixedArgument>
</file>
- <file src="libraries/classes/Controllers/ThemesController.php">
+ <file src="libraries/classes/Controllers/ThemeSetController.php">
<MixedArgument occurrences="2">
<code>$_POST['set_theme']</code>
<code>$preferences['config_data']</code>
@@ -17571,16 +17595,24 @@
<code>$actual['message']</code>
</MixedArgument>
</file>
- <file src="test/classes/Controllers/Server/Status/MonitorControllerTest.php">
- <MixedArrayAccess occurrences="9">
+ <file src="test/classes/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php">
+ <MixedArrayAccess occurrences="3">
+ <code>$ret['message']['numRows']</code>
+ <code>$ret['message']['rows']</code>
+ <code>$ret['message']['sum']</code>
+ </MixedArrayAccess>
+ </file>
+ <file src="test/classes/Controllers/Server/Status/Monitor/QueryAnalyzerControllerTest.php">
+ <MixedArrayAccess occurrences="3">
<code>$ret['message']['affectedRows']</code>
<code>$ret['message']['explain']</code>
- <code>$ret['message']['numRows']</code>
- <code>$ret['message']['numRows']</code>
<code>$ret['message']['profiling']</code>
+ </MixedArrayAccess>
+ </file>
+ <file src="test/classes/Controllers/Server/Status/Monitor/SlowLogControllerTest.php">
+ <MixedArrayAccess occurrences="3">
+ <code>$ret['message']['numRows']</code>
<code>$ret['message']['rows']</code>
- <code>$ret['message']['rows']</code>
- <code>$ret['message']['sum']</code>
<code>$ret['message']['sum']</code>
</MixedArrayAccess>
</file>
diff --git a/test/classes/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php b/test/classes/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php
new file mode 100644
index 0000000000..fbee18ab7b
--- /dev/null
+++ b/test/classes/Controllers/Server/Status/Monitor/GeneralLogControllerTest.php
@@ -0,0 +1,96 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\Monitor\GeneralLogController;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Server\Status\Monitor\GeneralLogController
+ */
+class GeneralLogControllerTest extends AbstractTestCase
+{
+ /** @var Data */
+ private $data;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $GLOBALS['text_dir'] = 'ltr';
+ parent::setGlobalConfig();
+ parent::setTheme();
+
+ $GLOBALS['server'] = 1;
+ $GLOBALS['db'] = 'db';
+ $GLOBALS['table'] = 'table';
+ $GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['cfg']['Server']['host'] = 'localhost';
+
+ $this->data = new Data();
+ }
+
+ public function testGeneralLog(): void
+ {
+ $value = [
+ 'sql_text' => 'insert sql_text',
+ '#' => 10,
+ 'argument' => 'argument argument2',
+ ];
+
+ $value2 = [
+ 'sql_text' => 'update sql_text',
+ '#' => 11,
+ 'argument' => 'argument3 argument4',
+ ];
+
+ $response = new ResponseRenderer();
+ $response->setAjax(true);
+
+ $controller = new GeneralLogController(
+ $response,
+ new Template(),
+ $this->data,
+ new Monitor($GLOBALS['dbi']),
+ $GLOBALS['dbi']
+ );
+
+ $_POST['time_start'] = '0';
+ $_POST['time_end'] = '10';
+ $_POST['limitTypes'] = '1';
+
+ $this->dummyDbi->addSelectDb('mysql');
+ $controller();
+ $this->assertAllSelectsConsumed();
+ $ret = $response->getJSONResult();
+
+ $resultRows = [
+ $value,
+ $value2,
+ ];
+ $resultSum = [
+ 'argument' => 10,
+ 'TOTAL' => 21,
+ 'argument3' => 11,
+ ];
+
+ $this->assertEquals(
+ 2,
+ $ret['message']['numRows']
+ );
+ $this->assertEquals(
+ $resultRows,
+ $ret['message']['rows']
+ );
+ $this->assertEquals(
+ $resultSum,
+ $ret['message']['sum']
+ );
+ }
+}
diff --git a/test/classes/Controllers/Server/Status/Monitor/LogVarsControllerTest.php b/test/classes/Controllers/Server/Status/Monitor/LogVarsControllerTest.php
new file mode 100644
index 0000000000..9373ef9b85
--- /dev/null
+++ b/test/classes/Controllers/Server/Status/Monitor/LogVarsControllerTest.php
@@ -0,0 +1,71 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\Monitor\LogVarsController;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Server\Status\Monitor\LogVarsController
+ */
+class LogVarsControllerTest extends AbstractTestCase
+{
+ /** @var Data */
+ private $data;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $GLOBALS['text_dir'] = 'ltr';
+ parent::setGlobalConfig();
+ parent::setTheme();
+
+ $GLOBALS['server'] = 1;
+ $GLOBALS['db'] = 'db';
+ $GLOBALS['table'] = 'table';
+ $GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['cfg']['Server']['host'] = 'localhost';
+
+ $this->data = new Data();
+ }
+
+ public function testLogVars(): void
+ {
+ $value = [
+ 'general_log' => 'OFF',
+ 'log_output' => 'FILE',
+ 'long_query_time' => '10.000000',
+ 'slow_query_log' => 'OFF',
+ ];
+
+ $response = new ResponseRenderer();
+ $response->setAjax(true);
+
+ $controller = new LogVarsController(
+ $response,
+ new Template(),
+ $this->data,
+ new Monitor($GLOBALS['dbi']),
+ $GLOBALS['dbi']
+ );
+
+ $_POST['varName'] = 'varName';
+
+ $this->dummyDbi->addSelectDb('mysql');
+ $controller();
+ $this->assertAllSelectsConsumed();
+ $ret = $response->getJSONResult();
+
+ $this->assertEquals(
+ $value,
+ $ret['message']
+ );
+ }
+}
diff --git a/test/classes/Controllers/Server/Status/Monitor/QueryAnalyzerControllerTest.php b/test/classes/Controllers/Server/Status/Monitor/QueryAnalyzerControllerTest.php
new file mode 100644
index 0000000000..92359ebad6
--- /dev/null
+++ b/test/classes/Controllers/Server/Status/Monitor/QueryAnalyzerControllerTest.php
@@ -0,0 +1,86 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\Monitor\QueryAnalyzerController;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+use PhpMyAdmin\Utils\SessionCache;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Server\Status\Monitor\QueryAnalyzerController
+ */
+class QueryAnalyzerControllerTest extends AbstractTestCase
+{
+ /** @var Data */
+ private $data;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $GLOBALS['text_dir'] = 'ltr';
+ parent::setGlobalConfig();
+ parent::setTheme();
+
+ $GLOBALS['server'] = 1;
+ $GLOBALS['db'] = 'db';
+ $GLOBALS['table'] = 'table';
+ $GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['cfg']['Server']['host'] = 'localhost';
+
+ $this->data = new Data();
+ }
+
+ public function testQueryAnalyzer(): void
+ {
+ global $cached_affected_rows;
+
+ $cached_affected_rows = 'cached_affected_rows';
+ SessionCache::set('profiling_supported', true);
+
+ $value = [
+ 'sql_text' => 'insert sql_text',
+ '#' => 10,
+ 'argument' => 'argument argument2',
+ ];
+
+ $response = new ResponseRenderer();
+ $response->setAjax(true);
+
+ $controller = new QueryAnalyzerController(
+ $response,
+ new Template(),
+ $this->data,
+ new Monitor($GLOBALS['dbi']),
+ $GLOBALS['dbi']
+ );
+
+ $_POST['database'] = 'database';
+ $_POST['query'] = 'query';
+
+ $this->dummyDbi->addSelectDb('mysql');
+ $this->dummyDbi->addSelectDb('database');
+ $controller();
+ $this->assertAllSelectsConsumed();
+ $ret = $response->getJSONResult();
+
+ $this->assertEquals(
+ 'cached_affected_rows',
+ $ret['message']['affectedRows']
+ );
+ $this->assertEquals(
+ [],
+ $ret['message']['profiling']
+ );
+ $this->assertEquals(
+ [$value],
+ $ret['message']['explain']
+ );
+ }
+}
diff --git a/test/classes/Controllers/Server/Status/Monitor/SlowLogControllerTest.php b/test/classes/Controllers/Server/Status/Monitor/SlowLogControllerTest.php
new file mode 100644
index 0000000000..f30ac69a44
--- /dev/null
+++ b/test/classes/Controllers/Server/Status/Monitor/SlowLogControllerTest.php
@@ -0,0 +1,88 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Server\Status\Monitor;
+
+use PhpMyAdmin\Controllers\Server\Status\Monitor\SlowLogController;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Monitor;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Server\Status\Monitor\SlowLogController
+ */
+class SlowLogControllerTest extends AbstractTestCase
+{
+ /** @var Data */
+ private $data;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $GLOBALS['text_dir'] = 'ltr';
+ parent::setGlobalConfig();
+ parent::setTheme();
+
+ $GLOBALS['server'] = 1;
+ $GLOBALS['db'] = 'db';
+ $GLOBALS['table'] = 'table';
+ $GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['cfg']['Server']['host'] = 'localhost';
+
+ $this->data = new Data();
+ }
+
+ public function testSlowLog(): void
+ {
+ $response = new ResponseRenderer();
+ $response->setAjax(true);
+
+ $controller = new SlowLogController(
+ $response,
+ new Template(),
+ $this->data,
+ new Monitor($GLOBALS['dbi']),
+ $GLOBALS['dbi']
+ );
+
+ $_POST['time_start'] = '0';
+ $_POST['time_end'] = '10';
+
+ $this->dummyDbi->addSelectDb('mysql');
+ $controller();
+ $this->assertAllSelectsConsumed();
+ $ret = $response->getJSONResult();
+
+ $resultRows = [
+ [
+ 'sql_text' => 'insert sql_text',
+ '#' => 11,
+ ],
+ [
+ 'sql_text' => 'update sql_text',
+ '#' => 10,
+ ],
+ ];
+ $resultSum = [
+ 'insert' => 11,
+ 'TOTAL' => 21,
+ 'update' => 10,
+ ];
+ $this->assertEquals(
+ 2,
+ $ret['message']['numRows']
+ );
+ $this->assertEquals(
+ $resultRows,
+ $ret['message']['rows']
+ );
+ $this->assertEquals(
+ $resultSum,
+ $ret['message']['sum']
+ );
+ }
+}
diff --git a/test/classes/Controllers/Server/Status/MonitorControllerTest.php b/test/classes/Controllers/Server/Status/MonitorControllerTest.php
index 3087a7ce1e..3b40b3852b 100644
--- a/test/classes/Controllers/Server/Status/MonitorControllerTest.php
+++ b/test/classes/Controllers/Server/Status/MonitorControllerTest.php
@@ -6,11 +6,9 @@ namespace PhpMyAdmin\Tests\Controllers\Server\Status;
use PhpMyAdmin\Controllers\Server\Status\MonitorController;
use PhpMyAdmin\Server\Status\Data;
-use PhpMyAdmin\Server\Status\Monitor;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
-use PhpMyAdmin\Utils\SessionCache;
use function __;
@@ -47,12 +45,11 @@ class MonitorControllerTest extends AbstractTestCase
$response,
new Template(),
$this->data,
- new Monitor($GLOBALS['dbi']),
$GLOBALS['dbi']
);
$this->dummyDbi->addSelectDb('mysql');
- $controller->index();
+ $controller();
$this->assertAllSelectsConsumed();
$html = $response->getHTMLResult();
@@ -138,192 +135,4 @@ class MonitorControllerTest extends AbstractTestCase
$html
);
}
-
- public function testLogDataTypeSlow(): void
- {
- $response = new ResponseRenderer();
- $response->setAjax(true);
-
- $controller = new MonitorController(
- $response,
- new Template(),
- $this->data,
- new Monitor($GLOBALS['dbi']),
- $GLOBALS['dbi']
- );
-
- $_POST['time_start'] = '0';
- $_POST['time_end'] = '10';
-
- $this->dummyDbi->addSelectDb('mysql');
- $controller->logDataTypeSlow();
- $this->assertAllSelectsConsumed();
- $ret = $response->getJSONResult();
-
- $resultRows = [
- [
- 'sql_text' => 'insert sql_text',
- '#' => 11,
- ],
- [
- 'sql_text' => 'update sql_text',
- '#' => 10,
- ],
- ];
- $resultSum = [
- 'insert' => 11,
- 'TOTAL' => 21,
- 'update' => 10,
- ];
- $this->assertEquals(
- 2,
- $ret['message']['numRows']
- );
- $this->assertEquals(
- $resultRows,
- $ret['message']['rows']
- );
- $this->assertEquals(
- $resultSum,
- $ret['message']['sum']
- );
- }
-
- public function testLogDataTypeGeneral(): void
- {
- $value = [
- 'sql_text' => 'insert sql_text',
- '#' => 10,
- 'argument' => 'argument argument2',
- ];
-
- $value2 = [
- 'sql_text' => 'update sql_text',
- '#' => 11,
- 'argument' => 'argument3 argument4',
- ];
-
- $response = new ResponseRenderer();
- $response->setAjax(true);
-
- $controller = new MonitorController(
- $response,
- new Template(),
- $this->data,
- new Monitor($GLOBALS['dbi']),
- $GLOBALS['dbi']
- );
-
- $_POST['time_start'] = '0';
- $_POST['time_end'] = '10';
- $_POST['limitTypes'] = '1';
-
- $this->dummyDbi->addSelectDb('mysql');
- $controller->logDataTypeGeneral();
- $this->assertAllSelectsConsumed();
- $ret = $response->getJSONResult();
-
- $resultRows = [
- $value,
- $value2,
- ];
- $resultSum = [
- 'argument' => 10,
- 'TOTAL' => 21,
- 'argument3' => 11,
- ];
-
- $this->assertEquals(
- 2,
- $ret['message']['numRows']
- );
- $this->assertEquals(
- $resultRows,
- $ret['message']['rows']
- );
- $this->assertEquals(
- $resultSum,
- $ret['message']['sum']
- );
- }
-
- public function testLoggingVars(): void
- {
- $value = [
- 'general_log' => 'OFF',
- 'log_output' => 'FILE',
- 'long_query_time' => '10.000000',
- 'slow_query_log' => 'OFF',
- ];
-
- $response = new ResponseRenderer();
- $response->setAjax(true);
-
- $controller = new MonitorController(
- $response,
- new Template(),
- $this->data,
- new Monitor($GLOBALS['dbi']),
- $GLOBALS['dbi']
- );
-
- $_POST['varName'] = 'varName';
-
- $this->dummyDbi->addSelectDb('mysql');
- $controller->loggingVars();
- $this->assertAllSelectsConsumed();
- $ret = $response->getJSONResult();
-
- $this->assertEquals(
- $value,
- $ret['message']
- );
- }
-
- public function testQueryAnalyzer(): void
- {
- global $cached_affected_rows;
-
- $cached_affected_rows = 'cached_affected_rows';
- SessionCache::set('profiling_supported', true);
-
- $value = [
- 'sql_text' => 'insert sql_text',
- '#' => 10,
- 'argument' => 'argument argument2',
- ];
-
- $response = new ResponseRenderer();
- $response->setAjax(true);
-
- $controller = new MonitorController(
- $response,
- new Template(),
- $this->data,
- new Monitor($GLOBALS['dbi']),
- $GLOBALS['dbi']
- );
-
- $_POST['database'] = 'database';
- $_POST['query'] = 'query';
-
- $this->dummyDbi->addSelectDb('mysql');
- $this->dummyDbi->addSelectDb('database');
- $controller->queryAnalyzer();
- $this->assertAllSelectsConsumed();
- $ret = $response->getJSONResult();
-
- $this->assertEquals(
- 'cached_affected_rows',
- $ret['message']['affectedRows']
- );
- $this->assertEquals(
- [],
- $ret['message']['profiling']
- );
- $this->assertEquals(
- [$value],
- $ret['message']['explain']
- );
- }
}
diff --git a/test/classes/Controllers/Server/Status/Processes/RefreshControllerTest.php b/test/classes/Controllers/Server/Status/Processes/RefreshControllerTest.php
new file mode 100644
index 0000000000..92e9e7f8a6
--- /dev/null
+++ b/test/classes/Controllers/Server/Status/Processes/RefreshControllerTest.php
@@ -0,0 +1,135 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Server\Status\Processes;
+
+use PhpMyAdmin\Controllers\Server\Status\Processes\RefreshController;
+use PhpMyAdmin\Server\Status\Data;
+use PhpMyAdmin\Server\Status\Processes;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+use PhpMyAdmin\Url;
+
+use function __;
+use function htmlspecialchars;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Server\Status\Processes\RefreshController
+ */
+class RefreshControllerTest extends AbstractTestCase
+{
+ /** @var Data */
+ private $data;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $GLOBALS['text_dir'] = 'ltr';
+ parent::setGlobalConfig();
+ parent::setTheme();
+
+ $GLOBALS['server'] = 1;
+ $GLOBALS['db'] = 'db';
+ $GLOBALS['table'] = 'table';
+ $GLOBALS['PMA_PHP_SELF'] = 'index.php';
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['cfg']['Server']['host'] = 'localhost';
+
+ $this->data = new Data();
+ }
+
+ public function testRefresh(): void
+ {
+ $process = [
+ 'User' => 'User1',
+ 'Host' => 'Host1',
+ 'Id' => 'Id1',
+ 'db' => 'db1',
+ 'Command' => 'Command1',
+ 'Info' => 'Info1',
+ 'State' => 'State1',
+ 'Time' => 'Time1',
+ ];
+ $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 12;
+
+ $response = new ResponseRenderer();
+ $response->setAjax(true);
+
+ $controller = new RefreshController(
+ $response,
+ new Template(),
+ $this->data,
+ new Processes($GLOBALS['dbi'])
+ );
+
+ $_POST['full'] = '1';
+ $_POST['order_by_field'] = 'process';
+ $_POST['sort_order'] = 'DESC';
+
+ $controller();
+ $html = $response->getHTMLResult();
+
+ $this->assertStringContainsString(
+ 'index.php?route=/server/status/processes',
+ $html
+ );
+ $killProcess = 'data-post="'
+ . Url::getCommon(['kill' => $process['Id']], '') . '"';
+ $this->assertStringContainsString(
+ $killProcess,
+ $html
+ );
+ $this->assertStringContainsString(
+ 'ajax kill_process',
+ $html
+ );
+ $this->assertStringContainsString(
+ __('Kill'),
+ $html
+ );
+
+ //validate 2: $process['User']
+ $this->assertStringContainsString(
+ htmlspecialchars($process['User']),
+ $html
+ );
+
+ //validate 3: $process['Host']
+ $this->assertStringContainsString(
+ htmlspecialchars($process['Host']),
+ $html
+ );
+
+ //validate 4: $process['db']
+ $this->assertStringContainsString(
+ __('None'),
+ $html
+ );
+
+ //validate 5: $process['Command']
+ $this->assertStringContainsString(
+ htmlspecialchars($process['Command']),
+ $html
+ );
+
+ //validate 6: $process['Time']
+ $this->assertStringContainsString(
+ $process['Time'],
+ $html
+ );
+
+ //validate 7: $process['state']
+ $this->assertStringContainsString(
+ $process['State'],
+ $html
+ );
+
+ //validate 8: $process['info']
+ $this->assertStringContainsString(
+ $process['Info'],
+ $html
+ );
+ }
+}
diff --git a/test/classes/Controllers/Server/Status/ProcessesControllerTest.php b/test/classes/Controllers/Server/Status/ProcessesControllerTest.php
index af8585c206..3f6f8ea74e 100644
--- a/test/classes/Controllers/Server/Status/ProcessesControllerTest.php
+++ b/test/classes/Controllers/Server/Status/ProcessesControllerTest.php
@@ -10,10 +10,6 @@ use PhpMyAdmin\Server\Status\Processes;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
-use PhpMyAdmin\Url;
-
-use function __;
-use function htmlspecialchars;
/**
* @covers \PhpMyAdmin\Controllers\Server\Status\ProcessesController
@@ -53,7 +49,7 @@ class ProcessesControllerTest extends AbstractTestCase
);
$this->dummyDbi->addSelectDb('mysql');
- $controller->index();
+ $controller();
$this->assertAllSelectsConsumed();
$html = $response->getHTMLResult();
@@ -115,7 +111,7 @@ class ProcessesControllerTest extends AbstractTestCase
$_POST['sort_order'] = 'ASC';
$this->dummyDbi->addSelectDb('mysql');
- $controller->index();
+ $controller();
$this->assertAllSelectsConsumed();
$html = $response->getHTMLResult();
@@ -137,7 +133,7 @@ class ProcessesControllerTest extends AbstractTestCase
$_POST['sort_order'] = 'DESC';
$this->dummyDbi->addSelectDb('mysql');
- $controller->index();
+ $controller();
$this->assertAllSelectsConsumed();
$html = $response->getHTMLResult();
@@ -150,98 +146,4 @@ class ProcessesControllerTest extends AbstractTestCase
$html
);
}
-
- public function testRefresh(): void
- {
- $process = [
- 'User' => 'User1',
- 'Host' => 'Host1',
- 'Id' => 'Id1',
- 'db' => 'db1',
- 'Command' => 'Command1',
- 'Info' => 'Info1',
- 'State' => 'State1',
- 'Time' => 'Time1',
- ];
- $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 12;
-
- $response = new ResponseRenderer();
- $response->setAjax(true);
-
- $controller = new ProcessesController(
- $response,
- new Template(),
- $this->data,
- $GLOBALS['dbi'],
- new Processes($GLOBALS['dbi'])
- );
-
- $_POST['full'] = '1';
- $_POST['order_by_field'] = 'process';
- $_POST['sort_order'] = 'DESC';
-
- $controller->refresh();
- $html = $response->getHTMLResult();
-
- $this->assertStringContainsString(
- 'index.php?route=/server/status/processes',
- $html
- );
- $killProcess = 'data-post="'
- . Url::getCommon(['kill' => $process['Id']], '') . '"';
- $this->assertStringContainsString(
- $killProcess,
- $html
- );
- $this->assertStringContainsString(
- 'ajax kill_process',
- $html
- );
- $this->assertStringContainsString(
- __('Kill'),
- $html
- );
-
- //validate 2: $process['User']
- $this->assertStringContainsString(
- htmlspecialchars($process['User']),
- $html
- );
-
- //validate 3: $process['Host']
- $this->assertStringContainsString(
- htmlspecialchars($process['Host']),
- $html
- );
-
- //validate 4: $process['db']
- $this->assertStringContainsString(
- __('None'),
- $html
- );
-
- //validate 5: $process['Command']
- $this->assertStringContainsString(
- htmlspecialchars($process['Command']),
- $html
- );
-
- //validate 6: $process['Time']
- $this->assertStringContainsString(
- $process['Time'],
- $html
- );
-
- //validate 7: $process['state']
- $this->assertStringContainsString(
- $process['State'],
- $html
- );
-
- //validate 8: $process['info']
- $this->assertStringContainsString(
- $process['Info'],
- $html
- );
- }
}
diff --git a/test/classes/Controllers/Server/VariablesControllerTest.php b/test/classes/Controllers/Server/VariablesControllerTest.php
index 85fd2c9625..88f5206f46 100644
--- a/test/classes/Controllers/Server/VariablesControllerTest.php
+++ b/test/classes/Controllers/Server/VariablesControllerTest.php
@@ -87,7 +87,7 @@ class VariablesControllerTest extends AbstractTestCase
$controller = new VariablesController($response, new Template(), $GLOBALS['dbi']);
- $controller->index();
+ $controller();
$html = $response->getHTMLResult();
$this->assertStringContainsString(