Use the router for table operations page

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2019-08-14 13:57:33 -03:00
parent 542059eca0
commit ea3599194e
8 changed files with 41 additions and 31 deletions

View File

@ -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';
});

View File

@ -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 () {

View File

@ -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',

View File

@ -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);

View File

@ -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

View File

@ -838,7 +838,7 @@ class Operations
{
$html_output = '<div>';
$html_output .= '<form method="post" id="alterTableOrderby" '
. 'action="tbl_operations.php">';
. 'action="' . Url::getFromRoute('/table/operations') . '">';
$html_output .= Url::getHiddenInputs(
$GLOBALS['db'],
$GLOBALS['table']
@ -879,8 +879,8 @@ class Operations
public function getHtmlForMoveTable()
{
$html_output = '<div>';
$html_output .= '<form method="post" action="tbl_operations.php"'
. ' id="moveTableForm" class="ajax"'
$html_output .= '<form method="post" action="' . Url::getFromRoute('/table/operations')
. '" id="moveTableForm" class="ajax"'
. ' onsubmit="return Functions.emptyCheckTheField(this, \'new_name\')">'
. Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
@ -970,8 +970,8 @@ class Operations
$checksum
) {
$html_output = '<div>';
$html_output .= '<form method="post" action="tbl_operations.php"';
$html_output .= ' id="tableOptionsForm" class="ajax">';
$html_output .= '<form method="post" action="' . Url::getFromRoute('/table/operations');
$html_output .= '" id="tableOptionsForm" class="ajax">';
$html_output .= Url::getHiddenInputs(
$GLOBALS['db'],
$GLOBALS['table']
@ -1339,8 +1339,8 @@ class Operations
public function getHtmlForCopytable()
{
$html_output = '<div>';
$html_output .= '<form method="post" action="tbl_operations.php" '
. 'name="copyTable" '
$html_output .= '<form method="post" action="' . Url::getFromRoute('/table/operations')
. '" name="copyTable" '
. 'id="copyTable" '
. ' class="ajax" '
. 'onsubmit="return Functions.emptyCheckTheField(this, \'new_name\')">'
@ -1700,7 +1700,7 @@ class Operations
$html_output = '<div>'
. '<form id="partitionsForm" class="ajax" '
. 'method="post" action="tbl_operations.php" >'
. 'method="post" action="' . Url::getFromRoute('/table/operations') . '">'
. Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
. '<fieldset>'
. '<legend>'

View File

@ -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 .= '&amp;goto=tbl_operations.php&amp;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

View File

@ -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);
}