diff options
32 files changed, 888 insertions, 500 deletions
diff --git a/composer.json b/composer.json index 4fa40f4f61..27b0ccdc37 100644 --- a/composer.json +++ b/composer.json @@ -101,7 +101,7 @@ "samyoul/u2f-php-server": "^1.1", "symfony/console": "^5.2.3", "tecnickcom/tcpdf": "^6.4.2", - "vimeo/psalm": "^4.9.2" + "vimeo/psalm": "^4.10.0" }, "extra": { "branch-alias": { diff --git a/libraries/classes/Controllers/Config/GetConfigController.php b/libraries/classes/Controllers/Config/GetConfigController.php new file mode 100644 index 0000000000..220fedfeb9 --- /dev/null +++ b/libraries/classes/Controllers/Config/GetConfigController.php @@ -0,0 +1,42 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Config; + +use PhpMyAdmin\Config; +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +final class GetConfigController extends AbstractController +{ + /** @var Config */ + private $config; + + /** + * @param ResponseRenderer $response + */ + public function __construct($response, Template $template, Config $config) + { + parent::__construct($response, $template); + $this->config = $config; + } + + public function __invoke(ServerRequest $request): void + { + /** @var string|null $key */ + $key = $request->getParsedBodyParam('key'); + + if (! isset($key)) { + $this->response->setRequestStatus(false); + $this->response->addJSON(['message' => Message::error()]); + + return; + } + + $this->response->addJSON(['value' => $this->config->get($key)]); + } +} diff --git a/libraries/classes/Controllers/ConfigController.php b/libraries/classes/Controllers/Config/SetConfigController.php index 63c8f3d7bd..f40486d493 100644 --- a/libraries/classes/Controllers/ConfigController.php +++ b/libraries/classes/Controllers/Config/SetConfigController.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace PhpMyAdmin\Controllers; +namespace PhpMyAdmin\Controllers\Config; use PhpMyAdmin\Config; +use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Message; use PhpMyAdmin\ResponseRenderer; @@ -12,7 +13,7 @@ use PhpMyAdmin\Template; use function json_decode; -final class ConfigController extends AbstractController +final class SetConfigController extends AbstractController { /** @var Config */ private $config; @@ -26,22 +27,7 @@ final class ConfigController extends AbstractController $this->config = $config; } - public function get(ServerRequest $request): void - { - /** @var string|null $key */ - $key = $request->getParsedBodyParam('key'); - - if (! isset($key)) { - $this->response->setRequestStatus(false); - $this->response->addJSON(['message' => Message::error()]); - - return; - } - - $this->response->addJSON(['value' => $this->config->get($key)]); - } - - public function set(ServerRequest $request): void + public function __invoke(ServerRequest $request): void { /** @var string|null $key */ $key = $request->getParsedBodyParam('key'); diff --git a/libraries/classes/Controllers/Database/CentralColumns/PopulateColumnsController.php b/libraries/classes/Controllers/Database/CentralColumns/PopulateColumnsController.php new file mode 100644 index 0000000000..6fce7d0c07 --- /dev/null +++ b/libraries/classes/Controllers/Database/CentralColumns/PopulateColumnsController.php @@ -0,0 +1,33 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Database\CentralColumns; + +use PhpMyAdmin\Controllers\Database\AbstractController; +use PhpMyAdmin\Database\CentralColumns; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +final class PopulateColumnsController extends AbstractController +{ + /** @var CentralColumns */ + private $centralColumns; + + /** + * @param ResponseRenderer $response + * @param string $db Database name + * @param CentralColumns $centralColumns + */ + public function __construct($response, Template $template, $db, $centralColumns) + { + parent::__construct($response, $template, $db); + $this->centralColumns = $centralColumns; + } + + public function __invoke(): void + { + $columns = $this->centralColumns->getColumnsNotInCentralList($this->db, $_POST['selectedTable']); + $this->render('database/central_columns/populate_columns', ['columns' => $columns]); + } +} diff --git a/libraries/classes/Controllers/Database/CentralColumnsController.php b/libraries/classes/Controllers/Database/CentralColumnsController.php index e3074ffdef..5b607a7e38 100644 --- a/libraries/classes/Controllers/Database/CentralColumnsController.php +++ b/libraries/classes/Controllers/Database/CentralColumnsController.php @@ -34,7 +34,7 @@ class CentralColumnsController extends AbstractController $this->centralColumns = $centralColumns; } - public function index(): void + public function __invoke(): void { global $cfg, $db, $message, $pos, $num_cols; @@ -192,12 +192,6 @@ class CentralColumnsController extends AbstractController ); } - public function populateColumns(): void - { - $columns = $this->centralColumns->getColumnsNotInCentralList($this->db, $_POST['selectedTable']); - $this->render('database/central_columns/populate_columns', ['columns' => $columns]); - } - /** * @param array $params Request parameters * diff --git a/libraries/classes/Controllers/Database/ExportController.php b/libraries/classes/Controllers/Database/ExportController.php index b3013bc3ad..f9f90e53b1 100644 --- a/libraries/classes/Controllers/Database/ExportController.php +++ b/libraries/classes/Controllers/Database/ExportController.php @@ -37,7 +37,7 @@ final class ExportController extends AbstractController $this->exportOptions = $exportOptions; } - public function index(): void + public function __invoke(): void { global $db, $table, $sub_part, $urlParams, $sql_query; global $tables, $num_tables, $total_num_tables, $tooltip_truename; @@ -174,16 +174,4 @@ final class ExportController extends AbstractController 'tables' => $tablesForMultiValues, ])); } - - public function tables(): void - { - if (empty($_POST['selected_tbl'])) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No table selected.')); - - return; - } - - $this->index(); - } } diff --git a/libraries/classes/Controllers/Database/MultiTableQuery/QueryController.php b/libraries/classes/Controllers/Database/MultiTableQuery/QueryController.php new file mode 100644 index 0000000000..45c311a33e --- /dev/null +++ b/libraries/classes/Controllers/Database/MultiTableQuery/QueryController.php @@ -0,0 +1,21 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Database\MultiTableQuery; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Database\MultiTableQuery; + +final class QueryController extends AbstractController +{ + public function __invoke(): void + { + $params = [ + 'sql_query' => $_POST['sql_query'], + 'db' => $_POST['db'] ?? $_GET['db'] ?? null, + ]; + + $this->response->addHTML(MultiTableQuery::displayResults($params['sql_query'], $params['db'])); + } +} diff --git a/libraries/classes/Controllers/Database/MultiTableQuery/TablesController.php b/libraries/classes/Controllers/Database/MultiTableQuery/TablesController.php new file mode 100644 index 0000000000..6508ffa0b6 --- /dev/null +++ b/libraries/classes/Controllers/Database/MultiTableQuery/TablesController.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Database\MultiTableQuery; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Query\Generator as QueryGenerator; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +use function rtrim; + +final class TablesController 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; + } + + public function __invoke(): void + { + $params = [ + 'tables' => $_GET['tables'] ?? [], + 'db' => $_GET['db'] ?? '', + ]; + + $tablesListForQuery = ''; + foreach ($params['tables'] as $table) { + $tablesListForQuery .= "'" . $this->dbi->escapeString($table) . "',"; + } + + $tablesListForQuery = rtrim($tablesListForQuery, ','); + + $constrains = $this->dbi->fetchResult( + QueryGenerator::getInformationSchemaForeignKeyConstraintsRequest( + $this->dbi->escapeString($params['db']), + $tablesListForQuery + ), + null, + null, + DatabaseInterface::CONNECT_USER, + DatabaseInterface::QUERY_STORE + ); + $this->response->addJSON(['foreignKeyConstrains' => $constrains]); + } +} diff --git a/libraries/classes/Controllers/Database/MultiTableQueryController.php b/libraries/classes/Controllers/Database/MultiTableQueryController.php index c537df2402..191479a10e 100644 --- a/libraries/classes/Controllers/Database/MultiTableQueryController.php +++ b/libraries/classes/Controllers/Database/MultiTableQueryController.php @@ -6,12 +6,9 @@ namespace PhpMyAdmin\Controllers\Database; use PhpMyAdmin\Database\MultiTableQuery; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Query\Generator as QueryGenerator; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; -use function rtrim; - /** * Handles database multi-table querying */ @@ -31,7 +28,7 @@ class MultiTableQueryController extends AbstractController $this->dbi = $dbi; } - public function index(): void + public function __invoke(): void { $this->addScriptFiles([ 'database/multi_table_query.js', @@ -42,44 +39,4 @@ class MultiTableQueryController extends AbstractController $this->response->addHTML($queryInstance->getFormHtml()); } - - public function displayResults(): void - { - $params = [ - 'sql_query' => $_POST['sql_query'], - 'db' => $_POST['db'] ?? $_GET['db'] ?? null, - ]; - - $this->response->addHTML(MultiTableQuery::displayResults( - $params['sql_query'], - $params['db'] - )); - } - - public function table(): void - { - $params = [ - 'tables' => $_GET['tables'] ?? [], - 'db' => $_GET['db'] ?? '', - ]; - - $tablesListForQuery = ''; - foreach ($params['tables'] as $table) { - $tablesListForQuery .= "'" . $this->dbi->escapeString($table) . "',"; - } - - $tablesListForQuery = rtrim($tablesListForQuery, ','); - - $constrains = $this->dbi->fetchResult( - QueryGenerator::getInformationSchemaForeignKeyConstraintsRequest( - $this->dbi->escapeString($params['db']), - $tablesListForQuery - ), - null, - null, - DatabaseInterface::CONNECT_USER, - DatabaseInterface::QUERY_STORE - ); - $this->response->addJSON(['foreignKeyConstrains' => $constrains]); - } } diff --git a/libraries/classes/Controllers/ExportController.php b/libraries/classes/Controllers/Export/ExportController.php index 25f2f1be62..2c514890e8 100644 --- a/libraries/classes/Controllers/ExportController.php +++ b/libraries/classes/Controllers/Export/ExportController.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace PhpMyAdmin\Controllers; +namespace PhpMyAdmin\Controllers\Export; +use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Controllers\Database\ExportController as DatabaseExportController; use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; @@ -468,7 +469,7 @@ final class ExportController extends AbstractController $active_page = Url::getFromRoute('/database/export'); /** @var DatabaseExportController $controller */ $controller = $containerBuilder->get(DatabaseExportController::class); - $controller->index(); + $controller(); exit; } } @@ -663,7 +664,7 @@ final class ExportController extends AbstractController throw new ExportException('Failure during footer export.'); } } catch (ExportException $e) { - null; // Avoid phpcs error... + // Ignore } if ($save_on_server && ! empty($message)) { diff --git a/libraries/classes/Controllers/Export/TablesController.php b/libraries/classes/Controllers/Export/TablesController.php new file mode 100644 index 0000000000..85a392962a --- /dev/null +++ b/libraries/classes/Controllers/Export/TablesController.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Export; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Controllers\Database\ExportController; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +use function __; + +final class TablesController extends AbstractController +{ + /** @var ExportController */ + private $exportController; + + /** + * @param ResponseRenderer $response + */ + public function __construct($response, Template $template, ExportController $exportController) + { + parent::__construct($response, $template); + $this->exportController = $exportController; + } + + public function __invoke(): void + { + if (empty($_POST['selected_tbl'])) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No table selected.')); + + return; + } + + ($this->exportController)(); + } +} diff --git a/libraries/classes/Controllers/Export/Template/CreateController.php b/libraries/classes/Controllers/Export/Template/CreateController.php new file mode 100644 index 0000000000..d55005eb90 --- /dev/null +++ b/libraries/classes/Controllers/Export/Template/CreateController.php @@ -0,0 +1,90 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Export\Template as ExportTemplate; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +use function is_array; +use function is_string; + +final class CreateController extends AbstractController +{ + /** @var TemplateModel */ + private $model; + + /** @var Relation */ + private $relation; + + /** + * @param ResponseRenderer $response + */ + public function __construct( + $response, + Template $template, + TemplateModel $model, + Relation $relation + ) { + parent::__construct($response, $template); + $this->model = $model; + $this->relation = $relation; + } + + public function __invoke(ServerRequest $request): void + { + global $cfg; + + /** @var string $exportType */ + $exportType = $request->getParsedBodyParam('exportType', ''); + /** @var string $templateName */ + $templateName = $request->getParsedBodyParam('templateName', ''); + /** @var string $templateData */ + $templateData = $request->getParsedBodyParam('templateData', ''); + /** @var string|null $templateId */ + $templateId = $request->getParsedBodyParam('template_id'); + + $cfgRelation = $this->relation->getRelationsParam(); + + if (! $cfgRelation['exporttemplateswork']) { + return; + } + + $template = ExportTemplate::fromArray([ + 'username' => $cfg['Server']['user'], + 'exportType' => $exportType, + 'name' => $templateName, + 'data' => $templateData, + ]); + $result = $this->model->create($cfgRelation['db'], $cfgRelation['export_templates'], $template); + + if (is_string($result)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', $result); + + return; + } + + $templates = $this->model->getAll( + $cfgRelation['db'], + $cfgRelation['export_templates'], + $template->getUsername(), + $template->getExportType() + ); + + $this->response->setRequestStatus(true); + $this->response->addJSON( + 'data', + $this->template->render('export/template_options', [ + 'templates' => is_array($templates) ? $templates : [], + 'selected_template' => $templateId, + ]) + ); + } +} diff --git a/libraries/classes/Controllers/Export/Template/DeleteController.php b/libraries/classes/Controllers/Export/Template/DeleteController.php new file mode 100644 index 0000000000..348430bd9f --- /dev/null +++ b/libraries/classes/Controllers/Export/Template/DeleteController.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +use function is_string; + +final class DeleteController extends AbstractController +{ + /** @var TemplateModel */ + private $model; + + /** @var Relation */ + private $relation; + + /** + * @param ResponseRenderer $response + */ + public function __construct( + $response, + Template $template, + TemplateModel $model, + Relation $relation + ) { + parent::__construct($response, $template); + $this->model = $model; + $this->relation = $relation; + } + + public function __invoke(ServerRequest $request): void + { + global $cfg; + + $templateId = (int) $request->getParsedBodyParam('templateId'); + $cfgRelation = $this->relation->getRelationsParam(); + + if (! $cfgRelation['exporttemplateswork']) { + return; + } + + $result = $this->model->delete( + $cfgRelation['db'], + $cfgRelation['export_templates'], + $cfg['Server']['user'], + $templateId + ); + + if (is_string($result)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', $result); + + return; + } + + $this->response->setRequestStatus(true); + } +} diff --git a/libraries/classes/Controllers/Export/Template/LoadController.php b/libraries/classes/Controllers/Export/Template/LoadController.php new file mode 100644 index 0000000000..3cf4bbdb2c --- /dev/null +++ b/libraries/classes/Controllers/Export/Template/LoadController.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Export\Template as ExportTemplate; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +final class LoadController extends AbstractController +{ + /** @var TemplateModel */ + private $model; + + /** @var Relation */ + private $relation; + + /** + * @param ResponseRenderer $response + */ + public function __construct( + $response, + Template $template, + TemplateModel $model, + Relation $relation + ) { + parent::__construct($response, $template); + $this->model = $model; + $this->relation = $relation; + } + + public function __invoke(ServerRequest $request): void + { + global $cfg; + + $templateId = (int) $request->getParsedBodyParam('templateId'); + $cfgRelation = $this->relation->getRelationsParam(); + + if (! $cfgRelation['exporttemplateswork']) { + return; + } + + $template = $this->model->load( + $cfgRelation['db'], + $cfgRelation['export_templates'], + $cfg['Server']['user'], + $templateId + ); + + if (! $template instanceof ExportTemplate) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', $template); + + return; + } + + $this->response->setRequestStatus(true); + $this->response->addJSON('data', $template->getData()); + } +} diff --git a/libraries/classes/Controllers/Export/Template/UpdateController.php b/libraries/classes/Controllers/Export/Template/UpdateController.php new file mode 100644 index 0000000000..3ac3c4d1c3 --- /dev/null +++ b/libraries/classes/Controllers/Export/Template/UpdateController.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\Export\Template as ExportTemplate; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +use function is_string; + +final class UpdateController extends AbstractController +{ + /** @var TemplateModel */ + private $model; + + /** @var Relation */ + private $relation; + + /** + * @param ResponseRenderer $response + */ + public function __construct( + $response, + Template $template, + TemplateModel $model, + Relation $relation + ) { + parent::__construct($response, $template); + $this->model = $model; + $this->relation = $relation; + } + + public function __invoke(ServerRequest $request): void + { + global $cfg; + + $templateId = (int) $request->getParsedBodyParam('templateId'); + /** @var string $templateData */ + $templateData = $request->getParsedBodyParam('templateData', ''); + $cfgRelation = $this->relation->getRelationsParam(); + + if (! $cfgRelation['exporttemplateswork']) { + return; + } + + $template = ExportTemplate::fromArray([ + 'id' => $templateId, + 'username' => $cfg['Server']['user'], + 'data' => $templateData, + ]); + $result = $this->model->update($cfgRelation['db'], $cfgRelation['export_templates'], $template); + + if (is_string($result)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', $result); + + return; + } + + $this->response->setRequestStatus(true); + } +} diff --git a/libraries/classes/Controllers/ExportTemplateController.php b/libraries/classes/Controllers/ExportTemplateController.php deleted file mode 100644 index 3764c0fd40..0000000000 --- a/libraries/classes/Controllers/ExportTemplateController.php +++ /dev/null @@ -1,176 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace PhpMyAdmin\Controllers; - -use PhpMyAdmin\Export\Template as ExportTemplate; -use PhpMyAdmin\Export\TemplateModel; -use PhpMyAdmin\Http\ServerRequest; -use PhpMyAdmin\Relation; -use PhpMyAdmin\ResponseRenderer; -use PhpMyAdmin\Template; - -use function is_array; -use function is_string; - -final class ExportTemplateController extends AbstractController -{ - /** @var TemplateModel */ - private $model; - - /** @var Relation */ - private $relation; - - /** - * @param ResponseRenderer $response - */ - public function __construct( - $response, - Template $template, - TemplateModel $model, - Relation $relation - ) { - parent::__construct($response, $template); - $this->model = $model; - $this->relation = $relation; - } - - public function create(ServerRequest $request): void - { - global $cfg; - - /** @var string $exportType */ - $exportType = $request->getParsedBodyParam('exportType', ''); - /** @var string $templateName */ - $templateName = $request->getParsedBodyParam('templateName', ''); - /** @var string $templateData */ - $templateData = $request->getParsedBodyParam('templateData', ''); - /** @var string|null $templateId */ - $templateId = $request->getParsedBodyParam('template_id'); - - $cfgRelation = $this->relation->getRelationsParam(); - - if (! $cfgRelation['exporttemplateswork']) { - return; - } - - $template = ExportTemplate::fromArray([ - 'username' => $cfg['Server']['user'], - 'exportType' => $exportType, - 'name' => $templateName, - 'data' => $templateData, - ]); - $result = $this->model->create($cfgRelation['db'], $cfgRelation['export_templates'], $template); - - if (is_string($result)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', $result); - - return; - } - - $templates = $this->model->getAll( - $cfgRelation['db'], - $cfgRelation['export_templates'], - $template->getUsername(), - $template->getExportType() - ); - - $this->response->setRequestStatus(true); - $this->response->addJSON( - 'data', - $this->template->render('export/template_options', [ - 'templates' => is_array($templates) ? $templates : [], - 'selected_template' => $templateId, - ]) - ); - } - - public function delete(ServerRequest $request): void - { - global $cfg; - - $templateId = (int) $request->getParsedBodyParam('templateId'); - $cfgRelation = $this->relation->getRelationsParam(); - - if (! $cfgRelation['exporttemplateswork']) { - return; - } - - $result = $this->model->delete( - $cfgRelation['db'], - $cfgRelation['export_templates'], - $cfg['Server']['user'], - $templateId - ); - - if (is_string($result)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', $result); - - return; - } - - $this->response->setRequestStatus(true); - } - - public function load(ServerRequest $request): void - { - global $cfg; - - $templateId = (int) $request->getParsedBodyParam('templateId'); - $cfgRelation = $this->relation->getRelationsParam(); - - if (! $cfgRelation['exporttemplateswork']) { - return; - } - - $template = $this->model->load( - $cfgRelation['db'], - $cfgRelation['export_templates'], - $cfg['Server']['user'], - $templateId - ); - - if (! $template instanceof ExportTemplate) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', $template); - - return; - } - - $this->response->setRequestStatus(true); - $this->response->addJSON('data', $template->getData()); - } - - public function update(ServerRequest $request): void - { - global $cfg; - - $templateId = (int) $request->getParsedBodyParam('templateId'); - /** @var string $templateData */ - $templateData = $request->getParsedBodyParam('templateData', ''); - $cfgRelation = $this->relation->getRelationsParam(); - - if (! $cfgRelation['exporttemplateswork']) { - return; - } - - $template = ExportTemplate::fromArray([ - 'id' => $templateId, - 'username' => $cfg['Server']['user'], - 'data' => $templateData, - ]); - $result = $this->model->update($cfgRelation['db'], $cfgRelation['export_templates'], $template); - - if (is_string($result)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', $result); - - return; - } - - $this->response->setRequestStatus(true); - } -} diff --git a/libraries/classes/Controllers/TransformationOverviewController.php b/libraries/classes/Controllers/Transformation/OverviewController.php index 01eace769d..f781db4774 100644 --- a/libraries/classes/Controllers/TransformationOverviewController.php +++ b/libraries/classes/Controllers/Transformation/OverviewController.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace PhpMyAdmin\Controllers; +namespace PhpMyAdmin\Controllers\Transformation; +use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; use PhpMyAdmin\Transformations; @@ -13,7 +14,7 @@ use function array_keys; /** * Lists available transformation plugins */ -class TransformationOverviewController extends AbstractController +class OverviewController extends AbstractController { /** @var Transformations */ private $transformations; diff --git a/libraries/classes/Controllers/TransformationWrapperController.php b/libraries/classes/Controllers/Transformation/WrapperController.php index eaa7b56cca..a5ec4c3ce8 100644 --- a/libraries/classes/Controllers/TransformationWrapperController.php +++ b/libraries/classes/Controllers/Transformation/WrapperController.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace PhpMyAdmin\Controllers; +namespace PhpMyAdmin\Controllers\Transformation; +use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\DbTableExists; @@ -27,7 +28,7 @@ use function substr; /** * Wrapper script for rendering transformations */ -class TransformationWrapperController extends AbstractController +class WrapperController extends AbstractController { /** @var Transformations */ private $transformations; diff --git a/libraries/classes/Controllers/ViewCreateController.php b/libraries/classes/Controllers/View/CreateController.php index a6b365b6fc..11f79ee8f7 100644 --- a/libraries/classes/Controllers/ViewCreateController.php +++ b/libraries/classes/Controllers/View/CreateController.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace PhpMyAdmin\Controllers; +namespace PhpMyAdmin\Controllers\View; +use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Controllers\Table\StructureController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; @@ -30,7 +31,7 @@ use function substr; /** * Handles creation of VIEWs. */ -class ViewCreateController extends AbstractController +class CreateController extends AbstractController { /** @var DatabaseInterface */ private $dbi; diff --git a/libraries/classes/Controllers/ViewOperationsController.php b/libraries/classes/Controllers/View/OperationsController.php index e0a3bf8e67..7a48e0925f 100644 --- a/libraries/classes/Controllers/ViewOperationsController.php +++ b/libraries/classes/Controllers/View/OperationsController.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace PhpMyAdmin\Controllers; +namespace PhpMyAdmin\Controllers\View; +use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\DbTableExists; use PhpMyAdmin\Html\Generator; @@ -19,7 +20,7 @@ use function __; /** * View manipulations */ -class ViewOperationsController extends AbstractController +class OperationsController extends AbstractController { /** @var Operations */ private $operations; diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index 6e3aad5e75..a417e0cba9 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -1243,7 +1243,7 @@ class Export $active_page = Url::getFromRoute('/database/export'); /** @var DatabaseExportController $controller */ $controller = $containerBuilder->get(DatabaseExportController::class); - $controller->index(); + $controller(); return; } diff --git a/libraries/routes.php b/libraries/routes.php index e3af4252fe..3acb0f8633 100644 --- a/libraries/routes.php +++ b/libraries/routes.php @@ -8,13 +8,17 @@ use PhpMyAdmin\Controllers\ChangeLogController; use PhpMyAdmin\Controllers\CheckRelationsController; use PhpMyAdmin\Controllers\CollationConnectionController; use PhpMyAdmin\Controllers\ColumnController; -use PhpMyAdmin\Controllers\ConfigController; +use PhpMyAdmin\Controllers\Config\GetConfigController; +use PhpMyAdmin\Controllers\Config\SetConfigController; +use PhpMyAdmin\Controllers\Database\CentralColumns\PopulateColumnsController; use PhpMyAdmin\Controllers\Database\CentralColumnsController; use PhpMyAdmin\Controllers\Database\DataDictionaryController; use PhpMyAdmin\Controllers\Database\DesignerController; use PhpMyAdmin\Controllers\Database\EventsController; use PhpMyAdmin\Controllers\Database\ExportController as DatabaseExportController; use PhpMyAdmin\Controllers\Database\ImportController as DatabaseImportController; +use PhpMyAdmin\Controllers\Database\MultiTableQuery\QueryController; +use PhpMyAdmin\Controllers\Database\MultiTableQuery\TablesController as MultiTableQueryTablesController; use PhpMyAdmin\Controllers\Database\MultiTableQueryController; use PhpMyAdmin\Controllers\Database\OperationsController; use PhpMyAdmin\Controllers\Database\QueryByExampleController; @@ -28,8 +32,12 @@ use PhpMyAdmin\Controllers\Database\TrackingController; use PhpMyAdmin\Controllers\Database\TriggersController; use PhpMyAdmin\Controllers\DatabaseController; use PhpMyAdmin\Controllers\ErrorReportController; -use PhpMyAdmin\Controllers\ExportController; -use PhpMyAdmin\Controllers\ExportTemplateController; +use PhpMyAdmin\Controllers\Export\ExportController; +use PhpMyAdmin\Controllers\Export\TablesController; +use PhpMyAdmin\Controllers\Export\Template\CreateController as TemplateCreateController; +use PhpMyAdmin\Controllers\Export\Template\DeleteController as TemplateDeleteController; +use PhpMyAdmin\Controllers\Export\Template\LoadController as TemplateLoadController; +use PhpMyAdmin\Controllers\Export\Template\UpdateController as TemplateUpdateController; use PhpMyAdmin\Controllers\GisDataEditorController; use PhpMyAdmin\Controllers\GitInfoController; use PhpMyAdmin\Controllers\HomeController; @@ -99,12 +107,12 @@ use PhpMyAdmin\Controllers\Table\TriggersController as TableTriggersController; use PhpMyAdmin\Controllers\Table\ZoomSearchController; use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\Controllers\ThemesController; -use PhpMyAdmin\Controllers\TransformationOverviewController; -use PhpMyAdmin\Controllers\TransformationWrapperController; +use PhpMyAdmin\Controllers\Transformation\OverviewController; +use PhpMyAdmin\Controllers\Transformation\WrapperController; use PhpMyAdmin\Controllers\UserPasswordController; use PhpMyAdmin\Controllers\VersionCheckController; -use PhpMyAdmin\Controllers\ViewCreateController; -use PhpMyAdmin\Controllers\ViewOperationsController; +use PhpMyAdmin\Controllers\View\CreateController as ViewCreateController; +use PhpMyAdmin\Controllers\View\OperationsController as ViewOperationsController; if (! defined('PHPMYADMIN')) { exit; @@ -118,23 +126,23 @@ return static function (RouteCollector $routes): void { $routes->post('/collation-connection', CollationConnectionController::class); $routes->post('/columns', ColumnController::class); $routes->addGroup('/config', static function (RouteCollector $routes): void { - $routes->post('/get', [ConfigController::class, 'get']); - $routes->post('/set', [ConfigController::class, 'set']); + $routes->post('/get', GetConfigController::class); + $routes->post('/set', SetConfigController::class); }); $routes->addGroup('/database', static function (RouteCollector $routes): void { $routes->addGroup('/central-columns', static function (RouteCollector $routes): void { - $routes->addRoute(['GET', 'POST'], '', [CentralColumnsController::class, 'index']); - $routes->post('/populate', [CentralColumnsController::class, 'populateColumns']); + $routes->addRoute(['GET', 'POST'], '', CentralColumnsController::class); + $routes->post('/populate', PopulateColumnsController::class); }); $routes->get('/data-dictionary', DataDictionaryController::class); $routes->addRoute(['GET', 'POST'], '/designer', DesignerController::class); $routes->addRoute(['GET', 'POST'], '/events', EventsController::class); - $routes->addRoute(['GET', 'POST'], '/export', [DatabaseExportController::class, 'index']); + $routes->addRoute(['GET', 'POST'], '/export', DatabaseExportController::class); $routes->addRoute(['GET', 'POST'], '/import', DatabaseImportController::class); $routes->addGroup('/multi-table-query', static function (RouteCollector $routes): void { - $routes->get('', [MultiTableQueryController::class, 'index']); - $routes->get('/tables', [MultiTableQueryController::class, 'table']); - $routes->post('/query', [MultiTableQueryController::class, 'displayResults']); + $routes->get('', MultiTableQueryController::class); + $routes->get('/tables', MultiTableQueryTablesController::class); + $routes->post('/query', QueryController::class); }); $routes->addGroup('/operations', static function (RouteCollector $routes): void { $routes->addRoute(['GET', 'POST'], '', [OperationsController::class, 'index']); @@ -185,12 +193,12 @@ return static function (RouteCollector $routes): void { $routes->addGroup('/export', static function (RouteCollector $routes): void { $routes->addRoute(['GET', 'POST'], '', ExportController::class); $routes->get('/check-time-out', [ExportController::class, 'checkTimeOut']); - $routes->post('/tables', [DatabaseExportController::class, 'tables']); + $routes->post('/tables', TablesController::class); $routes->addGroup('/template', static function (RouteCollector $routes): void { - $routes->post('/create', [ExportTemplateController::class, 'create']); - $routes->post('/delete', [ExportTemplateController::class, 'delete']); - $routes->post('/load', [ExportTemplateController::class, 'load']); - $routes->post('/update', [ExportTemplateController::class, 'update']); + $routes->post('/create', TemplateCreateController::class); + $routes->post('/delete', TemplateDeleteController::class); + $routes->post('/load', TemplateLoadController::class); + $routes->post('/update', TemplateUpdateController::class); }); }); $routes->addRoute(['GET', 'POST'], '/gis-data-editor', GisDataEditorController::class); @@ -347,8 +355,8 @@ return static function (RouteCollector $routes): void { $routes->post('/set', [ThemesController::class, 'setTheme']); }); $routes->addGroup('/transformation', static function (RouteCollector $routes): void { - $routes->addRoute(['GET', 'POST'], '/overview', TransformationOverviewController::class); - $routes->addRoute(['GET', 'POST'], '/wrapper', TransformationWrapperController::class); + $routes->addRoute(['GET', 'POST'], '/overview', OverviewController::class); + $routes->addRoute(['GET', 'POST'], '/wrapper', WrapperController::class); }); $routes->addRoute(['GET', 'POST'], '/user-password', UserPasswordController::class); $routes->addRoute(['GET', 'POST'], '/version-check', VersionCheckController::class); diff --git a/libraries/services_controllers.php b/libraries/services_controllers.php index 64d25fdca2..b6ae3c6ead 100644 --- a/libraries/services_controllers.php +++ b/libraries/services_controllers.php @@ -44,14 +44,31 @@ return [ '$dbi' => '@dbi', ], ], - PhpMyAdmin\Controllers\ConfigController::class => [ - 'class' => PhpMyAdmin\Controllers\ConfigController::class, + PhpMyAdmin\Controllers\Config\GetConfigController::class => [ + 'class' => PhpMyAdmin\Controllers\Config\GetConfigController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', '$config' => '@config', ], ], + PhpMyAdmin\Controllers\Config\SetConfigController::class => [ + 'class' => PhpMyAdmin\Controllers\Config\SetConfigController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$config' => '@config', + ], + ], + PhpMyAdmin\Controllers\Database\CentralColumns\PopulateColumnsController::class => [ + 'class' => PhpMyAdmin\Controllers\Database\CentralColumns\PopulateColumnsController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$centralColumns' => '@central_columns', + ], + ], PhpMyAdmin\Controllers\Database\CentralColumnsController::class => [ 'class' => PhpMyAdmin\Controllers\Database\CentralColumnsController::class, 'arguments' => [ @@ -111,6 +128,21 @@ return [ '$dbi' => '@dbi', ], ], + PhpMyAdmin\Controllers\Database\MultiTableQuery\QueryController::class => [ + 'class' => PhpMyAdmin\Controllers\Database\MultiTableQuery\QueryController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + ], + ], + PhpMyAdmin\Controllers\Database\MultiTableQuery\TablesController::class => [ + 'class' => PhpMyAdmin\Controllers\Database\MultiTableQuery\TablesController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$dbi' => '@dbi', + ], + ], PhpMyAdmin\Controllers\Database\MultiTableQueryController::class => [ 'class' => PhpMyAdmin\Controllers\Database\MultiTableQueryController::class, 'arguments' => [ @@ -247,8 +279,8 @@ return [ '$errorHandler' => '@error_handler', ], ], - PhpMyAdmin\Controllers\ExportController::class => [ - 'class' => PhpMyAdmin\Controllers\ExportController::class, + PhpMyAdmin\Controllers\Export\ExportController::class => [ + 'class' => PhpMyAdmin\Controllers\Export\ExportController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', @@ -256,8 +288,43 @@ return [ '$relation' => '@relation', ], ], - PhpMyAdmin\Controllers\ExportTemplateController::class => [ - 'class' => PhpMyAdmin\Controllers\ExportTemplateController::class, + PhpMyAdmin\Controllers\Export\TablesController::class => [ + 'class' => PhpMyAdmin\Controllers\Export\TablesController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$exportController' => '@' . PhpMyAdmin\Controllers\Database\ExportController::class, + ], + ], + PhpMyAdmin\Controllers\Export\Template\CreateController::class => [ + 'class' => PhpMyAdmin\Controllers\Export\Template\CreateController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$model' => '@export_template_model', + '$relation' => '@relation', + ], + ], + PhpMyAdmin\Controllers\Export\Template\DeleteController::class => [ + 'class' => PhpMyAdmin\Controllers\Export\Template\DeleteController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$model' => '@export_template_model', + '$relation' => '@relation', + ], + ], + PhpMyAdmin\Controllers\Export\Template\LoadController::class => [ + 'class' => PhpMyAdmin\Controllers\Export\Template\LoadController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$model' => '@export_template_model', + '$relation' => '@relation', + ], + ], + PhpMyAdmin\Controllers\Export\Template\UpdateController::class => [ + 'class' => PhpMyAdmin\Controllers\Export\Template\UpdateController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', @@ -926,16 +993,16 @@ return [ '$themeManager' => '@theme_manager', ], ], - PhpMyAdmin\Controllers\TransformationOverviewController::class => [ - 'class' => PhpMyAdmin\Controllers\TransformationOverviewController::class, + PhpMyAdmin\Controllers\Transformation\OverviewController::class => [ + 'class' => PhpMyAdmin\Controllers\Transformation\OverviewController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', '$transformations' => '@transformations', ], ], - PhpMyAdmin\Controllers\TransformationWrapperController::class => [ - 'class' => PhpMyAdmin\Controllers\TransformationWrapperController::class, + PhpMyAdmin\Controllers\Transformation\WrapperController::class => [ + 'class' => PhpMyAdmin\Controllers\Transformation\WrapperController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', @@ -960,16 +1027,16 @@ return [ '$template' => '@template', ], ], - PhpMyAdmin\Controllers\ViewCreateController::class => [ - 'class' => PhpMyAdmin\Controllers\ViewCreateController::class, + PhpMyAdmin\Controllers\View\CreateController::class => [ + 'class' => PhpMyAdmin\Controllers\View\CreateController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', '$dbi' => '@dbi', ], ], - PhpMyAdmin\Controllers\ViewOperationsController::class => [ - 'class' => PhpMyAdmin\Controllers\ViewOperationsController::class, + PhpMyAdmin\Controllers\View\OperationsController::class => [ + 'class' => PhpMyAdmin\Controllers\View\OperationsController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8e6c8dd89d..4631822c98 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -106,11 +106,6 @@ parameters: path: libraries/classes/Controllers/Database/StructureController.php - - message: "#^Expression \"null\" on a separate line does not do anything\\.$#" - count: 1 - path: libraries/classes/Controllers/ExportController.php - - - message: "#^Elseif condition is always false\\.$#" count: 1 path: libraries/classes/Controllers/ImportController.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 33a43e6e49..16b4ff82ae 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<files psalm-version="4.9.3@4c262932602b9bbab5020863d1eb22d49de0dbf4"> +<files psalm-version="4.10.0@916b098b008f6de4543892b1e0651c1c3b92cbfa"> <file src="js/messages.php"> <UnusedVariable occurrences="1"> <code>$isMinimumCommon</code> @@ -648,6 +648,9 @@ <code>$verbose</code> <code>empty($host) ? 'localhost' : $host</code> </MixedReturnStatement> + <PossiblyInvalidPropertyAssignmentValue occurrences="1"> + <code>$this->defaultCfg</code> + </PossiblyInvalidPropertyAssignmentValue> <PossiblyNullArgument occurrences="1"> <code>$this->baseCfg</code> </PossiblyNullArgument> @@ -1091,14 +1094,18 @@ <code>$_POST['collation_connection']</code> </MixedArgument> </file> - <file src="libraries/classes/Controllers/ConfigController.php"> + <file src="libraries/classes/Controllers/Config/SetConfigController.php"> <MixedArgument occurrences="1"> <code>json_decode($value)</code> </MixedArgument> </file> - <file src="libraries/classes/Controllers/Database/CentralColumnsController.php"> - <MixedArgument occurrences="25"> + <file src="libraries/classes/Controllers/Database/CentralColumns/PopulateColumnsController.php"> + <MixedArgument occurrences="1"> <code>$_POST['selectedTable']</code> + </MixedArgument> + </file> + <file src="libraries/classes/Controllers/Database/CentralColumnsController.php"> + <MixedArgument occurrences="24"> <code>$columnDefault</code> <code>$columnDefault</code> <code>$db</code> @@ -1327,19 +1334,23 @@ <code>$_SESSION[$SESSION_KEY]['handler']::getIdKey()</code> </MixedMethodCall> </file> - <file src="libraries/classes/Controllers/Database/MultiTableQueryController.php"> - <MixedArgument occurrences="4"> - <code>$params['db']</code> + <file src="libraries/classes/Controllers/Database/MultiTableQuery/QueryController.php"> + <MixedArgument occurrences="2"> <code>$params['db']</code> <code>$params['sql_query']</code> + </MixedArgument> + <PossiblyNullArgument occurrences="1"> + <code>$params['db']</code> + </PossiblyNullArgument> + </file> + <file src="libraries/classes/Controllers/Database/MultiTableQuery/TablesController.php"> + <MixedArgument occurrences="2"> + <code>$params['db']</code> <code>$table</code> </MixedArgument> <MixedAssignment occurrences="1"> <code>$table</code> </MixedAssignment> - <PossiblyNullArgument occurrences="1"> - <code>$params['db']</code> - </PossiblyNullArgument> </file> <file src="libraries/classes/Controllers/Database/OperationsController.php"> <MixedArgument occurrences="17"> @@ -1846,7 +1857,7 @@ <code>$_SESSION['prev_error_subm_time']</code> </MixedOperand> </file> - <file src="libraries/classes/Controllers/ExportController.php"> + <file src="libraries/classes/Controllers/Export/ExportController.php"> <DocblockTypeContradiction occurrences="1"> <code>empty($export_plugin)</code> </DocblockTypeContradiction> @@ -4178,7 +4189,7 @@ <code>$preferences['config_data']['ThemeDefault']</code> </MixedAssignment> </file> - <file src="libraries/classes/Controllers/TransformationOverviewController.php"> + <file src="libraries/classes/Controllers/Transformation/OverviewController.php"> <MixedArgument occurrences="1"> <code>$types[$type . '_file'][$key]</code> </MixedArgument> @@ -4195,7 +4206,7 @@ <code>$transformation</code> </MixedAssignment> </file> - <file src="libraries/classes/Controllers/TransformationWrapperController.php"> + <file src="libraries/classes/Controllers/Transformation/WrapperController.php"> <MixedArgument occurrences="20"> <code>$_GET['where_clause_sign'] ?? ''</code> <code>$cn ?? ''</code> @@ -4279,7 +4290,7 @@ <code>$version</code> </MixedAssignment> </file> - <file src="libraries/classes/Controllers/ViewCreateController.php"> + <file src="libraries/classes/Controllers/View/CreateController.php"> <DocblockTypeContradiction occurrences="1"> <code>$view['as']</code> </DocblockTypeContradiction> @@ -4348,7 +4359,7 @@ <code>isset($stmt->body)</code> </RedundantConditionGivenDocblockType> </file> - <file src="libraries/classes/Controllers/ViewOperationsController.php"> + <file src="libraries/classes/Controllers/View/OperationsController.php"> <MixedArgument occurrences="5"> <code>$_POST['new_name']</code> <code>$db</code> @@ -7667,9 +7678,6 @@ </RedundantPropertyInitializationCheck> </file> <file src="libraries/classes/Gis/GisPolygon.php"> - <InvalidNullableReturnType occurrences="1"> - <code>array|false</code> - </InvalidNullableReturnType> <MixedArgument occurrences="7"> <code>$points_arr[2]</code> <code>$points_arr[2]</code> @@ -9385,8 +9393,7 @@ <code>$retval</code> <code>$value</code> </MixedAssignment> - <MixedOperand occurrences="4"> - <code>$retval</code> + <MixedOperand occurrences="3"> <code>$retval</code> <code>$retval</code> <code>$retval</code> @@ -10866,7 +10873,7 @@ <code>$do_mime</code> <code>$do_relation</code> </ParamNameMismatch> - <PossiblyNullArgument occurrences="10"> + <PossiblyNullArgument occurrences="9"> <code>$col_as</code> <code>$table_alias</code> <code>$table_alias</code> @@ -10875,7 +10882,6 @@ <code>$table_alias</code> <code>$table_alias</code> <code>$table_alias</code> - <code>$table_alias</code> <code>$view_alias</code> </PossiblyNullArgument> </file> @@ -12096,10 +12102,6 @@ <PossiblyInvalidCast occurrences="1"> <code>$tables[$i][Import::TBL_NAME]</code> </PossiblyInvalidCast> - <PossiblyNullReference occurrences="2"> - <code>attributes</code> - <code>attributes</code> - </PossiblyNullReference> <RedundantConditionGivenDocblockType occurrences="1"> <code>$xml</code> </RedundantConditionGivenDocblockType> @@ -17257,7 +17259,12 @@ <code>[$currentTable]</code> </MixedAssignment> </file> - <file src="test/classes/Controllers/ExportTemplateControllerTest.php"> + <file src="test/classes/Controllers/Export/Template/CreateControllerTest.php"> + <MixedArrayAssignment occurrences="1"> + <code>$_SESSION['relation'][$GLOBALS['server']]</code> + </MixedArrayAssignment> + </file> + <file src="test/classes/Controllers/Export/Template/LoadControllerTest.php"> <MixedArrayAssignment occurrences="1"> <code>$_SESSION['relation'][$GLOBALS['server']]</code> </MixedArrayAssignment> diff --git a/test/classes/Controllers/Database/MultiTableQueryControllerTest.php b/test/classes/Controllers/Database/MultiTableQuery/TablesControllerTest.php index 8dd7a538fe..c7bce01764 100644 --- a/test/classes/Controllers/Database/MultiTableQueryControllerTest.php +++ b/test/classes/Controllers/Database/MultiTableQuery/TablesControllerTest.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace PhpMyAdmin\Tests\Controllers\Database; +namespace PhpMyAdmin\Tests\Controllers\Database\MultiTableQuery; -use PhpMyAdmin\Controllers\Database\MultiTableQueryController; +use PhpMyAdmin\Controllers\Database\MultiTableQuery\TablesController; use PhpMyAdmin\Tests\AbstractTestCase; /** - * @covers \PhpMyAdmin\Controllers\Database\MultiTableQueryController + * @covers \PhpMyAdmin\Controllers\Database\MultiTableQuery\TablesController */ -class MultiTableQueryControllerTest extends AbstractTestCase +class TablesControllerTest extends AbstractTestCase { protected function setUp(): void { @@ -34,10 +34,9 @@ class MultiTableQueryControllerTest extends AbstractTestCase $_GET['db'] = 'test'; global $containerBuilder; - $containerBuilder->setParameter('db', $_GET['db']); - /** @var MultiTableQueryController $multiTableQueryController */ - $multiTableQueryController = $containerBuilder->get(MultiTableQueryController::class); - $multiTableQueryController->table(); + /** @var TablesController $multiTableQueryController */ + $multiTableQueryController = $containerBuilder->get(TablesController::class); + $multiTableQueryController(); $this->assertSame( [ 'foreignKeyConstrains' => [ diff --git a/test/classes/Controllers/Export/Template/CreateControllerTest.php b/test/classes/Controllers/Export/Template/CreateControllerTest.php new file mode 100644 index 0000000000..802d11b684 --- /dev/null +++ b/test/classes/Controllers/Export/Template/CreateControllerTest.php @@ -0,0 +1,82 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\Export\Template\CreateController; +use PhpMyAdmin\Export\Template as ExportTemplate; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; +use PhpMyAdmin\Version; + +/** + * @covers \PhpMyAdmin\Controllers\Export\Template\CreateController + */ +class CreateControllerTest extends AbstractTestCase +{ + public function testCreate(): void + { + global $cfg; + + $GLOBALS['server'] = 1; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = 'index.php'; + + $_SESSION['relation'][$GLOBALS['server']] = [ + 'version' => Version::VERSION, + 'exporttemplateswork' => true, + 'trackingwork' => false, + 'db' => 'db', + 'export_templates' => 'table', + ]; + + $cfg['Server']['user'] = 'user'; + + $response = new ResponseRenderer(); + $template = new Template(); + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([ + ['exportType', '', 'type'], + ['templateName', '', 'name'], + ['templateData', '', 'data'], + ['template_id', null, null], + ]); + + (new CreateController( + $response, + $template, + new TemplateModel($this->dbi), + new Relation($this->dbi, $template) + ))($request); + + $templates = [ + ExportTemplate::fromArray([ + 'id' => 1, + 'username' => 'user1', + 'exportType' => 'type1', + 'name' => 'name1', + 'data' => 'data1', + ]), + ExportTemplate::fromArray([ + 'id' => 2, + 'username' => 'user2', + 'exportType' => 'type2', + 'name' => 'name2', + 'data' => 'data2', + ]), + ]; + + $options = $template->render('export/template_options', [ + 'templates' => $templates, + 'selected_template' => null, + ]); + + $this->assertTrue($response->hasSuccessState()); + $this->assertEquals(['data' => $options], $response->getJSONResult()); + } +} diff --git a/test/classes/Controllers/Export/Template/DeleteControllerTest.php b/test/classes/Controllers/Export/Template/DeleteControllerTest.php new file mode 100644 index 0000000000..ee6cc95482 --- /dev/null +++ b/test/classes/Controllers/Export/Template/DeleteControllerTest.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\Export\Template\DeleteController; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Export\Template\DeleteController + */ +class DeleteControllerTest extends AbstractTestCase +{ + public function testDelete(): void + { + global $cfg; + + $GLOBALS['server'] = 1; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = 'index.php'; + + $cfg['Server']['user'] = 'user'; + + $response = new ResponseRenderer(); + $template = new Template(); + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturn('1'); + + (new DeleteController( + $response, + $template, + new TemplateModel($this->dbi), + new Relation($this->dbi, $template) + ))($request); + + $this->assertTrue($response->hasSuccessState()); + } +} diff --git a/test/classes/Controllers/Export/Template/LoadControllerTest.php b/test/classes/Controllers/Export/Template/LoadControllerTest.php new file mode 100644 index 0000000000..7fe946b650 --- /dev/null +++ b/test/classes/Controllers/Export/Template/LoadControllerTest.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\Export\Template\LoadController; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; +use PhpMyAdmin\Version; + +/** + * @covers \PhpMyAdmin\Controllers\Export\Template\LoadController + */ +class LoadControllerTest extends AbstractTestCase +{ + public function testLoad(): void + { + global $cfg; + + $GLOBALS['server'] = 1; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = 'index.php'; + + $_SESSION['relation'][$GLOBALS['server']] = [ + 'version' => Version::VERSION, + 'exporttemplateswork' => true, + 'trackingwork' => false, + 'db' => 'db', + 'export_templates' => 'table', + ]; + + $cfg['Server']['user'] = 'user'; + + $response = new ResponseRenderer(); + $template = new Template(); + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturn('1'); + + (new LoadController( + $response, + $template, + new TemplateModel($this->dbi), + new Relation($this->dbi, $template) + ))($request); + + $this->assertTrue($response->hasSuccessState()); + $this->assertEquals(['data' => 'data1'], $response->getJSONResult()); + } +} diff --git a/test/classes/Controllers/Export/Template/UpdateControllerTest.php b/test/classes/Controllers/Export/Template/UpdateControllerTest.php new file mode 100644 index 0000000000..1abb188fc4 --- /dev/null +++ b/test/classes/Controllers/Export/Template/UpdateControllerTest.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Export\Template; + +use PhpMyAdmin\Controllers\Export\Template\UpdateController; +use PhpMyAdmin\Export\TemplateModel; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; + +/** + * @covers \PhpMyAdmin\Controllers\Export\Template\UpdateController + */ +class UpdateControllerTest extends AbstractTestCase +{ + public function testUpdate(): void + { + global $cfg; + + $GLOBALS['server'] = 1; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = 'index.php'; + + $cfg['Server']['user'] = 'user'; + + $response = new ResponseRenderer(); + $template = new Template(); + $request = $this->createStub(ServerRequest::class); + $request->method('getParsedBodyParam')->willReturnMap([ + ['templateId', null, '1'], + ['templateData', '', 'data'], + ]); + + (new UpdateController( + $response, + $template, + new TemplateModel($this->dbi), + new Relation($this->dbi, $template) + ))($request); + + $this->assertTrue($response->hasSuccessState()); + } +} diff --git a/test/classes/Controllers/ExportTemplateControllerTest.php b/test/classes/Controllers/ExportTemplateControllerTest.php deleted file mode 100644 index 16966ff2a9..0000000000 --- a/test/classes/Controllers/ExportTemplateControllerTest.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace PhpMyAdmin\Tests\Controllers; - -use PhpMyAdmin\Controllers\ExportTemplateController; -use PhpMyAdmin\Export\Template as ExportTemplate; -use PhpMyAdmin\Export\TemplateModel; -use PhpMyAdmin\Http\ServerRequest; -use PhpMyAdmin\Relation; -use PhpMyAdmin\Template; -use PhpMyAdmin\Tests\AbstractTestCase; -use PhpMyAdmin\Tests\Stubs\ResponseRenderer; -use PhpMyAdmin\Version; - -/** - * @covers \PhpMyAdmin\Controllers\ExportTemplateController - */ -class ExportTemplateControllerTest extends AbstractTestCase -{ - /** @var ExportTemplateController */ - private $controller; - - /** @var ResponseRenderer */ - private $response; - - /** @var Template */ - private $template; - - protected function setUp(): void - { - parent::setUp(); - parent::setTheme(); - - global $dbi; - - $GLOBALS['server'] = 1; - $GLOBALS['text_dir'] = 'ltr'; - $GLOBALS['PMA_PHP_SELF'] = ''; - - $_SESSION['relation'][$GLOBALS['server']] = [ - 'version' => Version::VERSION, - 'exporttemplateswork' => true, - 'trackingwork' => false, - 'db' => 'db', - 'export_templates' => 'table', - ]; - - $this->response = new ResponseRenderer(); - $this->template = new Template(); - - $this->controller = new ExportTemplateController( - $this->response, - $this->template, - new TemplateModel($dbi), - new Relation($dbi, $this->template) - ); - } - - public function testCreate(): void - { - global $cfg; - - $cfg['Server']['user'] = 'user'; - - $request = $this->createStub(ServerRequest::class); - $request->method('getParsedBodyParam')->willReturnMap([ - ['exportType', '', 'type'], - ['templateName', '', 'name'], - ['templateData', '', 'data'], - ['template_id', null, null], - ]); - - $this->controller->create($request); - - $templates = [ - ExportTemplate::fromArray([ - 'id' => 1, - 'username' => 'user1', - 'exportType' => 'type1', - 'name' => 'name1', - 'data' => 'data1', - ]), - ExportTemplate::fromArray([ - 'id' => 2, - 'username' => 'user2', - 'exportType' => 'type2', - 'name' => 'name2', - 'data' => 'data2', - ]), - ]; - - $options = $this->template->render('export/template_options', [ - 'templates' => $templates, - 'selected_template' => null, - ]); - - $this->assertTrue($this->response->hasSuccessState()); - $this->assertEquals(['data' => $options], $this->response->getJSONResult()); - } - - public function testDelete(): void - { - global $cfg; - - $cfg['Server']['user'] = 'user'; - - $request = $this->createStub(ServerRequest::class); - $request->method('getParsedBodyParam')->willReturn('1'); - - $this->controller->delete($request); - - $this->assertTrue($this->response->hasSuccessState()); - } - - public function testLoad(): void - { - global $cfg; - - $cfg['Server']['user'] = 'user'; - - $request = $this->createStub(ServerRequest::class); - $request->method('getParsedBodyParam')->willReturn('1'); - - $this->controller->load($request); - - $this->assertTrue($this->response->hasSuccessState()); - $this->assertEquals(['data' => 'data1'], $this->response->getJSONResult()); - } - - public function testUpdate(): void - { - global $cfg; - - $cfg['Server']['user'] = 'user'; - - $request = $this->createStub(ServerRequest::class); - $request->method('getParsedBodyParam')->willReturnMap([ - ['templateId', null, '1'], - ['templateData', '', 'data'], - ]); - - $this->controller->update($request); - - $this->assertTrue($this->response->hasSuccessState()); - } -} diff --git a/test/classes/Controllers/TransformationOverviewControllerTest.php b/test/classes/Controllers/Transformation/OverviewControllerTest.php index 1a30a4a326..ca879f9126 100644 --- a/test/classes/Controllers/TransformationOverviewControllerTest.php +++ b/test/classes/Controllers/Transformation/OverviewControllerTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace PhpMyAdmin\Tests\Controllers; +namespace PhpMyAdmin\Tests\Controllers\Transformation; -use PhpMyAdmin\Controllers\TransformationOverviewController; +use PhpMyAdmin\Controllers\Transformation\OverviewController; use PhpMyAdmin\Template; use PhpMyAdmin\Tests\AbstractTestCase; use PhpMyAdmin\Tests\Stubs\ResponseRenderer; @@ -13,9 +13,9 @@ use PhpMyAdmin\Transformations; use function __; /** - * @covers \PhpMyAdmin\Controllers\TransformationOverviewController + * @covers \PhpMyAdmin\Controllers\Transformation\OverviewController */ -class TransformationOverviewControllerTest extends AbstractTestCase +class OverviewControllerTest extends AbstractTestCase { /** * Prepares environment for the test. @@ -37,7 +37,7 @@ class TransformationOverviewControllerTest extends AbstractTestCase { $response = new ResponseRenderer(); - $controller = new TransformationOverviewController($response, new Template(), new Transformations()); + $controller = new OverviewController($response, new Template(), new Transformations()); $controller(); $actual = $response->getHTMLResult(); |