Skip to content

Commit

Permalink
Extract the change action from table structure index method
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed May 22, 2020
1 parent 1667bd6 commit a6d9818
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 100 deletions.
2 changes: 2 additions & 0 deletions js/table/structure.js
Expand Up @@ -424,6 +424,8 @@ AJAX.registerOnload('table/structure.js', function () {
url = 'index.php?route=/table/structure/central-columns-add';
} else if (action === 'remove_from_central_columns') {
url = 'index.php?route=/table/structure/central-columns-remove';
} else if (action === 'change') {
url = 'index.php?route=/table/structure/change';
} else if (action === 'drop') {
url = 'index.php?route=/table/structure/drop-confirm';
} else if (action === 'ftext') {
Expand Down
115 changes: 15 additions & 100 deletions libraries/classes/Controllers/Table/StructureController.php
Expand Up @@ -231,67 +231,6 @@ public function index(): void
$GLOBALS['goto'],
$GLOBALS['pmaThemeImage']
);
} else {
// handle multiple field commands
// handle confirmation of deleting multiple columns
$action = Url::getFromRoute('/table/structure');
$GLOBALS['selected'] = $_POST['selected_fld'];
[
$what_ret,
$query_type_ret,
$is_unset_submit_mult,
$mult_btn_ret,
$centralColsError,
] = $this->getDataForSubmitMult(
$submit_mult,
$_POST['selected_fld'],
$action
);
//update the existing variables
if (isset($what_ret)) {
$GLOBALS['what'] = $what_ret;
global $what;
}
if (isset($query_type_ret)) {
$GLOBALS['query_type'] = $query_type_ret;
global $query_type;
}
if ($is_unset_submit_mult) {
unset($submit_mult);
}
if (isset($mult_btn_ret)) {
$GLOBALS['mult_btn'] = $mult_btn_ret;
global $mult_btn;
}

$goto = $_POST['goto'] ?? $goto ?? null;
$mult_btn = $_POST['mult_btn'] ?? $mult_btn ?? null;
$query_type = $_POST['query_type'] ?? $query_type ?? null;
$selected = $_POST['selected'] ?? $selected ?? null;
$selected_fld = $_POST['selected_fld'] ?? $selected_fld ?? null;
$sql_query = $_POST['sql_query'] ?? $sql_query ?? null;
$submit_mult = $_POST['submit_mult'] ?? $submit_mult ?? null;
$url_query = $_POST['url_query'] ?? $url_query ?? null;

if (! empty($submit_mult)
&& $submit_mult != __('With selected:')
&& ! empty($selected_fld)
) {
// phpcs:disable PSR1.Files.SideEffects
define('PMA_SUBMIT_MULT', 1);
// phpcs:enable
}

/**
* if $submit_mult == 'change', execution will have stopped
* at this point
*/
if (empty($message)) {
$message = Message::success();
}
$this->response->addHTML(
Generator::getMessage($message, $sql_query)
);
}
} else {
$this->response->setRequestStatus(false);
Expand Down Expand Up @@ -390,6 +329,20 @@ public function index(): void
);
}

public function change(): void
{
$selected = $_POST['selected_fld'] ?? [];

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

return;
}

$this->displayHtmlForColumnChange($selected, Url::getFromRoute('/table/structure'));
}

public function addToCentralColumns(): void
{
global $sql_query, $reread_info, $showtable;
Expand Down Expand Up @@ -1664,10 +1617,7 @@ protected function updatePartitioning()
*/
protected function getMultipleFieldCommandType()
{
$types = [
'change',
'browse',
];
$types = ['browse'];

foreach ($types as $type) {
if (isset($_POST['submit_mult_' . $type . '_x'])) {
Expand Down Expand Up @@ -2423,39 +2373,4 @@ protected function getKeyForTablePrimary()

return $primary;
}

/**
* Get List of information for Submit Mult
*
* @param string $submit_mult mult_submit type
* @param array $selected the selected columns
* @param string $action action type
*
* @return array
*/
protected function getDataForSubmitMult($submit_mult, $selected, $action)
{
$what = null;
$query_type = null;
$is_unset_submit_mult = false;
$mult_btn = null;
$centralColsError = null;
switch ($submit_mult) {
case 'change':
$this->displayHtmlForColumnChange($selected, $action);
// execution stops here but PhpMyAdmin\Response correctly finishes
// the rendering
exit;
case 'browse':
// this should already be handled by /table/structure
}

return [
$what,
$query_type,
$is_unset_submit_mult,
$mult_btn,
$centralColsError,
];
}
}
1 change: 1 addition & 0 deletions libraries/routes.php
Expand Up @@ -255,6 +255,7 @@
$routes->addRoute(['GET', 'POST'], '', [TableStructureController::class, 'index']);
$routes->post('/central-columns-add', [TableStructureController::class, 'addToCentralColumns']);
$routes->post('/central-columns-remove', [TableStructureController::class, 'removeFromCentralColumns']);
$routes->post('/change', [TableStructureController::class, 'change']);
$routes->post('/drop', [TableStructureController::class, 'drop']);
$routes->post('/drop-confirm', [TableStructureController::class, 'dropConfirm']);
$routes->post('/fulltext', [TableStructureController::class, 'fulltext']);
Expand Down

0 comments on commit a6d9818

Please sign in to comment.