diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-11 21:20:46 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-11 21:20:46 +0300 |
commit | bfaf16f56b0bab26ab994802045cf89fbf945c7d (patch) | |
tree | b09e728f68ef9f63f74e9f998ffdece5e6d41dbb /libraries | |
parent | 00cb1b366841d88621f6383f1b99638145424b7e (diff) |
Use only callable controllers
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
35 files changed, 1667 insertions, 854 deletions
diff --git a/libraries/classes/Controllers/Sql/ColumnPreferencesController.php b/libraries/classes/Controllers/Sql/ColumnPreferencesController.php new file mode 100644 index 0000000000..50aabe5213 --- /dev/null +++ b/libraries/classes/Controllers/Sql/ColumnPreferencesController.php @@ -0,0 +1,71 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Sql; + +use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Message; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Sql; +use PhpMyAdmin\Template; + +final class ColumnPreferencesController extends AbstractController +{ + /** @var Sql */ + private $sql; + + /** @var CheckUserPrivileges */ + private $checkUserPrivileges; + + /** @var DatabaseInterface */ + private $dbi; + + /** + * @param ResponseRenderer $response + * @param DatabaseInterface $dbi + */ + public function __construct( + $response, + Template $template, + Sql $sql, + CheckUserPrivileges $checkUserPrivileges, + $dbi + ) { + parent::__construct($response, $template); + $this->sql = $sql; + $this->checkUserPrivileges = $checkUserPrivileges; + $this->dbi = $dbi; + } + + public function __invoke(): void + { + global $db, $table; + + $this->checkUserPrivileges->getPrivileges(); + + $tableObject = $this->dbi->getTable($db, $table); + $status = false; + + // set column order + if (isset($_POST['col_order'])) { + $status = $this->sql->setColumnProperty($tableObject, 'col_order'); + } + + // set column visibility + if ($status === true && isset($_POST['col_visib'])) { + $status = $this->sql->setColumnProperty($tableObject, 'col_visib'); + } + + if ($status instanceof Message) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', $status->getString()); + + return; + } + + $this->response->setRequestStatus($status === true); + } +} diff --git a/libraries/classes/Controllers/Sql/DefaultForeignKeyCheckValueController.php b/libraries/classes/Controllers/Sql/DefaultForeignKeyCheckValueController.php new file mode 100644 index 0000000000..b6cb7d5556 --- /dev/null +++ b/libraries/classes/Controllers/Sql/DefaultForeignKeyCheckValueController.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Sql; + +use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use PhpMyAdmin\Utils\ForeignKey; + +final class DefaultForeignKeyCheckValueController extends AbstractController +{ + /** @var CheckUserPrivileges */ + private $checkUserPrivileges; + + /** + * @param ResponseRenderer $response + */ + public function __construct($response, Template $template, CheckUserPrivileges $checkUserPrivileges) + { + parent::__construct($response, $template); + $this->checkUserPrivileges = $checkUserPrivileges; + } + + public function __invoke(): void + { + $this->checkUserPrivileges->getPrivileges(); + $this->response->addJSON('default_fk_check_value', ForeignKey::isCheckEnabled()); + } +} diff --git a/libraries/classes/Controllers/Sql/EnumValuesController.php b/libraries/classes/Controllers/Sql/EnumValuesController.php new file mode 100644 index 0000000000..4248b40955 --- /dev/null +++ b/libraries/classes/Controllers/Sql/EnumValuesController.php @@ -0,0 +1,70 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Sql; + +use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Sql; +use PhpMyAdmin\Template; + +use function __; +use function htmlentities; + +use const ENT_COMPAT; + +final class EnumValuesController extends AbstractController +{ + /** @var Sql */ + private $sql; + + /** @var CheckUserPrivileges */ + private $checkUserPrivileges; + + /** + * @param ResponseRenderer $response + */ + public function __construct( + $response, + Template $template, + Sql $sql, + CheckUserPrivileges $checkUserPrivileges + ) { + parent::__construct($response, $template); + $this->sql = $sql; + $this->checkUserPrivileges = $checkUserPrivileges; + } + + /** + * Get possible values for enum fields during grid edit. + */ + public function __invoke(): void + { + global $db, $table; + + $this->checkUserPrivileges->getPrivileges(); + + $column = $_POST['column']; + $curr_value = $_POST['curr_value']; + $values = $this->sql->getValuesForColumn($db, $table, $column); + + if ($values === null) { + $this->response->addJSON('message', __('Error in processing request')); + $this->response->setRequestStatus(false); + + return; + } + + // Converts characters of $curr_value to HTML entities. + $convertedCurrentValue = htmlentities($curr_value, ENT_COMPAT, 'UTF-8'); + + $dropdown = $this->template->render('sql/enum_column_dropdown', [ + 'values' => $values, + 'selected_values' => [$convertedCurrentValue], + ]); + + $this->response->addJSON('dropdown', $dropdown); + } +} diff --git a/libraries/classes/Controllers/Sql/RelationalValuesController.php b/libraries/classes/Controllers/Sql/RelationalValuesController.php new file mode 100644 index 0000000000..f036c0079d --- /dev/null +++ b/libraries/classes/Controllers/Sql/RelationalValuesController.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Sql; + +use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Sql; +use PhpMyAdmin\Template; + +final class RelationalValuesController extends AbstractController +{ + /** @var Sql */ + private $sql; + + /** @var CheckUserPrivileges */ + private $checkUserPrivileges; + + /** + * @param ResponseRenderer $response + */ + public function __construct( + $response, + Template $template, + Sql $sql, + CheckUserPrivileges $checkUserPrivileges + ) { + parent::__construct($response, $template); + $this->sql = $sql; + $this->checkUserPrivileges = $checkUserPrivileges; + } + + /** + * Get values for the relational columns + * + * During grid edit, if we have a relational field, show the dropdown for it. + */ + public function __invoke(): void + { + global $db, $table; + + $this->checkUserPrivileges->getPrivileges(); + + $column = $_POST['column']; + if ( + $_SESSION['tmpval']['relational_display'] === 'D' + && isset($_POST['relation_key_or_display_column']) + && $_POST['relation_key_or_display_column'] + ) { + $curr_value = $_POST['relation_key_or_display_column']; + } else { + $curr_value = $_POST['curr_value']; + } + + $dropdown = $this->sql->getHtmlForRelationalColumnDropdown( + $db, + $table, + $column, + $curr_value + ); + $this->response->addJSON('dropdown', $dropdown); + } +} diff --git a/libraries/classes/Controllers/Sql/SetValuesController.php b/libraries/classes/Controllers/Sql/SetValuesController.php new file mode 100644 index 0000000000..b13f7b20a2 --- /dev/null +++ b/libraries/classes/Controllers/Sql/SetValuesController.php @@ -0,0 +1,83 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Sql; + +use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Sql; +use PhpMyAdmin\Template; + +use function __; +use function htmlentities; + +use const ENT_COMPAT; + +final class SetValuesController extends AbstractController +{ + /** @var Sql */ + private $sql; + + /** @var CheckUserPrivileges */ + private $checkUserPrivileges; + + /** + * @param ResponseRenderer $response + */ + public function __construct( + $response, + Template $template, + Sql $sql, + CheckUserPrivileges $checkUserPrivileges + ) { + parent::__construct($response, $template); + $this->sql = $sql; + $this->checkUserPrivileges = $checkUserPrivileges; + } + + /** + * Get possible values for SET fields during grid edit. + */ + public function __invoke(): void + { + global $db, $table; + + $this->checkUserPrivileges->getPrivileges(); + + $column = $_POST['column']; + $currentValue = $_POST['curr_value']; + $fullValues = $_POST['get_full_values'] ?? false; + $whereClause = $_POST['where_clause'] ?? null; + + $values = $this->sql->getValuesForColumn($db, $table, $column); + + if ($values === null) { + $this->response->addJSON('message', __('Error in processing request')); + $this->response->setRequestStatus(false); + + return; + } + + // If the $currentValue was truncated, we should fetch the correct full values from the table. + if ($fullValues && ! empty($whereClause)) { + $currentValue = $this->sql->getFullValuesForSetColumn( + $db, + $table, + $column, + $whereClause + ); + } + + // Converts characters of $currentValue to HTML entities. + $convertedCurrentValue = htmlentities($currentValue, ENT_COMPAT, 'UTF-8'); + + $select = $this->template->render('sql/set_column', [ + 'values' => $values, + 'current_values' => $convertedCurrentValue, + ]); + + $this->response->addJSON('select', $select); + } +} diff --git a/libraries/classes/Controllers/SqlController.php b/libraries/classes/Controllers/Sql/SqlController.php index b83730a1e9..d722592284 100644 --- a/libraries/classes/Controllers/SqlController.php +++ b/libraries/classes/Controllers/Sql/SqlController.php @@ -2,11 +2,12 @@ declare(strict_types=1); -namespace PhpMyAdmin\Controllers; +namespace PhpMyAdmin\Controllers\Sql; use PhpMyAdmin\Bookmark; use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; @@ -17,17 +18,13 @@ use PhpMyAdmin\Sql; use PhpMyAdmin\Template; use PhpMyAdmin\Url; use PhpMyAdmin\Util; -use PhpMyAdmin\Utils\ForeignKey; use function __; -use function htmlentities; use function mb_strpos; use function str_contains; use function strlen; use function urlencode; -use const ENT_COMPAT; - class SqlController extends AbstractController { /** @var Sql */ @@ -56,7 +53,7 @@ class SqlController extends AbstractController $this->dbi = $dbi; } - public function index(): void + public function __invoke(): void { global $cfg, $db, $display_query, $sql_query, $table; global $ajax_reload, $goto, $errorUrl, $find_real_end, $unlim_num_rows, $import_text, $disp_query; @@ -226,151 +223,6 @@ class SqlController extends AbstractController )); } - /** - * Get values for the relational columns - * - * During grid edit, if we have a relational field, show the dropdown for it. - */ - public function getRelationalValues(): void - { - global $db, $table; - - $this->checkUserPrivileges->getPrivileges(); - - $column = $_POST['column']; - if ( - $_SESSION['tmpval']['relational_display'] === 'D' - && isset($_POST['relation_key_or_display_column']) - && $_POST['relation_key_or_display_column'] - ) { - $curr_value = $_POST['relation_key_or_display_column']; - } else { - $curr_value = $_POST['curr_value']; - } - - $dropdown = $this->sql->getHtmlForRelationalColumnDropdown( - $db, - $table, - $column, - $curr_value - ); - $this->response->addJSON('dropdown', $dropdown); - } - - /** - * Get possible values for enum fields during grid edit. - */ - public function getEnumValues(): void - { - global $db, $table; - - $this->checkUserPrivileges->getPrivileges(); - - $column = $_POST['column']; - $curr_value = $_POST['curr_value']; - $values = $this->sql->getValuesForColumn($db, $table, $column); - - if ($values === null) { - $this->response->addJSON('message', __('Error in processing request')); - $this->response->setRequestStatus(false); - - return; - } - - // Converts characters of $curr_value to HTML entities. - $convertedCurrentValue = htmlentities($curr_value, ENT_COMPAT, 'UTF-8'); - - $dropdown = $this->template->render('sql/enum_column_dropdown', [ - 'values' => $values, - 'selected_values' => [$convertedCurrentValue], - ]); - - $this->response->addJSON('dropdown', $dropdown); - } - - /** - * Get possible values for SET fields during grid edit. - */ - public function getSetValues(): void - { - global $db, $table; - - $this->checkUserPrivileges->getPrivileges(); - - $column = $_POST['column']; - $currentValue = $_POST['curr_value']; - $fullValues = $_POST['get_full_values'] ?? false; - $whereClause = $_POST['where_clause'] ?? null; - - $values = $this->sql->getValuesForColumn($db, $table, $column); - - if ($values === null) { - $this->response->addJSON('message', __('Error in processing request')); - $this->response->setRequestStatus(false); - - return; - } - - // If the $currentValue was truncated, we should fetch the correct full values from the table. - if ($fullValues && ! empty($whereClause)) { - $currentValue = $this->sql->getFullValuesForSetColumn( - $db, - $table, - $column, - $whereClause - ); - } - - // Converts characters of $currentValue to HTML entities. - $convertedCurrentValue = htmlentities($currentValue, ENT_COMPAT, 'UTF-8'); - - $select = $this->template->render('sql/set_column', [ - 'values' => $values, - 'current_values' => $convertedCurrentValue, - ]); - - $this->response->addJSON('select', $select); - } - - public function getDefaultForeignKeyCheckValue(): void - { - $this->checkUserPrivileges->getPrivileges(); - - $this->response->addJSON( - 'default_fk_check_value', - ForeignKey::isCheckEnabled() - ); - } - - public function setColumnOrderOrVisibility(): void - { - global $db, $table; - - $this->checkUserPrivileges->getPrivileges(); - - $tableObject = $this->dbi->getTable($db, $table); - $status = false; - - // set column order - if (isset($_POST['col_order'])) { - $status = $this->sql->setColumnProperty($tableObject, 'col_order'); - } - - // set column visibility - if ($status === true && isset($_POST['col_visib'])) { - $status = $this->sql->setColumnProperty($tableObject, 'col_visib'); - } - - if ($status instanceof Message) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', $status->getString()); - - return; - } - - $this->response->setRequestStatus($status === true); - } - private function addBookmark(string $goto): void { global $cfg; diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index 419d7c3df3..fc18643204 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -50,7 +50,7 @@ class ChangeController extends AbstractController $this->relation = $relation; } - public function index(): void + public function __invoke(): void { global $cfg, $db, $table, $text_dir, $disp_message, $urlParams; global $errorUrl, $where_clause, $unsaved_values, $insert_mode, $where_clause_array, $where_clauses; @@ -305,31 +305,4 @@ class ChangeController extends AbstractController $this->response->addHTML($html_output); } - - public function rows(): void - { - global $active_page, $where_clause; - - if (isset($_POST['goto']) && (! isset($_POST['rows_to_delete']) || ! is_array($_POST['rows_to_delete']))) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No row selected.')); - - return; - } - - // As we got the rows to be edited from the - // 'rows_to_delete' checkbox, we use the index of it as the - // indicating WHERE clause. Then we build the array which is used - // for the /table/change script. - $where_clause = []; - if (isset($_POST['rows_to_delete']) && is_array($_POST['rows_to_delete'])) { - foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) { - $where_clause[] = $i_where_clause; - } - } - - $active_page = Url::getFromRoute('/table/change'); - - $this->index(); - } } diff --git a/libraries/classes/Controllers/Table/ChangeRowsController.php b/libraries/classes/Controllers/Table/ChangeRowsController.php new file mode 100644 index 0000000000..1218c53e2e --- /dev/null +++ b/libraries/classes/Controllers/Table/ChangeRowsController.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table; + +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use PhpMyAdmin\Url; + +use function __; +use function is_array; + +final class ChangeRowsController extends AbstractController +{ + /** @var ChangeController */ + private $changeController; + + /** + * @param ResponseRenderer $response + * @param string $db Database name + * @param string $table Table name + */ + public function __construct($response, Template $template, $db, $table, ChangeController $changeController) + { + parent::__construct($response, $template, $db, $table); + $this->changeController = $changeController; + } + + public function __invoke(): void + { + global $active_page, $where_clause; + + if (isset($_POST['goto']) && (! isset($_POST['rows_to_delete']) || ! is_array($_POST['rows_to_delete']))) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No row selected.')); + + return; + } + + // As we got the rows to be edited from the + // 'rows_to_delete' checkbox, we use the index of it as the + // indicating WHERE clause. Then we build the array which is used + // for the /table/change script. + $where_clause = []; + if (isset($_POST['rows_to_delete']) && is_array($_POST['rows_to_delete'])) { + foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) { + $where_clause[] = $i_where_clause; + } + } + + $active_page = Url::getFromRoute('/table/change'); + + ($this->changeController)(); + } +} diff --git a/libraries/classes/Controllers/Table/DeleteConfirmController.php b/libraries/classes/Controllers/Table/DeleteConfirmController.php new file mode 100644 index 0000000000..b2a1ea80d7 --- /dev/null +++ b/libraries/classes/Controllers/Table/DeleteConfirmController.php @@ -0,0 +1,46 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table; + +use PhpMyAdmin\DbTableExists; +use PhpMyAdmin\Url; +use PhpMyAdmin\Util; +use PhpMyAdmin\Utils\ForeignKey; + +use function __; +use function is_array; + +final class DeleteConfirmController extends AbstractController +{ + public function __invoke(): void + { + global $db, $table, $sql_query, $urlParams, $errorUrl, $cfg; + + $selected = $_POST['rows_to_delete'] ?? null; + + if (! isset($selected) || ! is_array($selected)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No row selected.')); + + return; + } + + Util::checkParameters(['db', 'table']); + + $urlParams = ['db' => $db, 'table' => $table]; + $errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table'); + $errorUrl .= Url::getCommon($urlParams, '&'); + + DbTableExists::check(); + + $this->render('table/delete/confirm', [ + 'db' => $db, + 'table' => $table, + 'selected' => $selected, + 'sql_query' => $sql_query, + 'is_foreign_key_check' => ForeignKey::isCheckEnabled(), + ]); + } +} diff --git a/libraries/classes/Controllers/Table/DeleteController.php b/libraries/classes/Controllers/Table/DeleteRowsController.php index fcb3a756e1..08347c7b53 100644 --- a/libraries/classes/Controllers/Table/DeleteController.php +++ b/libraries/classes/Controllers/Table/DeleteRowsController.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\DbTableExists; use PhpMyAdmin\Operations; use PhpMyAdmin\Relation; use PhpMyAdmin\RelationCleanup; @@ -18,10 +17,9 @@ use PhpMyAdmin\Util; use PhpMyAdmin\Utils\ForeignKey; use function __; -use function is_array; use function sprintf; -class DeleteController extends AbstractController +final class DeleteRowsController extends AbstractController { /** @var DatabaseInterface */ private $dbi; @@ -38,7 +36,7 @@ class DeleteController extends AbstractController $this->dbi = $dbi; } - public function rows(): void + public function __invoke(): void { global $db, $goto, $sql_query, $table, $disp_message, $disp_query, $active_page; @@ -111,34 +109,4 @@ class DeleteController extends AbstractController null )); } - - public function confirm(): void - { - global $db, $table, $sql_query, $urlParams, $errorUrl, $cfg; - - $selected = $_POST['rows_to_delete'] ?? null; - - if (! isset($selected) || ! is_array($selected)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No row selected.')); - - return; - } - - Util::checkParameters(['db', 'table']); - - $urlParams = ['db' => $db, 'table' => $table]; - $errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table'); - $errorUrl .= Url::getCommon($urlParams, '&'); - - DbTableExists::check(); - - $this->render('table/delete/confirm', [ - 'db' => $db, - 'table' => $table, - 'selected' => $selected, - 'sql_query' => $sql_query, - 'is_foreign_key_check' => ForeignKey::isCheckEnabled(), - ]); - } } diff --git a/libraries/classes/Controllers/Table/ExportController.php b/libraries/classes/Controllers/Table/ExportController.php index 4ea2181d02..428d23873b 100644 --- a/libraries/classes/Controllers/Table/ExportController.php +++ b/libraries/classes/Controllers/Table/ExportController.php @@ -42,7 +42,7 @@ class ExportController extends AbstractController $this->export = $export; } - public function index(): void + public function __invoke(): void { global $db, $urlParams, $table, $replaces, $cfg, $errorUrl; global $sql_query, $where_clause, $num_tables, $unlim_num_rows; @@ -141,34 +141,4 @@ class ExportController extends AbstractController 'page_settings_html' => $pageSettingsHtml, ])); } - - public function rows(): void - { - global $active_page, $single_table, $where_clause; - - if (isset($_POST['goto']) && (! isset($_POST['rows_to_delete']) || ! is_array($_POST['rows_to_delete']))) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No row selected.')); - - return; - } - - // Needed to allow SQL export - $single_table = true; - - // As we got the rows to be exported from the - // 'rows_to_delete' checkbox, we use the index of it as the - // indicating WHERE clause. Then we build the array which is used - // for the /table/change script. - $where_clause = []; - if (isset($_POST['rows_to_delete']) && is_array($_POST['rows_to_delete'])) { - foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) { - $where_clause[] = $i_where_clause; - } - } - - $active_page = Url::getFromRoute('/table/export'); - - $this->index(); - } } diff --git a/libraries/classes/Controllers/Table/ExportRowsController.php b/libraries/classes/Controllers/Table/ExportRowsController.php new file mode 100644 index 0000000000..424fe4896a --- /dev/null +++ b/libraries/classes/Controllers/Table/ExportRowsController.php @@ -0,0 +1,59 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table; + +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use PhpMyAdmin\Url; + +use function __; +use function is_array; + +final class ExportRowsController extends AbstractController +{ + /** @var ExportController */ + private $exportController; + + /** + * @param ResponseRenderer $response + * @param string $db Database name + * @param string $table Table name + */ + public function __construct($response, Template $template, $db, $table, ExportController $exportController) + { + parent::__construct($response, $template, $db, $table); + $this->exportController = $exportController; + } + + public function __invoke(): void + { + global $active_page, $single_table, $where_clause; + + if (isset($_POST['goto']) && (! isset($_POST['rows_to_delete']) || ! is_array($_POST['rows_to_delete']))) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No row selected.')); + + return; + } + + // Needed to allow SQL export + $single_table = true; + + // As we got the rows to be exported from the + // 'rows_to_delete' checkbox, we use the index of it as the + // indicating WHERE clause. Then we build the array which is used + // for the /table/change script. + $where_clause = []; + if (isset($_POST['rows_to_delete']) && is_array($_POST['rows_to_delete'])) { + foreach ($_POST['rows_to_delete'] as $i => $i_where_clause) { + $where_clause[] = $i_where_clause; + } + } + + $active_page = Url::getFromRoute('/table/export'); + + ($this->exportController)(); + } +} diff --git a/libraries/classes/Controllers/Table/IndexRenameController.php b/libraries/classes/Controllers/Table/IndexRenameController.php new file mode 100644 index 0000000000..23e545a565 --- /dev/null +++ b/libraries/classes/Controllers/Table/IndexRenameController.php @@ -0,0 +1,100 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table; + +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\DbTableExists; +use PhpMyAdmin\Index; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Table\Indexes; +use PhpMyAdmin\Template; +use PhpMyAdmin\Url; +use PhpMyAdmin\Util; + +use function is_array; + +final class IndexRenameController extends AbstractController +{ + /** @var DatabaseInterface */ + private $dbi; + + /** @var Indexes */ + private $indexes; + + /** + * @param ResponseRenderer $response + * @param string $db Database name. + * @param string $table Table name. + * @param DatabaseInterface $dbi + */ + public function __construct($response, Template $template, $db, $table, $dbi, Indexes $indexes) + { + parent::__construct($response, $template, $db, $table); + $this->dbi = $dbi; + $this->indexes = $indexes; + } + + public function __invoke(): void + { + global $db, $table, $urlParams, $cfg, $errorUrl; + + if (! isset($_POST['create_edit_table'])) { + Util::checkParameters(['db', 'table']); + + $urlParams = ['db' => $db, 'table' => $table]; + $errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table'); + $errorUrl .= Url::getCommon($urlParams, '&'); + + DbTableExists::check(); + } + + if (isset($_POST['index'])) { + if (is_array($_POST['index'])) { + // coming already from form + $index = new Index($_POST['index']); + } else { + $index = $this->dbi->getTable($this->db, $this->table)->getIndex($_POST['index']); + } + } else { + $index = new Index(); + } + + if (isset($_POST['do_save_data'])) { + $this->indexes->doSaveData($index, true, $this->db, $this->table); + + return; + } + + $this->displayRenameForm($index); + } + + /** + * Display the rename form to rename an index + * + * @param Index $index An Index instance. + */ + private function displayRenameForm(Index $index): void + { + $this->dbi->selectDb($GLOBALS['db']); + + $formParams = [ + 'db' => $this->db, + 'table' => $this->table, + ]; + + if (isset($_POST['old_index'])) { + $formParams['old_index'] = $_POST['old_index']; + } elseif (isset($_POST['index'])) { + $formParams['old_index'] = $_POST['index']; + } + + $this->addScriptFiles(['indexes.js']); + + $this->render('table/index_rename_form', [ + 'index' => $index, + 'form_params' => $formParams, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/IndexesController.php b/libraries/classes/Controllers/Table/IndexesController.php index 47ae0e7d33..99f53df2db 100644 --- a/libraries/classes/Controllers/Table/IndexesController.php +++ b/libraries/classes/Controllers/Table/IndexesController.php @@ -41,7 +41,7 @@ class IndexesController extends AbstractController $this->indexes = $indexes; } - public function index(): void + public function __invoke(): void { global $db, $table, $urlParams, $cfg, $errorUrl; @@ -75,68 +75,6 @@ class IndexesController extends AbstractController $this->displayForm($index); } - public function indexRename(): void - { - global $db, $table, $urlParams, $cfg, $errorUrl; - - if (! isset($_POST['create_edit_table'])) { - Util::checkParameters(['db', 'table']); - - $urlParams = ['db' => $db, 'table' => $table]; - $errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table'); - $errorUrl .= Url::getCommon($urlParams, '&'); - - DbTableExists::check(); - } - - if (isset($_POST['index'])) { - if (is_array($_POST['index'])) { - // coming already from form - $index = new Index($_POST['index']); - } else { - $index = $this->dbi->getTable($this->db, $this->table)->getIndex($_POST['index']); - } - } else { - $index = new Index(); - } - - if (isset($_POST['do_save_data'])) { - $this->indexes->doSaveData($index, true, $this->db, $this->table); - - return; - } - - $this->displayRenameForm($index); - } - - /** - * Display the rename form to rename an index - * - * @param Index $index An Index instance. - */ - private function displayRenameForm(Index $index): void - { - $this->dbi->selectDb($GLOBALS['db']); - - $formParams = [ - 'db' => $this->db, - 'table' => $this->table, - ]; - - if (isset($_POST['old_index'])) { - $formParams['old_index'] = $_POST['old_index']; - } elseif (isset($_POST['index'])) { - $formParams['old_index'] = $_POST['index']; - } - - $this->addScriptFiles(['indexes.js']); - - $this->render('table/index_rename_form', [ - 'index' => $index, - 'form_params' => $formParams, - ]); - } - /** * Display the form to edit/create an index * diff --git a/libraries/classes/Controllers/Table/Maintenance/AnalyzeController.php b/libraries/classes/Controllers/Table/Maintenance/AnalyzeController.php new file mode 100644 index 0000000000..1b822035c7 --- /dev/null +++ b/libraries/classes/Controllers/Table/Maintenance/AnalyzeController.php @@ -0,0 +1,72 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Maintenance; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Table\Maintenance; +use PhpMyAdmin\Template; + +use function __; +use function count; +use function is_array; + +final class AnalyzeController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + */ + public function __construct( + $response, + Template $template, + $db, + $table, + Maintenance $model + ) { + parent::__construct($response, $template, $db, $table); + $this->model = $model; + } + + public function __invoke(): void + { + global $cfg; + + /** @var string[] $selected */ + $selected = $_POST['selected_tbl'] ?? []; + + if (empty($selected) || ! is_array($selected)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No table selected.')); + + return; + } + + if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); + + return; + } + + [$rows, $query] = $this->model->getAnalyzeTableRows($this->db, $selected); + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/maintenance/analyze', [ + 'message' => $message, + 'rows' => $rows, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Maintenance/CheckController.php b/libraries/classes/Controllers/Table/Maintenance/CheckController.php new file mode 100644 index 0000000000..4bed3f3b1d --- /dev/null +++ b/libraries/classes/Controllers/Table/Maintenance/CheckController.php @@ -0,0 +1,75 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Maintenance; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Table\Maintenance; +use PhpMyAdmin\Template; + +use function __; +use function count; +use function is_array; + +final class CheckController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + */ + public function __construct( + $response, + Template $template, + $db, + $table, + Maintenance $model + ) { + parent::__construct($response, $template, $db, $table); + $this->model = $model; + } + + public function __invoke(): void + { + global $cfg; + + /** @var string[] $selected */ + $selected = $_POST['selected_tbl'] ?? []; + + if (empty($selected) || ! is_array($selected)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No table selected.')); + + return; + } + + if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); + + return; + } + + [$rows, $query] = $this->model->getCheckTableRows($this->db, $selected); + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $indexesProblems = $this->model->getIndexesProblems($this->db, $selected); + + $this->render('table/maintenance/check', [ + 'message' => $message, + 'rows' => $rows, + 'indexes_problems' => $indexesProblems, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Maintenance/ChecksumController.php b/libraries/classes/Controllers/Table/Maintenance/ChecksumController.php new file mode 100644 index 0000000000..1568058ad2 --- /dev/null +++ b/libraries/classes/Controllers/Table/Maintenance/ChecksumController.php @@ -0,0 +1,73 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Maintenance; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Table\Maintenance; +use PhpMyAdmin\Template; + +use function __; +use function count; +use function is_array; + +final class ChecksumController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + */ + public function __construct( + $response, + Template $template, + $db, + $table, + Maintenance $model + ) { + parent::__construct($response, $template, $db, $table); + $this->model = $model; + } + + public function __invoke(): void + { + global $cfg; + + /** @var string[] $selected */ + $selected = $_POST['selected_tbl'] ?? []; + + if (empty($selected) || ! is_array($selected)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No table selected.')); + + return; + } + + if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); + + return; + } + + [$rows, $query, $warnings] = $this->model->getChecksumTableRows($this->db, $selected); + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/maintenance/checksum', [ + 'message' => $message, + 'rows' => $rows, + 'warnings' => $warnings, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Maintenance/OptimizeController.php b/libraries/classes/Controllers/Table/Maintenance/OptimizeController.php new file mode 100644 index 0000000000..c0c7249924 --- /dev/null +++ b/libraries/classes/Controllers/Table/Maintenance/OptimizeController.php @@ -0,0 +1,72 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Maintenance; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Table\Maintenance; +use PhpMyAdmin\Template; + +use function __; +use function count; +use function is_array; + +final class OptimizeController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + */ + public function __construct( + $response, + Template $template, + $db, + $table, + Maintenance $model + ) { + parent::__construct($response, $template, $db, $table); + $this->model = $model; + } + + public function __invoke(): void + { + global $cfg; + + /** @var string[] $selected */ + $selected = $_POST['selected_tbl'] ?? []; + + if (empty($selected) || ! is_array($selected)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No table selected.')); + + return; + } + + if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); + + return; + } + + [$rows, $query] = $this->model->getOptimizeTableRows($this->db, $selected); + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/maintenance/optimize', [ + 'message' => $message, + 'rows' => $rows, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Maintenance/RepairController.php b/libraries/classes/Controllers/Table/Maintenance/RepairController.php new file mode 100644 index 0000000000..0ea2144136 --- /dev/null +++ b/libraries/classes/Controllers/Table/Maintenance/RepairController.php @@ -0,0 +1,72 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Maintenance; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Table\Maintenance; +use PhpMyAdmin\Template; + +use function __; +use function count; +use function is_array; + +final class RepairController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + */ + public function __construct( + $response, + Template $template, + $db, + $table, + Maintenance $model + ) { + parent::__construct($response, $template, $db, $table); + $this->model = $model; + } + + public function __invoke(): void + { + global $cfg; + + /** @var string[] $selected */ + $selected = $_POST['selected_tbl'] ?? []; + + if (empty($selected) || ! is_array($selected)) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No table selected.')); + + return; + } + + if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); + + return; + } + + [$rows, $query] = $this->model->getRepairTableRows($this->db, $selected); + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/maintenance/repair', [ + 'message' => $message, + 'rows' => $rows, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/MaintenanceController.php b/libraries/classes/Controllers/Table/MaintenanceController.php deleted file mode 100644 index c77e1e1e52..0000000000 --- a/libraries/classes/Controllers/Table/MaintenanceController.php +++ /dev/null @@ -1,215 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace PhpMyAdmin\Controllers\Table; - -use PhpMyAdmin\Html\Generator; -use PhpMyAdmin\ResponseRenderer; -use PhpMyAdmin\Table\Maintenance; -use PhpMyAdmin\Template; - -use function __; -use function count; -use function is_array; - -final class MaintenanceController extends AbstractController -{ - /** @var Maintenance */ - private $model; - - /** - * @param ResponseRenderer $response - * @param string $db - * @param string $table - */ - public function __construct( - $response, - Template $template, - $db, - $table, - Maintenance $model - ) { - parent::__construct($response, $template, $db, $table); - $this->model = $model; - } - - public function analyze(): void - { - global $cfg; - - /** @var string[] $selected */ - $selected = $_POST['selected_tbl'] ?? []; - - if (empty($selected) || ! is_array($selected)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No table selected.')); - - return; - } - - if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); - - return; - } - - [$rows, $query] = $this->model->getAnalyzeTableRows($this->db, $selected); - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/maintenance/analyze', [ - 'message' => $message, - 'rows' => $rows, - ]); - } - - public function check(): void - { - global $cfg; - - /** @var string[] $selected */ - $selected = $_POST['selected_tbl'] ?? []; - - if (empty($selected) || ! is_array($selected)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No table selected.')); - - return; - } - - if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); - - return; - } - - [$rows, $query] = $this->model->getCheckTableRows($this->db, $selected); - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $indexesProblems = $this->model->getIndexesProblems($this->db, $selected); - - $this->render('table/maintenance/check', [ - 'message' => $message, - 'rows' => $rows, - 'indexes_problems' => $indexesProblems, - ]); - } - - public function checksum(): void - { - global $cfg; - - /** @var string[] $selected */ - $selected = $_POST['selected_tbl'] ?? []; - - if (empty($selected) || ! is_array($selected)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No table selected.')); - - return; - } - - if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); - - return; - } - - [$rows, $query, $warnings] = $this->model->getChecksumTableRows($this->db, $selected); - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/maintenance/checksum', [ - 'message' => $message, - 'rows' => $rows, - 'warnings' => $warnings, - ]); - } - - public function optimize(): void - { - global $cfg; - - /** @var string[] $selected */ - $selected = $_POST['selected_tbl'] ?? []; - - if (empty($selected) || ! is_array($selected)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No table selected.')); - - return; - } - - if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); - - return; - } - - [$rows, $query] = $this->model->getOptimizeTableRows($this->db, $selected); - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/maintenance/optimize', [ - 'message' => $message, - 'rows' => $rows, - ]); - } - - public function repair(): void - { - global $cfg; - - /** @var string[] $selected */ - $selected = $_POST['selected_tbl'] ?? []; - - if (empty($selected) || ! is_array($selected)) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('No table selected.')); - - return; - } - - if ($cfg['DisableMultiTableMaintenance'] && count($selected) > 1) { - $this->response->setRequestStatus(false); - $this->response->addJSON('message', __('Maintenance operations on multiple tables are disabled.')); - - return; - } - - [$rows, $query] = $this->model->getRepairTableRows($this->db, $selected); - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/maintenance/repair', [ - 'message' => $message, - 'rows' => $rows, - ]); - } -} diff --git a/libraries/classes/Controllers/Table/Partition/AnalyzeController.php b/libraries/classes/Controllers/Table/Partition/AnalyzeController.php new file mode 100644 index 0000000000..e769c6672a --- /dev/null +++ b/libraries/classes/Controllers/Table/Partition/AnalyzeController.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Dbal\DatabaseName; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use Throwable; + +use function __; +use function strlen; + +final class AnalyzeController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + * @param Maintenance $maintenance + */ + public function __construct($response, Template $template, $db, $table, $maintenance) + { + parent::__construct($response, $template, $db, $table); + $this->model = $maintenance; + } + + public function __invoke(): void + { + $partitionName = $_POST['partition_name'] ?? ''; + + if (strlen($partitionName) === 0) { + return; + } + + try { + [$rows, $query] = $this->model->analyze(new DatabaseName($this->db), $this->table, $partitionName); + } catch (Throwable $e) { + $message = Message::error($e->getMessage()); + $this->response->addHTML($message->getDisplay()); + + return; + } + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/partition/analyze', [ + 'partition_name' => $partitionName, + 'message' => $message, + 'rows' => $rows, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Partition/CheckController.php b/libraries/classes/Controllers/Table/Partition/CheckController.php new file mode 100644 index 0000000000..8c877abf5a --- /dev/null +++ b/libraries/classes/Controllers/Table/Partition/CheckController.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Dbal\DatabaseName; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use Throwable; + +use function __; +use function strlen; + +final class CheckController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + * @param Maintenance $maintenance + */ + public function __construct($response, Template $template, $db, $table, $maintenance) + { + parent::__construct($response, $template, $db, $table); + $this->model = $maintenance; + } + + public function __invoke(): void + { + $partitionName = $_POST['partition_name'] ?? ''; + + if (strlen($partitionName) === 0) { + return; + } + + try { + [$rows, $query] = $this->model->check(new DatabaseName($this->db), $this->table, $partitionName); + } catch (Throwable $e) { + $message = Message::error($e->getMessage()); + $this->response->addHTML($message->getDisplay()); + + return; + } + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/partition/check', [ + 'partition_name' => $partitionName, + 'message' => $message, + 'rows' => $rows, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Partition/DropController.php b/libraries/classes/Controllers/Table/Partition/DropController.php new file mode 100644 index 0000000000..a01e89f4a5 --- /dev/null +++ b/libraries/classes/Controllers/Table/Partition/DropController.php @@ -0,0 +1,72 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Dbal\DatabaseName; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use Throwable; + +use function __; +use function strlen; + +final class DropController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + * @param Maintenance $maintenance + */ + public function __construct($response, Template $template, $db, $table, $maintenance) + { + parent::__construct($response, $template, $db, $table); + $this->model = $maintenance; + } + + public function __invoke(): void + { + $partitionName = $_POST['partition_name'] ?? ''; + + if (strlen($partitionName) === 0) { + return; + } + + try { + [$result, $query] = $this->model->drop(new DatabaseName($this->db), $this->table, $partitionName); + } catch (Throwable $e) { + $message = Message::error($e->getMessage()); + $this->response->addHTML($message->getDisplay()); + + return; + } + + if ($result) { + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + } else { + $message = Generator::getMessage( + __('Error'), + $query, + 'error' + ); + } + + $this->render('table/partition/drop', [ + 'partition_name' => $partitionName, + 'message' => $message, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Partition/OptimizeController.php b/libraries/classes/Controllers/Table/Partition/OptimizeController.php new file mode 100644 index 0000000000..2815c33bbe --- /dev/null +++ b/libraries/classes/Controllers/Table/Partition/OptimizeController.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Dbal\DatabaseName; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use Throwable; + +use function __; +use function strlen; + +final class OptimizeController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + * @param Maintenance $maintenance + */ + public function __construct($response, Template $template, $db, $table, $maintenance) + { + parent::__construct($response, $template, $db, $table); + $this->model = $maintenance; + } + + public function __invoke(): void + { + $partitionName = $_POST['partition_name'] ?? ''; + + if (strlen($partitionName) === 0) { + return; + } + + try { + [$rows, $query] = $this->model->optimize(new DatabaseName($this->db), $this->table, $partitionName); + } catch (Throwable $e) { + $message = Message::error($e->getMessage()); + $this->response->addHTML($message->getDisplay()); + + return; + } + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/partition/optimize', [ + 'partition_name' => $partitionName, + 'message' => $message, + 'rows' => $rows, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Partition/RebuildController.php b/libraries/classes/Controllers/Table/Partition/RebuildController.php new file mode 100644 index 0000000000..4236a8ad78 --- /dev/null +++ b/libraries/classes/Controllers/Table/Partition/RebuildController.php @@ -0,0 +1,72 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Dbal\DatabaseName; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use Throwable; + +use function __; +use function strlen; + +final class RebuildController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + * @param Maintenance $maintenance + */ + public function __construct($response, Template $template, $db, $table, $maintenance) + { + parent::__construct($response, $template, $db, $table); + $this->model = $maintenance; + } + + public function __invoke(): void + { + $partitionName = $_POST['partition_name'] ?? ''; + + if (strlen($partitionName) === 0) { + return; + } + + try { + [$result, $query] = $this->model->rebuild(new DatabaseName($this->db), $this->table, $partitionName); + } catch (Throwable $e) { + $message = Message::error($e->getMessage()); + $this->response->addHTML($message->getDisplay()); + + return; + } + + if ($result) { + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + } else { + $message = Generator::getMessage( + __('Error'), + $query, + 'error' + ); + } + + $this->render('table/partition/rebuild', [ + 'partition_name' => $partitionName, + 'message' => $message, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Partition/RepairController.php b/libraries/classes/Controllers/Table/Partition/RepairController.php new file mode 100644 index 0000000000..4d488efc74 --- /dev/null +++ b/libraries/classes/Controllers/Table/Partition/RepairController.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Dbal\DatabaseName; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use Throwable; + +use function __; +use function strlen; + +final class RepairController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + * @param Maintenance $maintenance + */ + public function __construct($response, Template $template, $db, $table, $maintenance) + { + parent::__construct($response, $template, $db, $table); + $this->model = $maintenance; + } + + public function __invoke(): void + { + $partitionName = $_POST['partition_name'] ?? ''; + + if (strlen($partitionName) === 0) { + return; + } + + try { + [$rows, $query] = $this->model->repair(new DatabaseName($this->db), $this->table, $partitionName); + } catch (Throwable $e) { + $message = Message::error($e->getMessage()); + $this->response->addHTML($message->getDisplay()); + + return; + } + + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + + $this->render('table/partition/repair', [ + 'partition_name' => $partitionName, + 'message' => $message, + 'rows' => $rows, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/Partition/TruncateController.php b/libraries/classes/Controllers/Table/Partition/TruncateController.php new file mode 100644 index 0000000000..26464128e6 --- /dev/null +++ b/libraries/classes/Controllers/Table/Partition/TruncateController.php @@ -0,0 +1,72 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Table\Partition; + +use PhpMyAdmin\Controllers\Table\AbstractController; +use PhpMyAdmin\Dbal\DatabaseName; +use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; +use PhpMyAdmin\Partitioning\Maintenance; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; +use Throwable; + +use function __; +use function strlen; + +final class TruncateController extends AbstractController +{ + /** @var Maintenance */ + private $model; + + /** + * @param ResponseRenderer $response + * @param string $db + * @param string $table + * @param Maintenance $maintenance + */ + public function __construct($response, Template $template, $db, $table, $maintenance) + { + parent::__construct($response, $template, $db, $table); + $this->model = $maintenance; + } + + public function __invoke(): void + { + $partitionName = $_POST['partition_name'] ?? ''; + + if (strlen($partitionName) === 0) { + return; + } + + try { + [$result, $query] = $this->model->truncate(new DatabaseName($this->db), $this->table, $partitionName); + } catch (Throwable $e) { + $message = Message::error($e->getMessage()); + $this->response->addHTML($message->getDisplay()); + + return; + } + + if ($result) { + $message = Generator::getMessage( + __('Your SQL query has been executed successfully.'), + $query, + 'success' + ); + } else { + $message = Generator::getMessage( + __('Error'), + $query, + 'error' + ); + } + + $this->render('table/partition/truncate', [ + 'partition_name' => $partitionName, + 'message' => $message, + ]); + } +} diff --git a/libraries/classes/Controllers/Table/PartitionController.php b/libraries/classes/Controllers/Table/PartitionController.php deleted file mode 100644 index 74e67deecc..0000000000 --- a/libraries/classes/Controllers/Table/PartitionController.php +++ /dev/null @@ -1,265 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace PhpMyAdmin\Controllers\Table; - -use PhpMyAdmin\Dbal\DatabaseName; -use PhpMyAdmin\Html\Generator; -use PhpMyAdmin\Message; -use PhpMyAdmin\Partitioning\Maintenance; -use PhpMyAdmin\ResponseRenderer; -use PhpMyAdmin\Template; -use Throwable; - -use function __; -use function strlen; - -final class PartitionController extends AbstractController -{ - /** @var Maintenance */ - private $model; - - /** - * @param ResponseRenderer $response - * @param string $db - * @param string $table - * @param Maintenance $maintenance - */ - public function __construct($response, Template $template, $db, $table, $maintenance) - { - parent::__construct($response, $template, $db, $table); - $this->model = $maintenance; - } - - public function analyze(): void - { - $partitionName = $_POST['partition_name'] ?? ''; - - if (strlen($partitionName) === 0) { - return; - } - - try { - [$rows, $query] = $this->model->analyze(new DatabaseName($this->db), $this->table, $partitionName); - } catch (Throwable $e) { - $message = Message::error($e->getMessage()); - $this->response->addHTML($message->getDisplay()); - - return; - } - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/partition/analyze', [ - 'partition_name' => $partitionName, - 'message' => $message, - 'rows' => $rows, - ]); - } - - public function check(): void - { - $partitionName = $_POST['partition_name'] ?? ''; - - if (strlen($partitionName) === 0) { - return; - } - - try { - [$rows, $query] = $this->model->check(new DatabaseName($this->db), $this->table, $partitionName); - } catch (Throwable $e) { - $message = Message::error($e->getMessage()); - $this->response->addHTML($message->getDisplay()); - - return; - } - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/partition/check', [ - 'partition_name' => $partitionName, - 'message' => $message, - 'rows' => $rows, - ]); - } - - public function drop(): void - { - $partitionName = $_POST['partition_name'] ?? ''; - - if (strlen($partitionName) === 0) { - return; - } - - try { - [$result, $query] = $this->model->drop(new DatabaseName($this->db), $this->table, $partitionName); - } catch (Throwable $e) { - $message = Message::error($e->getMessage()); - $this->response->addHTML($message->getDisplay()); - - return; - } - - if ($result) { - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - } else { - $message = Generator::getMessage( - __('Error'), - $query, - 'error' - ); - } - - $this->render('table/partition/drop', [ - 'partition_name' => $partitionName, - 'message' => $message, - ]); - } - - public function optimize(): void - { - $partitionName = $_POST['partition_name'] ?? ''; - - if (strlen($partitionName) === 0) { - return; - } - - try { - [$rows, $query] = $this->model->optimize(new DatabaseName($this->db), $this->table, $partitionName); - } catch (Throwable $e) { - $message = Message::error($e->getMessage()); - $this->response->addHTML($message->getDisplay()); - - return; - } - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/partition/optimize', [ - 'partition_name' => $partitionName, - 'message' => $message, - 'rows' => $rows, - ]); - } - - public function rebuild(): void - { - $partitionName = $_POST['partition_name'] ?? ''; - - if (strlen($partitionName) === 0) { - return; - } - - try { - [$result, $query] = $this->model->rebuild(new DatabaseName($this->db), $this->table, $partitionName); - } catch (Throwable $e) { - $message = Message::error($e->getMessage()); - $this->response->addHTML($message->getDisplay()); - - return; - } - - if ($result) { - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - } else { - $message = Generator::getMessage( - __('Error'), - $query, - 'error' - ); - } - - $this->render('table/partition/rebuild', [ - 'partition_name' => $partitionName, - 'message' => $message, - ]); - } - - public function repair(): void - { - $partitionName = $_POST['partition_name'] ?? ''; - - if (strlen($partitionName) === 0) { - return; - } - - try { - [$rows, $query] = $this->model->repair(new DatabaseName($this->db), $this->table, $partitionName); - } catch (Throwable $e) { - $message = Message::error($e->getMessage()); - $this->response->addHTML($message->getDisplay()); - - return; - } - - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - - $this->render('table/partition/repair', [ - 'partition_name' => $partitionName, - 'message' => $message, - 'rows' => $rows, - ]); - } - - public function truncate(): void - { - $partitionName = $_POST['partition_name'] ?? ''; - - if (strlen($partitionName) === 0) { - return; - } - - try { - [$result, $query] = $this->model->truncate(new DatabaseName($this->db), $this->table, $partitionName); - } catch (Throwable $e) { - $message = Message::error($e->getMessage()); - $this->response->addHTML($message->getDisplay()); - - return; - } - - if ($result) { - $message = Generator::getMessage( - __('Your SQL query has been executed successfully.'), - $query, - 'success' - ); - } else { - $message = Generator::getMessage( - __('Error'), - $query, - 'error' - ); - } - - $this->render('table/partition/truncate', [ - 'partition_name' => $partitionName, - 'message' => $message, - ]); - } -} diff --git a/libraries/classes/Controllers/Table/RecentFavoriteController.php b/libraries/classes/Controllers/Table/RecentFavoriteController.php index 71b1e3188f..68d80345e5 100644 --- a/libraries/classes/Controllers/Table/RecentFavoriteController.php +++ b/libraries/classes/Controllers/Table/RecentFavoriteController.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; -use PhpMyAdmin\Controllers\SqlController; +use PhpMyAdmin\Controllers\Sql\SqlController; use PhpMyAdmin\RecentFavoriteTable; /** @@ -28,6 +28,6 @@ class RecentFavoriteController extends AbstractController /** @var SqlController $controller */ $controller = $containerBuilder->get(SqlController::class); - $controller->index(); + $controller(); } } diff --git a/libraries/classes/Controllers/Table/ReplaceController.php b/libraries/classes/Controllers/Table/ReplaceController.php index f8fc83ee1e..492936c0e5 100644 --- a/libraries/classes/Controllers/Table/ReplaceController.php +++ b/libraries/classes/Controllers/Table/ReplaceController.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; use PhpMyAdmin\Controllers\Database\SqlController as DatabaseSqlController; -use PhpMyAdmin\Controllers\SqlController; +use PhpMyAdmin\Controllers\Sql\SqlController; use PhpMyAdmin\Controllers\Table\SqlController as TableSqlController; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; @@ -109,7 +109,7 @@ final class ReplaceController extends AbstractController $GLOBALS['cfg']['InsertRows'] = $_POST['insert_rows']; /** @var ChangeController $controller */ $controller = $containerBuilder->get(ChangeController::class); - $controller->index(); + $controller(); return; } @@ -438,7 +438,7 @@ final class ReplaceController extends AbstractController if ($goto_include === '/sql') { /** @var SqlController $controller */ $controller = $containerBuilder->get(SqlController::class); - $controller->index(); + $controller(); return; } @@ -454,7 +454,7 @@ final class ReplaceController extends AbstractController if ($goto_include === '/table/change') { /** @var ChangeController $controller */ $controller = $containerBuilder->get(ChangeController::class); - $controller->index(); + $controller(); return; } @@ -656,7 +656,7 @@ final class ReplaceController extends AbstractController if ($goto_include === '/sql') { /** @var SqlController $controller */ $controller = $containerBuilder->get(SqlController::class); - $controller->index(); + $controller(); return; } @@ -672,7 +672,7 @@ final class ReplaceController extends AbstractController if ($goto_include === '/table/change') { /** @var ChangeController $controller */ $controller = $containerBuilder->get(ChangeController::class); - $controller->index(); + $controller(); return; } diff --git a/libraries/classes/Controllers/Table/Structure/AddKeyController.php b/libraries/classes/Controllers/Table/Structure/AddKeyController.php index a9304e4b4f..933dd5163b 100644 --- a/libraries/classes/Controllers/Table/Structure/AddKeyController.php +++ b/libraries/classes/Controllers/Table/Structure/AddKeyController.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table\Structure; -use PhpMyAdmin\Controllers\SqlController; +use PhpMyAdmin\Controllers\Sql\SqlController; use PhpMyAdmin\Controllers\Table\AbstractController; use PhpMyAdmin\Controllers\Table\StructureController; use PhpMyAdmin\ResponseRenderer; @@ -40,7 +40,7 @@ final class AddKeyController extends AbstractController { global $reload; - $this->sqlController->index(); + ($this->sqlController)(); $reload = true; diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index a417e0cba9..a6bc7811ec 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -1251,7 +1251,7 @@ class Export $active_page = Url::getFromRoute('/table/export'); /** @var TableExportController $controller */ $controller = $containerBuilder->get(TableExportController::class); - $controller->index(); + $controller(); } /** diff --git a/libraries/classes/Routing.php b/libraries/classes/Routing.php index 18a5b51f8a..64aa58d7d7 100644 --- a/libraries/classes/Routing.php +++ b/libraries/classes/Routing.php @@ -9,7 +9,6 @@ use FastRoute\Dispatcher; use FastRoute\Dispatcher\GroupCountBased as DispatcherGroupCountBased; use FastRoute\RouteCollector; use FastRoute\RouteParser\Std as RouteParserStd; -use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Http\ServerRequest; use Psr\Container\ContainerInterface; use RuntimeException; @@ -20,7 +19,6 @@ use function file_put_contents; use function htmlspecialchars; use function is_array; use function is_readable; -use function is_string; use function is_writable; use function mb_strlen; use function rawurldecode; @@ -177,26 +175,13 @@ class Routing return; } - /** @psalm-var class-string|callable-array $handler */ - $handler = $routeInfo[1]; + /** @psalm-var class-string $controllerName */ + $controllerName = $routeInfo[1]; /** @var array<string, string> $vars */ $vars = $routeInfo[2]; - if (is_string($handler)) { - $controllerName = $handler; - /** @psalm-var callable(ServerRequest=, array=):void $controller */ - $controller = $container->get($controllerName); - $controller($request, $vars); - - return; - } - - /** @psalm-var class-string $controllerName */ - $controllerName = $handler[0]; - /** @var string $action */ - $action = $handler[1]; - /** @var AbstractController $controller */ + /** @psalm-var callable(ServerRequest=, array=):void $controller */ $controller = $container->get($controllerName); - $controller->$action($request, $vars); + $controller($request, $vars); } } diff --git a/libraries/routes.php b/libraries/routes.php index 331b76769c..593021508a 100644 --- a/libraries/routes.php +++ b/libraries/routes.php @@ -28,7 +28,7 @@ use PhpMyAdmin\Controllers\Preferences; use PhpMyAdmin\Controllers\RecentTablesListController; use PhpMyAdmin\Controllers\SchemaExportController; use PhpMyAdmin\Controllers\Server; -use PhpMyAdmin\Controllers\SqlController; +use PhpMyAdmin\Controllers\Sql; use PhpMyAdmin\Controllers\Table; use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\Controllers\ThemesController; @@ -192,50 +192,50 @@ return static function (RouteCollector $routes): void { }); }); $routes->addGroup('/sql', static function (RouteCollector $routes): void { - $routes->addRoute(['GET', 'POST'], '', [SqlController::class, 'index']); - $routes->post('/get-relational-values', [SqlController::class, 'getRelationalValues']); - $routes->post('/get-enum-values', [SqlController::class, 'getEnumValues']); - $routes->post('/get-set-values', [SqlController::class, 'getSetValues']); - $routes->get('/get-default-fk-check-value', [SqlController::class, 'getDefaultForeignKeyCheckValue']); - $routes->post('/set-column-preferences', [SqlController::class, 'setColumnOrderOrVisibility']); + $routes->addRoute(['GET', 'POST'], '', Sql\SqlController::class); + $routes->post('/get-relational-values', Sql\RelationalValuesController::class); + $routes->post('/get-enum-values', Sql\EnumValuesController::class); + $routes->post('/get-set-values', Sql\SetValuesController::class); + $routes->get('/get-default-fk-check-value', Sql\DefaultForeignKeyCheckValueController::class); + $routes->post('/set-column-preferences', Sql\ColumnPreferencesController::class); }); $routes->addGroup('/table', static function (RouteCollector $routes): void { $routes->addRoute(['GET', 'POST'], '/add-field', Table\AddFieldController::class); $routes->addGroup('/change', static function (RouteCollector $routes): void { - $routes->addRoute(['GET', 'POST'], '', [Table\ChangeController::class, 'index']); - $routes->post('/rows', [Table\ChangeController::class, 'rows']); + $routes->addRoute(['GET', 'POST'], '', Table\ChangeController::class); + $routes->post('/rows', Table\ChangeRowsController::class); }); $routes->addRoute(['GET', 'POST'], '/chart', Table\ChartController::class); $routes->addRoute(['GET', 'POST'], '/create', Table\CreateController::class); $routes->addGroup('/delete', static function (RouteCollector $routes): void { - $routes->post('/confirm', [Table\DeleteController::class, 'confirm']); - $routes->post('/rows', [Table\DeleteController::class, 'rows']); + $routes->post('/confirm', Table\DeleteConfirmController::class); + $routes->post('/rows', Table\DeleteRowsController::class); }); $routes->addGroup('/export', static function (RouteCollector $routes): void { - $routes->addRoute(['GET', 'POST'], '', [Table\ExportController::class, 'index']); - $routes->post('/rows', [Table\ExportController::class, 'rows']); + $routes->addRoute(['GET', 'POST'], '', Table\ExportController::class); + $routes->post('/rows', Table\ExportRowsController::class); }); $routes->addRoute(['GET', 'POST'], '/find-replace', Table\FindReplaceController::class); $routes->addRoute(['GET', 'POST'], '/get-field', Table\GetFieldController::class); $routes->addRoute(['GET', 'POST'], '/gis-visualization', Table\GisVisualizationController::class); $routes->addRoute(['GET', 'POST'], '/import', Table\ImportController::class); - $routes->addRoute(['GET', 'POST'], '/indexes', [Table\IndexesController::class, 'index']); - $routes->addRoute(['GET', 'POST'], '/indexes/rename', [Table\IndexesController::class, 'indexRename']); + $routes->addRoute(['GET', 'POST'], '/indexes', Table\IndexesController::class); + $routes->addRoute(['GET', 'POST'], '/indexes/rename', Table\IndexRenameController::class); $routes->addGroup('/maintenance', static function (RouteCollector $routes): void { - $routes->post('/analyze', [Table\MaintenanceController::class, 'analyze']); - $routes->post('/check', [Table\MaintenanceController::class, 'check']); - $routes->post('/checksum', [Table\MaintenanceController::class, 'checksum']); - $routes->post('/optimize', [Table\MaintenanceController::class, 'optimize']); - $routes->post('/repair', [Table\MaintenanceController::class, 'repair']); + $routes->post('/analyze', Table\Maintenance\AnalyzeController::class); + $routes->post('/check', Table\Maintenance\CheckController::class); + $routes->post('/checksum', Table\Maintenance\ChecksumController::class); + $routes->post('/optimize', Table\Maintenance\OptimizeController::class); + $routes->post('/repair', Table\Maintenance\RepairController::class); }); $routes->addGroup('/partition', static function (RouteCollector $routes): void { - $routes->post('/analyze', [Table\PartitionController::class, 'analyze']); - $routes->post('/check', [Table\PartitionController::class, 'check']); - $routes->post('/drop', [Table\PartitionController::class, 'drop']); - $routes->post('/optimize', [Table\PartitionController::class, 'optimize']); - $routes->post('/rebuild', [Table\PartitionController::class, 'rebuild']); - $routes->post('/repair', [Table\PartitionController::class, 'repair']); - $routes->post('/truncate', [Table\PartitionController::class, 'truncate']); + $routes->post('/analyze', Table\Partition\AnalyzeController::class); + $routes->post('/check', Table\Partition\CheckController::class); + $routes->post('/drop', Table\Partition\DropController::class); + $routes->post('/optimize', Table\Partition\OptimizeController::class); + $routes->post('/rebuild', Table\Partition\RebuildController::class); + $routes->post('/repair', Table\Partition\RepairController::class); + $routes->post('/truncate', Table\Partition\TruncateController::class); }); $routes->addRoute(['GET', 'POST'], '/operations', Table\OperationsController::class); $routes->addRoute(['GET', 'POST'], '/recent-favorite', Table\RecentFavoriteController::class); diff --git a/libraries/services_controllers.php b/libraries/services_controllers.php index 2bfadb3fda..56db96bbf4 100644 --- a/libraries/services_controllers.php +++ b/libraries/services_controllers.php @@ -28,7 +28,7 @@ use PhpMyAdmin\Controllers\Preferences; use PhpMyAdmin\Controllers\RecentTablesListController; use PhpMyAdmin\Controllers\SchemaExportController; use PhpMyAdmin\Controllers\Server; -use PhpMyAdmin\Controllers\SqlController; +use PhpMyAdmin\Controllers\Sql; use PhpMyAdmin\Controllers\Table; use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\Controllers\ThemesController; @@ -1018,8 +1018,53 @@ return [ '$dbi' => '@dbi', ], ], - SqlController::class => [ - 'class' => SqlController::class, + Sql\ColumnPreferencesController::class => [ + 'class' => Sql\ColumnPreferencesController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$sql' => '@sql', + '$checkUserPrivileges' => '@check_user_privileges', + '$dbi' => '@dbi', + ], + ], + Sql\DefaultForeignKeyCheckValueController::class => [ + 'class' => Sql\DefaultForeignKeyCheckValueController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$checkUserPrivileges' => '@check_user_privileges', + ], + ], + Sql\EnumValuesController::class => [ + 'class' => Sql\EnumValuesController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$sql' => '@sql', + '$checkUserPrivileges' => '@check_user_privileges', + ], + ], + Sql\RelationalValuesController::class => [ + 'class' => Sql\RelationalValuesController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$sql' => '@sql', + '$checkUserPrivileges' => '@check_user_privileges', + ], + ], + Sql\SetValuesController::class => [ + 'class' => Sql\SetValuesController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$sql' => '@sql', + '$checkUserPrivileges' => '@check_user_privileges', + ], + ], + Sql\SqlController::class => [ + 'class' => Sql\SqlController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', @@ -1052,6 +1097,16 @@ return [ '$relation' => '@relation', ], ], + Table\ChangeRowsController::class => [ + 'class' => Table\ChangeRowsController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$changeController' => '@' . Table\ChangeController::class, + ], + ], Table\ChartController::class => [ 'class' => Table\ChartController::class, 'arguments' => [ @@ -1075,8 +1130,17 @@ return [ '$dbi' => '@dbi', ], ], - Table\DeleteController::class => [ - 'class' => Table\DeleteController::class, + Table\DeleteConfirmController::class => [ + 'class' => Table\DeleteConfirmController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + ], + ], + Table\DeleteRowsController::class => [ + 'class' => Table\DeleteRowsController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', @@ -1116,6 +1180,16 @@ return [ '$export' => '@export_options', ], ], + Table\ExportRowsController::class => [ + 'class' => Table\ExportRowsController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$exportController' => '@' . Table\ExportController::class, + ], + ], Table\FindReplaceController::class => [ 'class' => Table\FindReplaceController::class, 'arguments' => [ @@ -1167,8 +1241,29 @@ return [ '$indexes' => '@table_indexes', ], ], - Table\MaintenanceController::class => [ - 'class' => Table\MaintenanceController::class, + Table\IndexRenameController::class => [ + 'class' => Table\IndexRenameController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$dbi' => '@dbi', + '$indexes' => '@table_indexes', + ], + ], + Table\Maintenance\AnalyzeController::class => [ + 'class' => Table\Maintenance\AnalyzeController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$model' => '@table_maintenance', + ], + ], + Table\Maintenance\CheckController::class => [ + 'class' => Table\Maintenance\CheckController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', @@ -1177,8 +1272,98 @@ return [ '$model' => '@table_maintenance', ], ], - Table\PartitionController::class => [ - 'class' => Table\PartitionController::class, + Table\Maintenance\ChecksumController::class => [ + 'class' => Table\Maintenance\ChecksumController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$model' => '@table_maintenance', + ], + ], + Table\Maintenance\OptimizeController::class => [ + 'class' => Table\Maintenance\OptimizeController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$model' => '@table_maintenance', + ], + ], + Table\Maintenance\RepairController::class => [ + 'class' => Table\Maintenance\RepairController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$model' => '@table_maintenance', + ], + ], + Table\Partition\AnalyzeController::class => [ + 'class' => Table\Partition\AnalyzeController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$maintenance' => '@partitioning_maintenance', + ], + ], + Table\Partition\CheckController::class => [ + 'class' => Table\Partition\CheckController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$maintenance' => '@partitioning_maintenance', + ], + ], + Table\Partition\DropController::class => [ + 'class' => Table\Partition\DropController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$maintenance' => '@partitioning_maintenance', + ], + ], + Table\Partition\OptimizeController::class => [ + 'class' => Table\Partition\OptimizeController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$maintenance' => '@partitioning_maintenance', + ], + ], + Table\Partition\RebuildController::class => [ + 'class' => Table\Partition\RebuildController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$maintenance' => '@partitioning_maintenance', + ], + ], + Table\Partition\RepairController::class => [ + 'class' => Table\Partition\RepairController::class, + 'arguments' => [ + '$response' => '@response', + '$template' => '@template', + '$db' => '%db%', + '$table' => '%table%', + '$maintenance' => '@partitioning_maintenance', + ], + ], + Table\Partition\TruncateController::class => [ + 'class' => Table\Partition\TruncateController::class, 'arguments' => [ '$response' => '@response', '$template' => '@template', @@ -1284,7 +1469,7 @@ return [ '$template' => '@template', '$db' => '%db%', '$table' => '%table%', - '$sqlController' => '@' . SqlController::class, + '$sqlController' => '@' . Sql\SqlController::class, '$structureController' => '@' . Table\StructureController::class, ], ], |