Skip to content

Commit

Permalink
Extract optimize action from db structure index method
Browse files Browse the repository at this point in the history
Related to #16173.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jun 20, 2020
1 parent dcf6586 commit d1e10a9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
2 changes: 2 additions & 0 deletions js/database/structure.js
Expand Up @@ -313,6 +313,8 @@ AJAX.registerOnload('database/structure.js', function () {
url = 'index.php?route=/database/structure/empty-form';
} else if (action === 'export') {
url = 'index.php?route=/database/structure/export';
} else if (action === 'optimize_tbl') {
url = 'index.php?route=/database/structure/optimize-table';
} else if (action === 'show_create') {
url = 'index.php?route=/database/structure/show-create';
} else {
Expand Down
58 changes: 51 additions & 7 deletions libraries/classes/Controllers/Database/StructureController.php
Expand Up @@ -402,7 +402,6 @@ public function multiSubmitAction(): void
// selected tables
$selected = $_POST['selected_tbl'];
switch ($submit_mult) {
case 'optimize_tbl':
case 'repair_tbl':
$query_type = $submit_mult;
unset($submit_mult);
Expand Down Expand Up @@ -468,12 +467,6 @@ public function multiSubmitAction(): void
$reload = 1;
break;

case 'optimize_tbl':
$sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ')
. Util::backquote($selected[$i]);
$execute_query_later = true;
break;

case 'repair_tbl':
$sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ')
. Util::backquote($selected[$i]);
Expand Down Expand Up @@ -1878,4 +1871,55 @@ public function checksumTable(): void

$this->index();
}

public function optimizeTable(): void
{
global $db, $goto, $pmaThemeImage;

$selected = $_POST['selected_tbl'] ?? [];

if (empty($selected)) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', __('No table selected.'));

return;
}

$sql_query = '';
$selectedCount = count($selected);

for ($i = 0; $i < $selectedCount; $i++) {
$sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ') . Util::backquote($selected[$i]);
}

$sql = new Sql();
$sql->executeQueryAndSendQueryResponse(
null,
false,
$db,
'',
null,
null,
null,
null,
null,
null,
$goto,
$pmaThemeImage,
null,
null,
'optimize_tbl',
$sql_query,
$selected,
null
);

if (empty($_POST['message'])) {
$_POST['message'] = Message::success();
}

unset($_POST['submit_mult']);

$this->index();
}
}
1 change: 1 addition & 0 deletions libraries/routes.php
Expand Up @@ -157,6 +157,7 @@
StructureController::class,
'addRemoveFavoriteTablesAction',
]);
$routes->post('/optimize-table', [StructureController::class, 'optimizeTable']);
$routes->addRoute(['GET', 'POST'], '/real-row-count', [
StructureController::class,
'handleRealRowCountRequestAction',
Expand Down

0 comments on commit d1e10a9

Please sign in to comment.