Skip to content

Commit

Permalink
Move Operations::getMaintenanceActions to the view
Browse files Browse the repository at this point in the history
Uses Table\MaintenanceController to handle the maintenance actions in
the table operations page.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Aug 28, 2020
1 parent 3b02872 commit 7936909
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 166 deletions.
Expand Up @@ -112,7 +112,6 @@ public function index(): void
null, // sql_query_for_bookmark
null, // extra_data
null, // message_to_show
null, // message
null, // sql_data
$goto, // goto
$pmaThemeImage, // pmaThemeImage
Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Controllers/ImportController.php
Expand Up @@ -806,7 +806,6 @@ public function index(): void
null, // sql_query_for_bookmark - see below
null, // extra_data
null, // message_to_show
null, // message
null, // sql_data
$goto, // goto
$pmaThemeImage, // pmaThemeImage
Expand Down
3 changes: 1 addition & 2 deletions libraries/classes/Controllers/SqlController.php
Expand Up @@ -53,7 +53,7 @@ public function __construct(

public function index(): void
{
global $cfg, $db, $display_query, $pmaThemeImage, $sql_query, $table, $message;
global $cfg, $db, $display_query, $pmaThemeImage, $sql_query, $table;
global $ajax_reload, $goto, $err_url, $find_real_end, $unlim_num_rows, $import_text, $disp_query;
global $extra_data, $message_to_show, $sql_data, $disp_message, $complete_query;
global $is_gotofile, $back, $table_from_sql;
Expand Down Expand Up @@ -209,7 +209,6 @@ public function index(): void
$import_text ?? null,
$extra_data ?? null,
$message_to_show ?? null,
$message ?? null,
$sql_data ?? null,
$goto,
$pmaThemeImage,
Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Controllers/Table/DeleteController.php
Expand Up @@ -73,7 +73,6 @@ public function rows(): void
null,
null,
null,
null,
$goto,
$pmaThemeImage,
null,
Expand Down
19 changes: 2 additions & 17 deletions libraries/classes/Controllers/Table/OperationsController.php
Expand Up @@ -7,7 +7,6 @@
use PhpMyAdmin\Charsets;
use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\SqlController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Index;
Expand Down Expand Up @@ -67,12 +66,11 @@ public function __construct(

public function index(): void
{
global $containerBuilder, $url_query, $url_params, $reread_info, $tbl_is_view, $tbl_storage_engine;
global $url_query, $url_params, $reread_info, $tbl_is_view, $tbl_storage_engine;
global $show_comment, $tbl_collation, $table_info_num_rows, $row_format, $auto_increment, $create_options;
global $table_alters, $warning_messages, $lowerCaseNames, $db, $table, $reload, $result;
global $new_tbl_storage_engine, $sql_query, $message_to_show, $columns, $hideOrderTable, $indexes;
global $notNull, $comment, $db_is_system_schema, $truncate_table_url_params, $drop_table_url_params;
global $this_sql_query;
global $notNull, $comment, $db_is_system_schema;

$this->checkUserPrivileges->getPrivileges();

Expand Down Expand Up @@ -163,16 +161,6 @@ public function index(): void
return;
}

/**
* If the table has to be maintained
*/
if (isset($_POST['table_maintenance'])) {
/** @var SqlController $controller */
$controller = $containerBuilder->get(SqlController::class);
$controller->index();

unset($result);
}
/**
* Updates table comment, type and options if required
*/
Expand Down Expand Up @@ -449,8 +437,6 @@ public function index(): void
$hasPrivileges = $GLOBALS['table_priv'] && $GLOBALS['col_priv'] && $GLOBALS['is_reload_priv'];
$switchToNew = isset($_SESSION['pma_switch_to_new']) && $_SESSION['pma_switch_to_new'];

$maintenanceActions = $this->operations->getMaintenanceActions($pma_table);

$partitions = [];
$partitionsChoices = [];

Expand Down Expand Up @@ -495,7 +481,6 @@ public function index(): void
'has_foreign_keys' => $hasForeignKeys,
'has_privileges' => $hasPrivileges,
'switch_to_new' => $switchToNew,
'maintenance_actions' => $maintenanceActions,
'is_system_schema' => isset($db_is_system_schema) && $db_is_system_schema,
'is_view' => $tbl_is_view,
'partitions' => $partitions,
Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Controllers/Table/SearchController.php
Expand Up @@ -268,7 +268,6 @@ public function doSelectionAction()
null, // sql_query_for_bookmark
null, // extra_data
null, // message_to_show
null, // message
null, // sql_data
$GLOBALS['goto'], // goto
$GLOBALS['pmaThemeImage'], // pmaThemeImage
Expand Down
Expand Up @@ -1068,7 +1068,6 @@ protected function displayTableBrowseForSelectedColumns($goto, $pmaThemeImage)
null, // sql_query_for_bookmark
null, // extra_data
null, // message_to_show
null, // message
null, // sql_data
$goto, // goto
$pmaThemeImage, // pmaThemeImage
Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Database/MultiTableQuery.php
Expand Up @@ -121,7 +121,6 @@ public static function displayResults($sqlQuery, $db, $pmaThemeImage): string
null, // sql_query_for_bookmark - see below
null, // extra_data
null, // message_to_show
null, // message
null, // sql_data
$goto, // goto
$pmaThemeImage, // pmaThemeImage
Expand Down
92 changes: 0 additions & 92 deletions libraries/classes/Operations.php
Expand Up @@ -12,10 +12,8 @@
use function array_merge;
use function count;
use function explode;
use function htmlspecialchars;
use function implode;
use function mb_strtolower;
use function sprintf;
use function str_replace;
use function strlen;
use function strtolower;
Expand Down Expand Up @@ -595,96 +593,6 @@ public function getPossibleRowFormat()
return $possible_row_formats;
}

/**
* @param Table $tableObject Table object
*
* @return array
*/
public function getMaintenanceActions(Table $tableObject): array
{
global $table;

$actions = [];

if ($tableObject->isEngine(['MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB', 'TOKUDB'])) {
$actions[] = [
'params' => [
'sql_query' => 'ANALYZE TABLE ' . Util::backquote($table),
'table_maintenance' => 'Go',
],
'message' => __('Analyze table'),
'link' => 'ANALYZE_TABLE',
];
}

if ($tableObject->isEngine(['MYISAM', 'ARIA', 'INNODB', 'TOKUDB'])) {
$actions[] = [
'params' => [
'sql_query' => 'CHECK TABLE ' . Util::backquote($table),
'table_maintenance' => 'Go',
],
'message' => __('Check table'),
'link' => 'CHECK_TABLE',
];
}

$actions[] = [
'params' => [
'sql_query' => 'CHECKSUM TABLE ' . Util::backquote($table),
'table_maintenance' => 'Go',
],
'message' => __('Checksum table'),
'link' => 'CHECKSUM_TABLE',
];

if ($tableObject->isEngine(['INNODB'])) {
$actions[] = [
'params' => [
'sql_query' => 'ALTER TABLE ' . Util::backquote($table) . ' ENGINE = InnoDB;',
],
'message' => __('Defragment table'),
'link' => 'InnoDB_File_Defragmenting',
];
}

$actions[] = [
'params' => [
'sql_query' => 'FLUSH TABLE ' . Util::backquote($table),
'message_to_show' => sprintf(
__('Table %s has been flushed.'),
htmlspecialchars($table)
),
'reload' => true,
],
'message' => __('Flush the table (FLUSH)'),
'link' => 'FLUSH',
];

if ($tableObject->isEngine(['MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB', 'TOKUDB'])) {
$actions[] = [
'params' => [
'sql_query' => 'OPTIMIZE TABLE ' . Util::backquote($table),
'table_maintenance' => 'Go',
],
'message' => __('Optimize table'),
'link' => 'OPTIMIZE_TABLE',
];
}

if ($tableObject->isEngine(['MYISAM', 'ARIA'])) {
$actions[] = [
'params' => [
'sql_query' => 'REPAIR TABLE ' . Util::backquote($table),
'table_maintenance' => 'Go',
],
'message' => __('Repair table'),
'link' => 'REPAIR_TABLE',
];
}

return $actions;
}

/**
* @return array<string, string>
*/
Expand Down
40 changes: 0 additions & 40 deletions libraries/classes/Sql.php
Expand Up @@ -26,7 +26,6 @@
use function in_array;
use function is_array;
use function is_bool;
use function is_string;
use function microtime;
use function session_start;
use function session_write_close;
Expand Down Expand Up @@ -1479,7 +1478,6 @@ private function getMessageIfMissingColumnIndex($table, $database, $editable, $h
* @param array $analyzed_sql_results analysed sql results
* @param string $db current database
* @param string $table current table
* @param Message|string|null $message message to show
* @param array|null $sql_data sql data
* @param DisplayResults $displayResultsObject Instance of DisplayResults
* @param string $pmaThemeImage uri of the theme image
Expand All @@ -1498,7 +1496,6 @@ private function getQueryResponseForResultsReturned(
array $analyzed_sql_results,
$db,
$table,
$message,
?array $sql_data,
$displayResultsObject,
$pmaThemeImage,
Expand Down Expand Up @@ -1606,36 +1603,6 @@ private function getQueryResponseForResultsReturned(
];
}

$tableMaintenanceHtml = '';
if (isset($_POST['table_maintenance'])) {
$scripts->addFile('makegrid.js');
$scripts->addFile('sql.js');
if (isset($message)) {
$message = is_string($message) ? Message::success($message) : $message;
$tableMaintenanceHtml = Generator::getMessage(
$message,
$GLOBALS['sql_query'],
'success'
);
}
$tableMaintenanceHtml .= $this->getHtmlForSqlQueryResultsTable(
$displayResultsObject,
$pmaThemeImage,
$url_query,
$displayParts,
false,
$unlim_num_rows,
$num_rows,
$showtable,
$result,
$analyzed_sql_results
);
if (empty($sql_data) || ($sql_data['valid_queries'] <= 1)) {
$response->addHTML($tableMaintenanceHtml);
exit;
}
}

if (! isset($_POST['printview']) || $_POST['printview'] != '1') {
$scripts->addFile('makegrid.js');
$scripts->addFile('sql.js');
Expand Down Expand Up @@ -1704,7 +1671,6 @@ private function getQueryResponseForResultsReturned(
}

return $this->template->render('sql/sql_query_results', [
'table_maintenance' => $tableMaintenanceHtml,
'previous_update_query' => $previousUpdateQueryHtml,
'profiling_chart' => $profilingChartHtml,
'missing_unique_column_message' => $missingUniqueColumnMessage,
Expand All @@ -1725,7 +1691,6 @@ private function getQueryResponseForResultsReturned(
* @param string|null $sql_query_for_bookmark the sql query to be stored as bookmark
* @param array|null $extra_data extra data
* @param string|null $message_to_show message to show
* @param Message|string|null $message message
* @param array|null $sql_data sql data
* @param string $goto goto page url
* @param string $pmaThemeImage uri of the PMA theme image
Expand All @@ -1743,7 +1708,6 @@ public function executeQueryAndSendQueryResponse(
$sql_query_for_bookmark,
$extra_data,
$message_to_show,
$message,
$sql_data,
$goto,
$pmaThemeImage,
Expand Down Expand Up @@ -1774,7 +1738,6 @@ public function executeQueryAndSendQueryResponse(
$sql_query_for_bookmark, // sql_query_for_bookmark
$extra_data, // extra_data
$message_to_show, // message_to_show
$message, // message
$sql_data, // sql_data
$goto, // goto
$pmaThemeImage, // pmaThemeImage
Expand All @@ -1796,7 +1759,6 @@ public function executeQueryAndSendQueryResponse(
* @param string|null $sql_query_for_bookmark the sql query to be stored as bookmark
* @param array|null $extra_data extra data
* @param string|null $message_to_show message to show
* @param Message|string|null $message message
* @param array|null $sql_data sql data
* @param string $goto goto page url
* @param string $pmaThemeImage uri of the PMA theme image
Expand All @@ -1816,7 +1778,6 @@ public function executeQueryAndGetQueryResponse(
?string $sql_query_for_bookmark,
$extra_data,
?string $message_to_show,
$message,
$sql_data,
$goto,
$pmaThemeImage,
Expand Down Expand Up @@ -1913,7 +1874,6 @@ public function executeQueryAndGetQueryResponse(
$analyzed_sql_results,
$db,
$table,
$message ?? null,
$sql_data ?? null,
$displayResultsObject,
$pmaThemeImage,
Expand Down
1 change: 0 additions & 1 deletion templates/sql/sql_query_results.twig
@@ -1,4 +1,3 @@
{{ table_maintenance|raw }}
<div class="sqlqueryresults ajax">
{{ previous_update_query|raw }}
{{ profiling_chart|raw }}
Expand Down

0 comments on commit 7936909

Please sign in to comment.