Skip to content

Commit

Permalink
Merge pull request phpmyadmin#19438 from MauricioFauth/sql_query-glob…
Browse files Browse the repository at this point in the history
…al-replacing

Replace sql_query global var with Current::$sqlQuery
  • Loading branch information
MauricioFauth authored Dec 9, 2024
2 parents 40c5a13 + 7d6b17a commit c29067d
Show file tree
Hide file tree
Showing 59 changed files with 269 additions and 608 deletions.
344 changes: 16 additions & 328 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

36 changes: 7 additions & 29 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,6 @@
<PossiblyUnusedMethod>
<code><![CDATA[__construct]]></code>
</PossiblyUnusedMethod>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Controllers/Database/Structure/EmptyFormController.php">
<PossiblyUnusedMethod>
Expand Down Expand Up @@ -1502,9 +1499,6 @@
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['file_handle']]]></code>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$dbSelect]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
Expand Down Expand Up @@ -1646,9 +1640,6 @@
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['file_handle']]]></code>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
</PossiblyInvalidArgument>
Expand All @@ -1668,9 +1659,6 @@
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
</PossiblyInvalidCast>
Expand Down Expand Up @@ -1848,7 +1836,6 @@
<code><![CDATA[$request->getParsedBodyParamAsString('import_type', '')]]></code>
</PropertyTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($config->settings['MemoryLimit'])]]></code>
</RiskyTruthyFalsyComparison>
<UnusedProperty>
Expand Down Expand Up @@ -2079,9 +2066,6 @@
</PossiblyUnusedReturnValue>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($GLOBALS['message_to_show'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($createOptions['checksum'])]]></code>
<code><![CDATA[empty($createOptions['checksum'])]]></code>
<code><![CDATA[empty($createOptions['delay_key_write'])]]></code>
Expand Down Expand Up @@ -2781,10 +2765,7 @@
<code><![CDATA[$GLOBALS['disp_message'] ?? null]]></code>
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
<code><![CDATA[$GLOBALS['message_to_show'] ?? null]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$request->getQueryParam('sql_signature')]]></code>
<code><![CDATA[$sqlQuery]]></code>
<code><![CDATA[Current::$table]]></code>
</MixedArgument>
<MixedArrayAccess>
Expand All @@ -2796,12 +2777,13 @@
<code><![CDATA[$GLOBALS['disp_query']]]></code>
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
<code><![CDATA[$GLOBALS['message_to_show']]]></code>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$GLOBALS['unlim_num_rows']]]></code>
<code><![CDATA[$bkmAllUsers]]></code>
<code><![CDATA[$sqlQuery]]></code>
<code><![CDATA[$sqlQuery]]></code>
</MixedAssignment>
<PossiblyNullArgument>
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
</PossiblyNullArgument>
</file>
<file src="src/Controllers/Table/AddFieldController.php">
<InvalidArrayOffset>
Expand Down Expand Up @@ -2908,6 +2890,9 @@
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[Current::$sqlQuery]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[UrlParams::$params]]></code>
</MixedArgumentTypeCoercion>
Expand Down Expand Up @@ -3071,7 +3056,6 @@
<code><![CDATA[$parser->list]]></code>
</PossiblyNullArgument>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($GLOBALS['where_clause'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
Expand Down Expand Up @@ -3447,7 +3431,6 @@
</PossiblyUnusedReturnValue>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($GLOBALS['query'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($mimeMap[$columnName]['input_transformation'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
Expand Down Expand Up @@ -3934,7 +3917,6 @@
<code><![CDATA[$view['name']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[$db]]></code>
<code><![CDATA[$table]]></code>
</MixedAssignment>
Expand Down Expand Up @@ -6031,7 +6013,6 @@
</PossiblyUndefinedArrayOffset>
<RedundantCast>
<code><![CDATA[(string) $GLOBALS['display_query']]]></code>
<code><![CDATA[(string) $GLOBALS['sql_query']]]></code>
</RedundantCast>
<RiskyCast>
<code><![CDATA[$_REQUEST['pos']]]></code>
Expand All @@ -6044,8 +6025,6 @@
<code><![CDATA[empty($GLOBALS['show_as_php'])]]></code>
<code><![CDATA[empty($GLOBALS['show_as_php'])]]></code>
<code><![CDATA[empty($GLOBALS['show_as_php'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
<code><![CDATA[empty($server['socket'])]]></code>
<code><![CDATA[empty($server['ssl_ca'])]]></code>
</RiskyTruthyFalsyComparison>
Expand Down Expand Up @@ -6076,7 +6055,7 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<MixedArgument>
<code><![CDATA[$GLOBALS['sql_query']]]></code>
<code><![CDATA[Current::$sqlQuery]]></code>
</MixedArgument>
</file>
<file src="src/Http/Middleware/TokenRequestParamChecking.php">
Expand Down Expand Up @@ -6187,7 +6166,6 @@
</RedundantCondition>
<RiskyTruthyFalsyComparison>
<code><![CDATA[ImportSettings::$runQuery]]></code>
<code><![CDATA[empty($GLOBALS['sql_query'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Index.php">
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
sql_ignore: bool,
sql_insert_syntax: 'complete'|'extended'|'both'|'none',
sql_max_query_size: 0|positive-int,
sql_query: string,
sql_structure_or_data: 'structure'|'data'|'structure_and_data',
sql_type: 'INSERT'|'UPDATE'|'REPLACE',
tbl_storage_engine: string,
Expand Down
6 changes: 1 addition & 5 deletions src/Controllers/Database/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ public function __invoke(ServerRequest $request): Response
];
}

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

if (! isset($GLOBALS['unlim_num_rows'])) {
$GLOBALS['unlim_num_rows'] = 0;
}
Expand Down Expand Up @@ -157,7 +153,7 @@ public function __invoke(ServerRequest $request): Response
$exportType,
Current::$database,
Current::$table,
$GLOBALS['sql_query'],
Current::$sqlQuery,
$GLOBALS['num_tables'],
$GLOBALS['unlim_num_rows'],
$exportList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public function __invoke(ServerRequest $request): Response
/** @var string[] $selected */
$selected = $request->getParsedBodyParam('selected', []);

$GLOBALS['sql_query'] = '';
Current::$sqlQuery = '';

$this->dbi->selectDb(Current::$database);

foreach ($selected as $selectedValue) {
$newTableName = $request->getParsedBodyParamAsString('add_prefix', '') . $selectedValue;
$aQuery = 'ALTER TABLE ' . Util::backquote($selectedValue) . ' RENAME ' . Util::backquote($newTableName);

$GLOBALS['sql_query'] .= $aQuery . ';' . "\n";
Current::$sqlQuery .= $aQuery . ';' . "\n";
$this->dbi->query($aQuery);
}

Expand Down
14 changes: 7 additions & 7 deletions src/Controllers/Database/Structure/DropTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke(ServerRequest $request): Response
}

$defaultFkCheckValue = ForeignKey::handleDisableCheckInit();
$GLOBALS['sql_query'] = '';
Current::$sqlQuery = '';
$sqlQueryViews = '';

foreach ($selected as $selectedValue) {
Expand All @@ -51,17 +51,17 @@ public function __invoke(ServerRequest $request): Response
if ($this->dbi->getTable(Current::$database, $selectedValue)->isView()) {
$sqlQueryViews .= ($sqlQueryViews === '' ? 'DROP VIEW ' : ', ') . Util::backquote($selectedValue);
} else {
$GLOBALS['sql_query'] .= (empty($GLOBALS['sql_query']) ? 'DROP TABLE ' : ', ')
Current::$sqlQuery .= (Current::$sqlQuery === '' ? 'DROP TABLE ' : ', ')
. Util::backquote($selectedValue);
}

$GLOBALS['reload'] = 1;
}

if (! empty($GLOBALS['sql_query'])) {
$GLOBALS['sql_query'] .= ';';
if (Current::$sqlQuery !== '') {
Current::$sqlQuery .= ';';
} elseif ($sqlQueryViews !== '') {
$GLOBALS['sql_query'] = $sqlQueryViews . ';';
Current::$sqlQuery = $sqlQueryViews . ';';
$sqlQueryViews = '';
}

Expand All @@ -79,14 +79,14 @@ public function __invoke(ServerRequest $request): Response
$GLOBALS['message'] = Message::success();

$this->dbi->selectDb(Current::$database);
$result = $this->dbi->tryQuery($GLOBALS['sql_query']);
$result = $this->dbi->tryQuery(Current::$sqlQuery);

if (! $result) {
$GLOBALS['message'] = Message::error($this->dbi->getError());
}

if ($result && $sqlQueryViews !== '') {
$GLOBALS['sql_query'] .= ' ' . $sqlQueryViews . ';';
Current::$sqlQuery .= ' ' . $sqlQueryViews . ';';
$result = $this->dbi->tryQuery($sqlQueryViews);
unset($sqlQueryViews);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/Structure/EmptyTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __invoke(ServerRequest $request): Response

$defaultFkCheckValue = ForeignKey::handleDisableCheckInit();

$GLOBALS['sql_query'] = '';
Current::$sqlQuery = '';

$this->dbi->selectDb(Current::$database);

Expand All @@ -66,7 +66,7 @@ public function __invoke(ServerRequest $request): Response
$aQuery = 'TRUNCATE ';
$aQuery .= Util::backquote($selectedValue);

$GLOBALS['sql_query'] .= $aQuery . ';' . "\n";
Current::$sqlQuery .= $aQuery . ';' . "\n";
$this->dbi->query($aQuery);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke(ServerRequest $request): Response
$fromPrefix = $request->getParsedBodyParamAsString('from_prefix', '');
$toPrefix = $request->getParsedBodyParamAsString('to_prefix', '');

$GLOBALS['sql_query'] = '';
Current::$sqlQuery = '';

$this->dbi->selectDb(Current::$database);

Expand All @@ -51,13 +51,13 @@ public function __invoke(ServerRequest $request): Response
$aQuery = 'ALTER TABLE ' . Util::backquote($selectedValue)
. ' RENAME ' . Util::backquote($newTableName);

$GLOBALS['sql_query'] .= $aQuery . ';' . "\n";
Current::$sqlQuery .= $aQuery . ';' . "\n";
$this->dbi->query($aQuery);
}

$GLOBALS['message'] = Message::success();

$this->flashMessenger->addMessage('success', $GLOBALS['message']->getMessage(), $GLOBALS['sql_query']);
$this->flashMessenger->addMessage('success', $GLOBALS['message']->getMessage(), Current::$sqlQuery);

return $this->responseFactory->createResponse(StatusCodeInterface::STATUS_FOUND)
->withHeader('Location', Url::getFromRoute('/database/structure', ['db' => Current::$database]));
Expand Down
10 changes: 5 additions & 5 deletions src/Controllers/Export/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function __invoke(ServerRequest $request): Response
'table' => Current::$table,
]);
} elseif ($GLOBALS['export_type'] === 'raw') {
$GLOBALS['errorUrl'] = Url::getFromRoute('/server/export', ['sql_query' => $GLOBALS['sql_query']]);
$GLOBALS['errorUrl'] = Url::getFromRoute('/server/export', ['sql_query' => Current::$sqlQuery]);
} else {
$this->response->setRequestStatus(false);
$this->response->addHTML(Message::error(__('Bad parameters!'))->getDisplay());
Expand All @@ -189,7 +189,7 @@ public function __invoke(ServerRequest $request): Response
// Merge SQL Query aliases with Export aliases from
// export page, Export page aliases are given more
// preference over SQL Query aliases.
$parser = new Parser($GLOBALS['sql_query']);
$parser = new Parser(Current::$sqlQuery);
$aliases = [];
if (! empty($parser->statements[0]) && $parser->statements[0] instanceof SelectStatement) {
$aliases = $parser->statements[0]->getAliases(Current::$database);
Expand Down Expand Up @@ -426,7 +426,7 @@ public function __invoke(ServerRequest $request): Response
$exportPlugin,
$GLOBALS['errorUrl'],
Current::$database,
$GLOBALS['sql_query'],
Current::$sqlQuery,
);
} else {
// We export just one table
Expand All @@ -452,7 +452,7 @@ public function __invoke(ServerRequest $request): Response
$allrows,
$limitTo,
$limitFrom,
$GLOBALS['sql_query'],
Current::$sqlQuery,
$aliases,
);
} finally {
Expand All @@ -473,7 +473,7 @@ public function __invoke(ServerRequest $request): Response
$allrows,
$limitTo,
$limitFrom,
$GLOBALS['sql_query'],
Current::$sqlQuery,
$aliases,
);
}
Expand Down
Loading

0 comments on commit c29067d

Please sign in to comment.