From 4e8484229a2e9fa6db473e02fc0f435115d6467e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 11 Jun 2020 21:48:36 -0300 Subject: [PATCH] Extract export action from db structure index method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to #16173 Signed-off-by: MaurĂ­cio Meneghini Fauth --- js/database/structure.js | 39 ++++++++++++++++--- .../Database/StructureController.php | 22 ++++++++--- libraries/routes.php | 1 + 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/js/database/structure.js b/js/database/structure.js index 612ba3bba477..1995358c7768 100644 --- a/js/database/structure.js +++ b/js/database/structure.js @@ -216,7 +216,9 @@ AJAX.registerOnload('database/structure.js', function () { * Event handler on select of "Make consistent with central list" */ $('select[name=submit_mult]').on('change', function (event) { - if ($(this).val() === 'make_consistent_with_central_list') { + var action = $(this).val(); + + if (action === 'make_consistent_with_central_list') { event.preventDefault(); event.stopPropagation(); jqConfirm( @@ -225,7 +227,13 @@ AJAX.registerOnload('database/structure.js', function () { } ); return false; - } else if ($(this).val() === 'copy_tbl' || $(this).val() === 'add_prefix_tbl' || $(this).val() === 'replace_prefix_tbl' || $(this).val() === 'copy_tbl_change_prefix') { + } + + if (action === 'copy_tbl' || + action === 'add_prefix_tbl' || + action === 'replace_prefix_tbl' || + action === 'copy_tbl_change_prefix' + ) { event.preventDefault(); event.stopPropagation(); if ($('input[name="selected_tbl[]"]:checked').length === 0) { @@ -233,13 +241,13 @@ AJAX.registerOnload('database/structure.js', function () { } var formData = $('#tablesForm').serialize(); var modalTitle = ''; - if ($(this).val() === 'copy_tbl') { + if (action === 'copy_tbl') { modalTitle = Messages.strCopyTablesTo; - } else if ($(this).val() === 'add_prefix_tbl') { + } else if (action === 'add_prefix_tbl') { modalTitle = Messages.strAddPrefix; - } else if ($(this).val() === 'replace_prefix_tbl') { + } else if (action === 'replace_prefix_tbl') { modalTitle = Messages.strReplacePrefix; - } else if ($(this).val() === 'copy_tbl_change_prefix') { + } else if (action === 'copy_tbl_change_prefix') { modalTitle = Messages.strCopyPrefix; } $.ajax({ @@ -268,9 +276,28 @@ AJAX.registerOnload('database/structure.js', function () { buttons: buttonOptions }); }); + + return; + } + + var url = ''; + + if (action === 'export') { + url = 'index.php?route=/database/structure/export'; } else { $('#tablesForm').trigger('submit'); + + return; } + + var $form = $(this).parents('form'); + var argsep = CommonParams.get('arg_separator'); + var data = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true'; + + Functions.ajaxShowMessage(); + AJAX.source = $form; + + $.post(url, data, AJAX.responseHandler); }); /** diff --git a/libraries/classes/Controllers/Database/StructureController.php b/libraries/classes/Controllers/Database/StructureController.php index 4d60a5a83313..017893e2c4c4 100644 --- a/libraries/classes/Controllers/Database/StructureController.php +++ b/libraries/classes/Controllers/Database/StructureController.php @@ -420,12 +420,6 @@ public function multiSubmitAction(): void unset($submit_mult); $mult_btn = __('Yes'); break; - case 'export': - unset($submit_mult); - /** @var ExportController $controller */ - $controller = $containerBuilder->get(ExportController::class); - $controller->index(); - exit; case 'copy_tbl': $_url_params = [ 'query_type' => 'copy_tbl', @@ -1613,4 +1607,20 @@ protected function getValuesForInnodbTable( $sum_size, ]; } + + public function export(): void + { + global $containerBuilder; + + if (empty($_POST['selected_tbl'])) { + $this->response->setRequestStatus(false); + $this->response->addJSON('message', __('No table selected.')); + + return; + } + + /** @var ExportController $controller */ + $controller = $containerBuilder->get(ExportController::class); + $controller->index(); + } } diff --git a/libraries/routes.php b/libraries/routes.php index f6e115394de5..e39d0841dd1e 100644 --- a/libraries/routes.php +++ b/libraries/routes.php @@ -138,6 +138,7 @@ }); $routes->addGroup('/structure', static function (RouteCollector $routes) { $routes->addRoute(['GET', 'POST'], '', [StructureController::class, 'index']); + $routes->post('/export', [StructureController::class, 'export']); $routes->addRoute(['GET', 'POST'], '/favorite-table', [ StructureController::class, 'addRemoveFavoriteTablesAction',