Skip to content

Commit 9b5b210

Browse files
committed
Remove action global var from ColumnsDefinition class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent a1a778d commit 9b5b210

7 files changed

Lines changed: 23 additions & 30 deletions

File tree

libraries/classes/Controllers/Table/AddFieldController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959

6060
public function __invoke(): void
6161
{
62-
global $errorUrl, $message, $action, $active_page, $sql_query;
62+
global $errorUrl, $message, $active_page, $sql_query;
6363
global $num_fields, $regenerate, $result, $db, $table;
6464

6565
$this->addScriptFiles(['table/structure.js']);
@@ -174,14 +174,10 @@ public function __invoke(): void
174174
DbTableExists::check($db, $table);
175175

176176
$active_page = Url::getFromRoute('/table/structure');
177-
/**
178-
* Display the form
179-
*/
180-
$action = Url::getFromRoute('/table/add-field');
181177

182178
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
183179

184-
$templateData = $this->columnsDefinition->displayForm($action, $num_fields, $regenerate);
180+
$templateData = $this->columnsDefinition->displayForm('/table/add-field', $num_fields, $regenerate);
185181

186182
$this->render('columns_definitions/column_definitions_form', $templateData);
187183
}

libraries/classes/Controllers/Table/CreateController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(
5858

5959
public function __invoke(): void
6060
{
61-
global $num_fields, $action, $sql_query, $result, $db, $table;
61+
global $num_fields, $sql_query, $result, $db, $table;
6262

6363
Util::checkParameters(['db']);
6464

@@ -100,8 +100,6 @@ public function __invoke(): void
100100

101101
$num_fields = $createAddField->getNumberOfFieldsFromRequest();
102102

103-
$action = Url::getFromRoute('/table/create');
104-
105103
/**
106104
* The form used to define the structure of the table has been submitted
107105
*/
@@ -160,7 +158,7 @@ public function __invoke(): void
160158

161159
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
162160

163-
$templateData = $this->columnsDefinition->displayForm($action, $num_fields);
161+
$templateData = $this->columnsDefinition->displayForm('/table/create', $num_fields);
164162

165163
$this->render('columns_definitions/column_definitions_form', $templateData);
166164
}

libraries/classes/Controllers/Table/Structure/ChangeController.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PhpMyAdmin\ResponseRenderer;
1212
use PhpMyAdmin\Table\ColumnsDefinition;
1313
use PhpMyAdmin\Template;
14-
use PhpMyAdmin\Url;
1514

1615
use function __;
1716
use function count;
@@ -62,7 +61,7 @@ public function __invoke(): void
6261
*/
6362
private function displayHtmlForColumnChange(?array $selected): void
6463
{
65-
global $action, $num_fields;
64+
global $num_fields;
6665

6766
if (empty($selected)) {
6867
$selected[] = $_REQUEST['field'];
@@ -90,8 +89,6 @@ private function displayHtmlForColumnChange(?array $selected): void
9089

9190
$num_fields = count($fields_meta);
9291

93-
$action = Url::getFromRoute('/table/structure/save');
94-
9592
/**
9693
* Form for changing properties.
9794
*/
@@ -100,7 +97,13 @@ private function displayHtmlForColumnChange(?array $selected): void
10097

10198
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
10299

103-
$templateData = $this->columnsDefinition->displayForm($action, $num_fields, null, $selected, $fields_meta);
100+
$templateData = $this->columnsDefinition->displayForm(
101+
'/table/structure/save',
102+
$num_fields,
103+
null,
104+
$selected,
105+
$fields_meta
106+
);
104107

105108
$this->render('columns_definitions/column_definitions_form', $templateData);
106109
}

libraries/classes/Table/ColumnsDefinition.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PhpMyAdmin\StorageEngine;
1414
use PhpMyAdmin\Table;
1515
use PhpMyAdmin\Transformations;
16-
use PhpMyAdmin\Url;
1716
use PhpMyAdmin\Util;
1817

1918
use function array_keys;
@@ -54,11 +53,11 @@ public function __construct(DatabaseInterface $dbi, Relation $relation, Transfor
5453
}
5554

5655
/**
57-
* @param string $action Action
5856
* @param int $num_fields The number of fields
5957
* @param string|null $regenerate Use regeneration
6058
* @param array|null $selected Selected
6159
* @param array|null $fields_meta Fields meta
60+
* @psalm-param '/table/create'|'/table/add-field'|'/table/structure/save' $action
6261
*
6362
* @return array<string, mixed>
6463
*/
@@ -75,18 +74,17 @@ public function displayForm(
7574
'server',
7675
'db',
7776
'table',
78-
'action',
7977
'num_fields',
8078
]);
8179

8280
$length_values_input_size = 8;
8381
$content_cells = [];
8482
$form_params = ['db' => $db];
8583

86-
if ($action == Url::getFromRoute('/table/create')) {
84+
if ($action === '/table/create') {
8785
$form_params['reload'] = 1;
8886
} else {
89-
if ($action == Url::getFromRoute('/table/add-field')) {
87+
if ($action === '/table/add-field') {
9088
$form_params = array_merge(
9189
$form_params,
9290
[
@@ -117,8 +115,7 @@ public function displayForm(
117115
}
118116
}
119117

120-
$is_backup = ($action != Url::getFromRoute('/table/create')
121-
&& $action != Url::getFromRoute('/table/add-field'));
118+
$is_backup = $action !== '/table/create' && $action !== '/table/add-field';
122119

123120
$relationParameters = $this->relation->getRelationParameters();
124121

templates/columns_definitions/column_definitions_form.twig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
<form method="post" action="{{ action }}" class="
2-
{{- action == url('/table/create') ? 'create_table' : 'append_fields' -}}
3-
_form ajax lock-page">
1+
<form method="post" action="{{ url(action) }}" class="
2+
{{- action == '/table/create' ? 'create_table_form' : 'append_fields_form' }} ajax lock-page">
43
{{ get_hidden_inputs(form_params) }}
54
{# happens when an index has been set on a column #}
65
{# and a column is added to the table creation dialog #}
@@ -16,7 +15,7 @@
1615
<input type="hidden" name="spatial_indexes" value="
1716
{{- spatial_indexes is not empty ? spatial_indexes : '[]' }}">
1817

19-
{% if action == url('/table/create') %}
18+
{% if action == '/table/create' %}
2019
<div id="table_name_col_no_outer">
2120
<table id="table_name_col_no" class="table table-borderless tdblock">
2221
<tr class="align-middle float-start">
@@ -65,7 +64,7 @@
6564
'charsets': charsets
6665
} only %}
6766
{% endif %}
68-
{% if action == url('/table/create') %}
67+
{% if action == '/table/create' %}
6968
<div class="responsivetable">
7069
<table class="table table-borderless w-auto align-middle mb-0">
7170
<tr class="align-top">
@@ -150,7 +149,7 @@
150149
</div>
151150
{% endif %}
152151
<fieldset class="pma-fieldset tblFooters">
153-
{% if action == url('/table/add-field') or action == url('/table/structure/save') %}
152+
{% if action == '/table/add-field' or action == '/table/structure/save' %}
154153
<input type="checkbox" name="online_transaction" value="ONLINE_TRANSACTION_ENABLED" />{% trans %}Online transaction{% context %}Online transaction part of the SQL DDL for InnoDB{% endtrans %}{{ show_mysql_docu('innodb-online-ddl') }}
155154
{% endif %}
156155
<input class="btn btn-secondary preview_sql" type="button"

test/classes/Controllers/Table/AddFieldControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testInvoke(): void
171171
'is_backup' => false,
172172
'fields_meta' => null,
173173
'relation_parameters' => $relation->getRelationParameters(),
174-
'action' => 'index.php?route=/table/add-field&lang=en',
174+
'action' => '/table/add-field',
175175
'form_params' => [
176176
'db' => 'test_db',
177177
'field_where' => 'after',

test/classes/Controllers/Table/CreateControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function testCreateController(): void
169169
'is_backup' => false,
170170
'fields_meta' => null,
171171
'relation_parameters' => $relation->getRelationParameters(),
172-
'action' => 'index.php?route=/table/create&lang=en',
172+
'action' => '/table/create',
173173
'form_params' => [
174174
'db' => 'test_db',
175175
'reload' => 1,

0 commit comments

Comments
 (0)