From ea3599194eac9a9bcd1c91bac5dc6a0b59e39020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 14 Aug 2019 13:57:33 -0300 Subject: [PATCH] Use the router for table operations page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- index.php | 3 ++ js/table/operations.js | 2 +- libraries/classes/Core.php | 1 - libraries/classes/Import.php | 2 +- libraries/classes/Menu.php | 3 +- libraries/classes/Operations.php | 16 +++++----- .../entry_points/table/operations.php | 14 +++------ test/classes/OperationsTest.php | 31 +++++++++++++------ 8 files changed, 41 insertions(+), 31 deletions(-) rename tbl_operations.php => libraries/entry_points/table/operations.php (97%) diff --git a/index.php b/index.php index e86a41a5d5..bb87b3ff33 100644 --- a/index.php +++ b/index.php @@ -139,6 +139,9 @@ if (isset($_GET['route']) || isset($_POST['route'])) { $routes->addRoute(['GET', 'POST'], '/change', function () { require_once ROOT_PATH . 'libraries/entry_points/table/change.php'; }); + $routes->addRoute(['GET', 'POST'], '/operations', function () { + require_once ROOT_PATH . 'libraries/entry_points/table/operations.php'; + }); $routes->addRoute(['GET', 'POST'], '/search', function () { require_once ROOT_PATH . 'libraries/entry_points/table/select.php'; }); diff --git a/js/table/operations.js b/js/table/operations.js index a7cf967999..df4fc31633 100644 --- a/js/table/operations.js +++ b/js/table/operations.js @@ -13,7 +13,7 @@ AJAX.registerTeardown('table/operations.js', function () { }); /** - * jQuery coding for 'Table operations'. Used on tbl_operations.php + * jQuery coding for 'Table operations'. Used on /table/operations * Attach Ajax Event handlers for Table operations */ AJAX.registerOnload('table/operations.js', function () { diff --git a/libraries/classes/Core.php b/libraries/classes/Core.php index 8245832dc5..b40590bd4b 100644 --- a/libraries/classes/Core.php +++ b/libraries/classes/Core.php @@ -41,7 +41,6 @@ class Core 'tbl_import.php', 'tbl_indexes.php', 'tbl_export.php', - 'tbl_operations.php', 'tbl_relation.php', 'tbl_replace.php', 'tbl_row_action.php', diff --git a/libraries/classes/Import.php b/libraries/classes/Import.php index 415d119864..fb34632802 100644 --- a/libraries/classes/Import.php +++ b/libraries/classes/Import.php @@ -1271,7 +1271,7 @@ class Import ]; $tbl_url = Url::getFromRoute('/sql', $params); $tbl_struct_url = Url::getFromRoute('/table/structure', $params); - $tbl_ops_url = 'tbl_operations.php' . Url::getCommon($params); + $tbl_ops_url = Url::getFromRoute('/table/operations', $params); unset($params); diff --git a/libraries/classes/Menu.php b/libraries/classes/Menu.php index fd6f9d4d51..05d898777c 100644 --- a/libraries/classes/Menu.php +++ b/libraries/classes/Menu.php @@ -401,8 +401,9 @@ class Menu */ if (! $tbl_is_view && ! $db_is_system_schema) { $tabs['operation']['icon'] = 'b_tblops'; - $tabs['operation']['link'] = 'tbl_operations.php'; + $tabs['operation']['link'] = Url::getFromRoute('/table/operations'); $tabs['operation']['text'] = __('Operations'); + $tabs['operation']['active'] = isset($_REQUEST['route']) && $_REQUEST['route'] === '/table/operations'; } /** * Views support a limited number of operations diff --git a/libraries/classes/Operations.php b/libraries/classes/Operations.php index 49b2e343a9..5dc9823b63 100644 --- a/libraries/classes/Operations.php +++ b/libraries/classes/Operations.php @@ -838,7 +838,7 @@ class Operations { $html_output = '
'; $html_output .= '
'; + . 'action="' . Url::getFromRoute('/table/operations') . '">'; $html_output .= Url::getHiddenInputs( $GLOBALS['db'], $GLOBALS['table'] @@ -879,8 +879,8 @@ class Operations public function getHtmlForMoveTable() { $html_output = '
'; - $html_output .= '' . Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); @@ -970,8 +970,8 @@ class Operations $checksum ) { $html_output = '
'; - $html_output .= '' @@ -1700,7 +1700,7 @@ class Operations $html_output = '
' . '' + . 'method="post" action="' . Url::getFromRoute('/table/operations') . '">' . Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']) . '
' . '' diff --git a/tbl_operations.php b/libraries/entry_points/table/operations.php similarity index 97% rename from tbl_operations.php rename to libraries/entry_points/table/operations.php index c2b1d01cdf..032bb6be93 100644 --- a/tbl_operations.php +++ b/libraries/entry_points/table/operations.php @@ -19,14 +19,12 @@ use PhpMyAdmin\Table; use PhpMyAdmin\Url; use PhpMyAdmin\Util; -if (! defined('ROOT_PATH')) { - define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); +if (! defined('PHPMYADMIN')) { + exit; } global $containerBuilder, $url_query; -require_once ROOT_PATH . 'libraries/common.inc.php'; - /** @var Response $response */ $response = $containerBuilder->get(Response::class); @@ -60,8 +58,8 @@ $scripts->addFile('table/operations.js'); * Runs common work */ require ROOT_PATH . 'libraries/tbl_common.inc.php'; -$url_query .= '&goto=tbl_operations.php&back=tbl_operations.php'; -$url_params['goto'] = $url_params['back'] = 'tbl_operations.php'; +$url_params['goto'] = $url_params['back'] = Url::getFromRoute('/table/operations'); +$url_query .= Url::getCommon($url_params, '&'); /** * Gets relation settings @@ -342,9 +340,7 @@ if (isset($result) && empty($message_to_show)) { unset($_message); } -$url_params['goto'] - = $url_params['back'] - = 'tbl_operations.php'; +$url_params['goto'] = $url_params['back'] = Url::getFromRoute('/table/operations'); /** * Get columns names diff --git a/test/classes/OperationsTest.php b/test/classes/OperationsTest.php index a3edaf6f5e..64003fcf1e 100644 --- a/test/classes/OperationsTest.php +++ b/test/classes/OperationsTest.php @@ -143,15 +143,23 @@ class OperationsTest extends TestCase */ public function testGetHtmlForOrderTheTable() { - - $this->assertRegExp( - '/.*tbl_operations.php(.|[\n])*Alter table order by([\n]|.)*order_order.*/m', - $this->operations->getHtmlForOrderTheTable( - [ - ['Field' => "column1"], - ['Field' => "column2"], - ] - ) + $actual = $this->operations->getHtmlForOrderTheTable( + [ + ['Field' => "column1"], + ['Field' => "column2"], + ] + ); + $this->assertStringContainsString( + 'index.php?route=/table/operations', + $actual + ); + $this->assertStringContainsString( + 'Alter table order by', + $actual + ); + $this->assertStringContainsString( + 'order_order', + $actual ); } @@ -257,7 +265,10 @@ class OperationsTest extends TestCase "param2" => 'bar', ] ); - $this->assertRegExp('/.*action="tbl_operations.php".*/', $html); + $this->assertStringContainsString( + 'action="index.php?route=/table/operations', + $html + ); $this->assertRegExp('/.*ANALYZE.*/', $html); $this->assertRegExp('/.*REBUILD.*/', $html); }