Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global variables #19503

Merged
merged 63 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a01fed1
Remove username global variable
MauricioFauth Jan 7, 2025
d253986
Remove hostname global variable
MauricioFauth Jan 7, 2025
c481ab3
Remove the pred_username global variable
MauricioFauth Jan 8, 2025
64f86ad
Remove the pred_hostname global variable
MauricioFauth Jan 8, 2025
b4cd510
Remove the new_username global variable
MauricioFauth Jan 8, 2025
ebea0aa
Remove the reload global variable
MauricioFauth Jan 8, 2025
aad57a8
Remove the asfile global variable
MauricioFauth Jan 8, 2025
a164696
Remove the SESSION_KEY global variable
MauricioFauth Jan 8, 2025
f39f285
Remove the import_text global variable
MauricioFauth Jan 8, 2025
0958b97
Remove the save_on_server global variable
MauricioFauth Jan 8, 2025
716c4bb
Remove the output_charset_conversion global variable
MauricioFauth Jan 8, 2025
b3df04b
Remove the buffer_needed global variable
MauricioFauth Jan 8, 2025
ae305d6
Remove the output_kanji_conversion global variable
MauricioFauth Jan 8, 2025
11766ad
Remove the where_clause global variable
MauricioFauth Jan 8, 2025
1998aa7
Remove some unused global variables
MauricioFauth Jan 8, 2025
138c502
Remove the single_table global variable
MauricioFauth Jan 8, 2025
1406816
Remove the conn_error global variable
MauricioFauth Jan 8, 2025
0669a17
Remove the display_query global variable
MauricioFauth Jan 9, 2025
f5d99ce
Remove the errno global variable
MauricioFauth Jan 9, 2025
b962abf
Remove the charset global variable
MauricioFauth Jan 9, 2025
aa9736b
Remove the pma_auth_server global variable
MauricioFauth Jan 9, 2025
7742e3a
Remove the cached_affected_rows global variable
MauricioFauth Jan 9, 2025
17371f0
Remove the complete_query global variable
MauricioFauth Jan 9, 2025
0ffbe20
Remove the compression global variable
MauricioFauth Jan 9, 2025
4f4f31e
Remove the file_handle global variable
MauricioFauth Jan 9, 2025
06c62ee
Remove the from_cookie global variable
MauricioFauth Jan 9, 2025
941a1e2
Remove the knjenc global variable
MauricioFauth Jan 9, 2025
01a9449
Remove the maxsize global variable
MauricioFauth Jan 9, 2025
04f1bef
Remove the memory_limit global variable
MauricioFauth Jan 9, 2025
84546f0
Remove the old_tz global variable
MauricioFauth Jan 9, 2025
7475ea4
Remove the onfly_compression global variable
MauricioFauth Jan 9, 2025
8c6b69d
Remove the plugin_scripts global variable
MauricioFauth Jan 9, 2025
f42d1b2
Remove the querytime global variable
MauricioFauth Jan 9, 2025
96cf13c
Remove the ajax_reload global variable
MauricioFauth Jan 9, 2025
99c70e3
Remove the unlim_num_rows global variable
MauricioFauth Jan 10, 2025
56b9e21
Remove the show_as_php global variable
MauricioFauth Jan 10, 2025
7748867
Remove the table_select global variable
MauricioFauth Jan 10, 2025
e479d26
Remove the table_data global variable
MauricioFauth Jan 10, 2025
bf223b2
Remove the xkana global variable
MauricioFauth Jan 10, 2025
760ad51
Remove the unsaved_values global variable
MauricioFauth Jan 10, 2025
bff3ffb
Remove the disp_message global variable
MauricioFauth Jan 10, 2025
34b3a81
Remove the num_tables global variable
MauricioFauth Jan 10, 2025
3bfa09e
Remove the result global variable
MauricioFauth Jan 10, 2025
8f932a5
Remove the auto_increment global variable
MauricioFauth Jan 10, 2025
adf0f1f
Remove the row global variable
MauricioFauth Jan 10, 2025
ce275e1
Remove the save_filename global variable
MauricioFauth Jan 10, 2025
ec80fd2
Remove the disp_query global variable
MauricioFauth Jan 10, 2025
faded19
Remove the no_constraints_comments global variable
MauricioFauth Jan 10, 2025
da51a2c
Remove the time_start global variable
MauricioFauth Jan 10, 2025
1564e80
Remove the using_bookmark_message global variable
MauricioFauth Jan 10, 2025
34bd94b
Remove the errorUrl global varaible
MauricioFauth Jan 10, 2025
4e1f0c1
Remove the maxY global variable
MauricioFauth Jan 10, 2025
2b4aac5
Remove the message_to_show global variable
MauricioFauth Jan 10, 2025
1176de2
Remove the importHandle global variable
MauricioFauth Jan 10, 2025
43cd4f4
Remove the buffer global variable
MauricioFauth Jan 10, 2025
25e0ef6
Remove the eof global variable
MauricioFauth Jan 10, 2025
c635322
Remove the special_message global variable
MauricioFauth Jan 10, 2025
c2cdfd7
Remove the buffer_message global variable
MauricioFauth Jan 10, 2025
728f682
Remove the exporting_metadata global variable
MauricioFauth Jan 10, 2025
657d1d0
Remove the current_result global variable
MauricioFauth Jan 10, 2025
fa744d7
Access _POST and _SESSION directly
MauricioFauth Jan 10, 2025
3e5934e
Fix failing tests
MauricioFauth Jan 11, 2025
ed9dc6c
Remove $GLOBALS clean up from AbstractTestCase
MauricioFauth Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
690 changes: 93 additions & 597 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

495 changes: 88 additions & 407 deletions psalm-baseline.xml

Large diffs are not rendered by default.

32 changes: 0 additions & 32 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,4 @@
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>

<globals>
<var name="GLOBALS" type="array{
asfile: bool,
buffer_needed: bool,
cached_affected_rows: int|numeric-string,
charset: string,
complete_query: string,
compression: 'none'|'zip'|'gzip',
conn_error: string,
display_query: string,
errno: int,
error: bool,
file_handle: resource|null,
from_cookie: bool,
hostname: string,
import_text: string,
knjenc: string,
maxsize: string,
memory_limit: int,
old_tz: string,
onfly_compression: bool,
output_charset_conversion: bool,
output_kanji_conversion: bool,
plugin_scripts: string[],
pma_auth_server: string,
querytime: float|int,
save_on_server: bool,
SESSION_KEY: string,
username: string
}"/>
</globals>
</psalm>
20 changes: 10 additions & 10 deletions resources/templates/server/privileges/login_information_fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<label for="select_pred_username">{{ t('User name:') }}</label>
<span class="options">
<select name="pred_username" id="select_pred_username" title="{{ t('User name') }}">
<option value="any"{{ pred_username == 'any' ? ' selected' }}>{{ t('Any user') }}</option>
<option value="userdefined"{{ pred_username is null or pred_username == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
<option value="any"{{ predefined_username == 'any' ? ' selected' }}>{{ t('Any user') }}</option>
<option value="userdefined"{{ predefined_username == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
</select>
</span>
<input type="text" spellcheck="false" name="username" id="pma_username" class="autofocus" maxlength="{{ username_length }}" title="{{ t('User name') }}"
{%- if username is not empty %} value="{{ new_username is not null ? new_username : username }}"{% endif -%}
{{- pred_username is null or pred_username == 'userdefined' ? ' required' }}>
{%- if username is not empty %} value="{{ username }}"{% endif -%}
{{- predefined_username == 'userdefined' ? ' required' }}>

<div id="user_exists_warning" class="hide">
{{ t('An account already exists with the same username but possibly a different hostname.')|notice }}
Expand All @@ -25,17 +25,17 @@
<span class="options">
<select name="pred_hostname" id="select_pred_hostname" title="{{ t('Host name') }}"
{{- this_host is not null and this_host != 'localhost' and this_host != '127.0.0.1' ? ' data-thishost="' ~ this_host ~ '"' }}>
<option value="any"{{ pred_hostname == 'any' ? ' selected' }}>{{ t('Any host') }}</option>
<option value="localhost"{{ pred_hostname == 'localhost' ? ' selected' }}>{{ t('Local') }}</option>
<option value="any"{{ predefined_hostname == 'any' ? ' selected' }}>{{ t('Any host') }}</option>
<option value="localhost"{{ predefined_hostname == 'localhost' ? ' selected' }}>{{ t('Local') }}</option>
{% if this_host is not empty %}
<option value="thishost"{{ pred_hostname == 'thishost' ? ' selected' }}>{{ t('This host') }}</option>
<option value="thishost"{{ predefined_hostname == 'thishost' ? ' selected' }}>{{ t('This host') }}</option>
{% endif %}
<option value="hosttable"{{ pred_hostname == 'hosttable' ? ' selected' }}>{{ t('Use host table') }}</option>
<option value="userdefined"{{ pred_hostname == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
<option value="hosttable"{{ predefined_hostname == 'hosttable' ? ' selected' }}>{{ t('Use host table') }}</option>
<option value="userdefined"{{ predefined_hostname == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
</select>
</span>
<input type="text" name="hostname" id="pma_hostname" maxlength="{{ hostname_length }}" value="{{ hostname|default('%') }}" title="
{{- t('Host name') }}"{{ pred_hostname == 'userdefined' ? ' required' }}>
{{- t('Host name') }}"{{ predefined_hostname == 'userdefined' ? ' required' }}>

{{ show_hint(t('When Host table is used, this field is ignored and values stored in Host table are used instead.')) }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigStorage/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@
* on_delete: string
* }
*/
public function getColumnFromForeignKeysData(array $foreignKeysData, string $column): array|false

Check failure on line 1378 in src/ConfigStorage/Relation.php

View workflow job for this annotation

GitHub Actions / lint-docs

The hint on "getColumnFromForeignKeysData" at @return is invalid: "false|array{ foreign_field: string, foreign_db: string, foreign_table: string|null, constraint: string|null, on_update: string, on_delete: string }" on "PhpMyAdmin\ConfigStorage\Relation::getColumnFromForeignKeysData"
{
$foreigner = [];
foreach ($foreignKeysData as $oneKey) {
Expand Down Expand Up @@ -1450,7 +1450,7 @@

Current::$message = Message::error($error);

if ($GLOBALS['errno'] === 1044) {
if (DatabaseInterface::$errorNumber === 1044) {
Current::$message = Message::error(sprintf(
__(
'You do not have necessary privileges to create a database named'
Expand Down
35 changes: 13 additions & 22 deletions src/Controllers/Database/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['table_select'] ??= null;
$GLOBALS['unlim_num_rows'] ??= null;

$this->pageSettings->init('Export');
$pageSettingsErrorHtml = $this->pageSettings->getErrorHTML();
$pageSettingsHtml = $this->pageSettings->getHTML();
Expand Down Expand Up @@ -68,10 +65,10 @@ public function __invoke(ServerRequest $request): Response
UrlParams::$params['goto'] = Url::getFromRoute('/database/export');

$tableNames = $this->export->getTableNames(Current::$database);
$GLOBALS['num_tables'] = count($tableNames);
Current::$numTables = count($tableNames);

// exit if no tables in db found
if ($GLOBALS['num_tables'] < 1) {
if (Current::$numTables < 1) {
$this->response->addHTML(
Message::error(__('No tables found in database.'))->getDisplay(),
);
Expand All @@ -80,30 +77,26 @@ public function __invoke(ServerRequest $request): Response
}

$selectedTable = $request->getParsedBodyParam('selected_tbl');
if (! empty($selectedTable) && empty($GLOBALS['table_select'])) {
$GLOBALS['table_select'] = $selectedTable;
}

$tableSelect = $request->getParsedBodyParam('table_select');
$tableStructure = $request->getParsedBodyParam('table_structure');
$tableData = $request->getParsedBodyParam('table_data');
$tablesForMultiValues = [];

foreach ($tableNames as $tableName) {
$tableSelect = $request->getParsedBodyParam('table_select');
if (is_array($tableSelect)) {
$isChecked = $this->export->getCheckedClause($tableName, $tableSelect);
} elseif (isset($GLOBALS['table_select'])) {
$isChecked = $this->export->getCheckedClause($tableName, $GLOBALS['table_select']);
} elseif (is_array($selectedTable)) {
$isChecked = $this->export->getCheckedClause($tableName, $selectedTable);
} else {
$isChecked = true;
}

$tableStructure = $request->getParsedBodyParam('table_structure');
if (is_array($tableStructure)) {
$structureChecked = $this->export->getCheckedClause($tableName, $tableStructure);
} else {
$structureChecked = $isChecked;
}

$tableData = $request->getParsedBodyParam('table_data');
if (is_array($tableData)) {
$dataChecked = $this->export->getCheckedClause($tableName, $tableData);
} else {
Expand All @@ -118,20 +111,18 @@ public function __invoke(ServerRequest $request): Response
];
}

if (! isset($GLOBALS['unlim_num_rows'])) {
$GLOBALS['unlim_num_rows'] = 0;
}

$isReturnBackFromRawExport = $request->getParsedBodyParam('export_type') === 'raw';
if ($request->hasBodyParam('raw_query') || $isReturnBackFromRawExport) {
$exportType = ExportType::Raw;
} else {
$exportType = ExportType::Database;
}

$GLOBALS['single_table'] = $request->getParam('single_table') ?? $GLOBALS['single_table'] ?? null;
if ($request->has('single_table')) {
Export::$singleTable = (bool) $request->getParam('single_table');
}

$exportList = Plugins::getExport($exportType, isset($GLOBALS['single_table']));
$exportList = Plugins::getExport($exportType, Export::$singleTable);

if ($exportList === []) {
$this->response->addHTML(Message::error(
Expand All @@ -146,8 +137,8 @@ public function __invoke(ServerRequest $request): Response
Current::$database,
Current::$table,
Current::$sqlQuery,
$GLOBALS['num_tables'],
$GLOBALS['unlim_num_rows'],
Current::$numTables,
0,
$exportList,
);

Expand Down
8 changes: 3 additions & 5 deletions src/Controllers/Database/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['SESSION_KEY'] ??= null;

$this->pageSettings->init('Import');
$pageSettingsErrorHtml = $this->pageSettings->getErrorHTML();
$pageSettingsHtml = $this->pageSettings->getHTML();
Expand All @@ -67,7 +65,7 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

[$GLOBALS['SESSION_KEY'], $uploadId] = Ajax::uploadProgressSetup();
[$uploadId] = Ajax::uploadProgressSetup();

ImportSettings::$importType = 'database';
$importList = Plugins::getImport();
Expand All @@ -91,7 +89,7 @@ public function __invoke(ServerRequest $request): Response

$charsets = Charsets::getCharsets($this->dbi, $config->selectedServer['DisableIS']);

$idKey = $_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getIdKey();
$idKey = $_SESSION[Ajax::SESSION_KEY]['handler']::getIdKey();
$hiddenInputs = [$idKey => $uploadId, 'import_type' => 'database', 'db' => Current::$database];

$default = $request->hasQueryParam('format')
Expand All @@ -107,7 +105,7 @@ public function __invoke(ServerRequest $request): Response
'page_settings_error_html' => $pageSettingsErrorHtml,
'page_settings_html' => $pageSettingsHtml,
'upload_id' => $uploadId,
'handler' => $_SESSION[$GLOBALS['SESSION_KEY']]['handler'],
'handler' => $_SESSION[Ajax::SESSION_KEY]['handler'],
'hidden_inputs' => $hiddenInputs,
'db' => Current::$database,
'table' => Current::$table,
Expand Down
9 changes: 7 additions & 2 deletions src/Controllers/Database/Structure/DropTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\ForeignKey;

Expand All @@ -28,7 +29,11 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['reload'] = $_POST['reload'] ?? $GLOBALS['reload'] ?? null;
if ($request->hasBodyParam('reload')) {
$reload = $request->getParsedBodyParamAsString('reload');
ResponseRenderer::$reload = $reload === '1' || $reload === 'true';
}

$multBtn = $_POST['mult_btn'] ?? '';
/** @var string[] $selected */
$selected = $_POST['selected'] ?? [];
Expand All @@ -55,7 +60,7 @@ public function __invoke(ServerRequest $request): Response
. Util::backquote($selectedValue);
}

$GLOBALS['reload'] = 1;
ResponseRenderer::$reload = true;
}

if (Current::$sqlQuery !== '') {
Expand Down
Loading
Loading