Refactor handleRollbackRequest()

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2024-04-06 17:12:35 +02:00
parent 938d6b516e
commit e447622a3d
4 changed files with 8 additions and 29 deletions

View File

@ -8545,11 +8545,6 @@ parameters:
count: 1
path: src/Import/Import.php
-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
count: 1
path: src/Import/Import.php
-
message: "#^Parameter \\#1 \\$precision of static method PhpMyAdmin\\\\Import\\\\DecimalSize\\:\\:fromPrecisionAndScale\\(\\) expects int, int\\|PhpMyAdmin\\\\Import\\\\DecimalSize given\\.$#"
count: 1

View File

@ -6680,7 +6680,6 @@
<code><![CDATA[$GLOBALS['result'] == false]]></code>
</RedundantCondition>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$error]]></code>
<code><![CDATA[ImportSettings::$runQuery]]></code>
</RiskyTruthyFalsyComparison>
</file>

View File

@ -712,12 +712,10 @@ final class ImportController extends AbstractController
}
// If there is request for ROLLBACK in the end.
if (! $request->hasBodyParam('rollback_query')) {
return null;
if ($request->hasBodyParam('rollback_query')) {
$this->dbi->query('ROLLBACK');
}
$this->dbi->query('ROLLBACK');
return null;
}
}

View File

@ -928,20 +928,10 @@ class Import
ImportSettings::$importNotice = $message;
}
/**
* Handles request for ROLLBACK.
*
* @param string $sqlQuery SQL query(s)
*/
public function handleRollbackRequest(string $sqlQuery): void
{
$sqlDelimiter = $_POST['sql_delimiter'];
$queries = explode($sqlDelimiter, $sqlQuery);
$error = false;
$errorMsg = __(
'Only INSERT, UPDATE, DELETE and REPLACE '
. 'SQL queries containing transactional engine tables can be rolled back.',
);
$dbi = DatabaseInterface::getInstance();
foreach ($queries as $sqlQuery) {
if ($sqlQuery === '') {
@ -953,17 +943,14 @@ class Import
continue;
}
$globalError = $dbi->getError();
$error = $globalError !== '' ? $globalError : $errorMsg;
$sqlError = $dbi->getError();
$error = $sqlError !== '' ? $sqlError : __(
'Only INSERT, UPDATE, DELETE and REPLACE '
. 'SQL queries containing transactional engine tables can be rolled back.',
);
break;
}
if ($error) {
unset($_POST['rollback_query']);
$response = ResponseRenderer::getInstance();
$message = Message::rawError($error);
$response->addJSON('message', $message);
$response->addJSON('message', Message::rawError($error));
$response->callExit();
}