Remove error global variable

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2025-01-06 23:17:58 -03:00
parent a6350ad8e0
commit 4b30f0eaaf
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
25 changed files with 80 additions and 191 deletions

View File

@ -2964,12 +2964,6 @@ parameters:
count: 1
path: src/Controllers/Import/ImportController.php
-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 5
path: src/Controllers/Import/ImportController.php
-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
@ -2994,12 +2988,6 @@ parameters:
count: 2
path: src/Controllers/Import/ImportController.php
-
message: '#^Parameter \#5 \$exit of static method PhpMyAdmin\\Html\\Generator\:\:mysqlDie\(\) expects bool, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Import/ImportController.php
-
message: '#^Result of \|\| is always true\.$#'
identifier: booleanOr.alwaysTrue
@ -3255,12 +3243,6 @@ parameters:
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: '#^Only booleans are allowed in an if condition, PhpMyAdmin\\Message\|string given\.$#'
identifier: if.condNotBoolean
count: 1
path: src/Controllers/Preferences/ManageController.php
-
message: '#^Only numeric types are allowed in \+, int\<0, max\>\|false given on the left side\.$#'
identifier: plus.leftNonNumeric
@ -9363,18 +9345,6 @@ parameters:
count: 1
path: src/Import/Import.php
-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Import/Import.php
-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
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\.$#'
identifier: argument.type
@ -12846,12 +12816,6 @@ parameters:
count: 1
path: src/Plugins/Import/ImportCsv.php
-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportCsv.php
-
message: '#^Parameter \#1 \$columnNames of method PhpMyAdmin\\Plugins\\Import\\ImportCsv\:\:getColumnNames\(\) expects list\<string\>, array\|null given\.$#'
identifier: argument.type
@ -12894,12 +12858,6 @@ parameters:
count: 1
path: src/Plugins/Import/ImportMediawiki.php
-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportMediawiki.php
-
message: '#^Cannot access property \$body on SimpleXMLElement\|null\.$#'
identifier: property.nonObject
@ -12960,12 +12918,6 @@ parameters:
count: 2
path: src/Plugins/Import/ImportOds.php
-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportOds.php
-
message: '#^Parameter \#1 \$cellAttrs of method PhpMyAdmin\\Plugins\\Import\\ImportOds\:\:getValue\(\) expects SimpleXMLElement, \(SimpleXMLElement\|null\) given\.$#'
identifier: argument.type
@ -13086,18 +13038,6 @@ parameters:
count: 1
path: src/Plugins/Import/ImportSql.php
-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 2
path: src/Plugins/Import/ImportSql.php
-
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
identifier: if.condNotBoolean
count: 1
path: src/Plugins/Import/ImportSql.php
-
message: '#^Parameter \#1 \$delimiter of method PhpMyAdmin\\SqlParser\\Utils\\BufferedQuery\:\:setDelimiter\(\) expects string, mixed given\.$#'
identifier: argument.type
@ -13158,12 +13098,6 @@ parameters:
count: 4
path: src/Plugins/Import/ImportXml.php
-
message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Plugins/Import/ImportXml.php
-
message: '#^Method PhpMyAdmin\\Plugins\\Import\\ShapeFileImport\:\:readSHP\(\) never returns false so it can be removed from the return type\.$#'
identifier: return.unusedType

View File

@ -1918,9 +1918,6 @@
<code><![CDATA[is_array($_FILES['import_file'])]]></code>
<code><![CDATA[is_string($_FILES['import_file']['tmp_name'])]]></code>
</RedundantCondition>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$GLOBALS['error']]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Controllers/Preferences/NavigationController.php">
<DeprecatedMethod>
@ -7529,9 +7526,6 @@
<code><![CDATA[$values[count($values) - 1]]]></code>
<code><![CDATA[$values[count($values) - 1]]]></code>
</InvalidArrayOffset>
<MixedAssignment>
<code><![CDATA[$GLOBALS['error']]]></code>
</MixedAssignment>
<PossiblyNullOperand>
<code><![CDATA[$ch]]></code>
</PossiblyNullOperand>

View File

@ -64,7 +64,6 @@ final class ImportController implements InvocableController
$GLOBALS['display_query'] ??= null;
$GLOBALS['ajax_reload'] ??= null;
$GLOBALS['import_text'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['result'] ??= null;
ImportSettings::$charsetOfFile = $request->getParsedBodyParamAsString('charset_of_file', '');
@ -240,7 +239,7 @@ final class ImportController implements InvocableController
// set default values
ImportSettings::$timeoutPassed = false;
$GLOBALS['error'] = false;
Import::$hasError = false;
ImportSettings::$readMultiply = 1;
ImportSettings::$finished = false;
ImportSettings::$offset = 0;
@ -333,7 +332,7 @@ final class ImportController implements InvocableController
}
ImportSettings::$runQuery = false;
$GLOBALS['error'] = true; // this is kind of hack to skip processing the query
Import::$hasError = true; // this is kind of hack to skip processing the query
break;
}
}
@ -394,7 +393,7 @@ final class ImportController implements InvocableController
// Do we have file to import?
if (ImportSettings::$importFile !== 'none' && ! $GLOBALS['error']) {
if (ImportSettings::$importFile !== 'none' && ! Import::$hasError) {
/**
* Handle file compression
*/
@ -431,7 +430,7 @@ final class ImportController implements InvocableController
return $this->response->response();
}
} elseif (! $GLOBALS['error'] && empty($GLOBALS['import_text'])) {
} elseif (! Import::$hasError && empty($GLOBALS['import_text'])) {
Current::$message = Message::error(
__(
'No data was received to import. Either no file name was ' .
@ -463,7 +462,7 @@ final class ImportController implements InvocableController
}
// Something to skip? (because timeout has passed)
if (! $GLOBALS['error'] && $request->hasBodyParam('skip')) {
if (! Import::$hasError && $request->hasBodyParam('skip')) {
$originalSkip = $skip = (int) $request->getParsedBodyParamAsStringOrNull('skip');
while ($skip > 0 && ! ImportSettings::$finished) {
$this->import->getNextChunk(
@ -482,7 +481,7 @@ final class ImportController implements InvocableController
// and complete valid sql statement (which affected for rows)
$queriesToBeExecuted = [];
if (! $GLOBALS['error']) {
if (! Import::$hasError) {
$importPlugin = new ($importFormat->getClassName());
$importPlugin->setImportOptions($request);
@ -513,10 +512,10 @@ final class ImportController implements InvocableController
if ($idBookmark !== 0 && $actionBookmark === 2) {
Current::$message = Message::success(__('The bookmark has been deleted.'));
$GLOBALS['display_query'] = $GLOBALS['import_text'];
$GLOBALS['error'] = false; // unset error marker, it was used just to skip processing
Import::$hasError = false; // unset error marker, it was used just to skip processing
} elseif ($idBookmark !== 0 && $actionBookmark === 1) {
Current::$message = Message::notice(__('Showing bookmark'));
} elseif (ImportSettings::$finished && ! $GLOBALS['error']) {
} elseif (ImportSettings::$finished && ! Import::$hasError) {
// Do not display the query with message, we do it separately
$GLOBALS['display_query'] = ';';
if (ImportSettings::$importType !== 'query') {
@ -604,7 +603,7 @@ final class ImportController implements InvocableController
}
foreach (ImportSettings::$failedQueries as $die) {
Generator::mysqlDie($die['error'], $die['sql'], false, $GLOBALS['errorUrl'], $GLOBALS['error']);
Generator::mysqlDie($die['error'], $die['sql'], false, $GLOBALS['errorUrl'], Import::$hasError);
}
if (ImportSettings::$goSql) {

View File

@ -35,8 +35,6 @@ final class ExportController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
@ -50,7 +48,7 @@ final class ExportController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
@ -66,8 +64,6 @@ final class ExportController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
}
$relationParameters = $this->relation->getRelationParameters();
@ -81,7 +77,7 @@ final class ExportController implements InvocableController
$formErrors = $formDisplay->displayErrors();
$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(

View File

@ -35,8 +35,6 @@ final class FeaturesController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
@ -50,7 +48,7 @@ final class FeaturesController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
@ -66,8 +64,6 @@ final class FeaturesController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
}
$relationParameters = $this->relation->getRelationParameters();
@ -81,7 +77,7 @@ final class FeaturesController implements InvocableController
$formErrors = $formDisplay->displayErrors();
$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(

View File

@ -35,8 +35,6 @@ final class ImportController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
@ -50,7 +48,7 @@ final class ImportController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
@ -66,8 +64,6 @@ final class ImportController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
}
$relationParameters = $this->relation->getRelationParameters();
@ -81,7 +77,7 @@ final class ImportController implements InvocableController
$formErrors = $formDisplay->displayErrors();
$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(

View File

@ -35,8 +35,6 @@ final class MainPanelController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
@ -50,7 +48,7 @@ final class MainPanelController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
@ -66,8 +64,6 @@ final class MainPanelController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
}
$relationParameters = $this->relation->getRelationParameters();
@ -81,7 +77,7 @@ final class MainPanelController implements InvocableController
$formErrors = $formDisplay->displayErrors();
$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(

View File

@ -59,14 +59,12 @@ final class ManageController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;
$route = $request->getRoute();
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
$GLOBALS['error'] = '';
$error = null;
if ($request->hasBodyParam('submit_export') && $request->getParsedBodyParam('export_type') === 'text_file') {
// export to JSON file
$response = $this->responseFactory->createResponse();
@ -118,7 +116,7 @@ final class ManageController implements InvocableController
$importHandle = new File($_FILES['import_file']['tmp_name']);
$importHandle->checkUploadedFile();
if ($importHandle->isError()) {
$GLOBALS['error'] = $importHandle->getError();
$error = $importHandle->getError();
} else {
// read JSON from uploaded file
$json = $importHandle->getRawContent();
@ -134,8 +132,8 @@ final class ManageController implements InvocableController
$configuration = json_decode($json, true);
$returnUrl = $request->getParsedBodyParamAsStringOrNull('return_url');
if (! is_array($configuration)) {
if (! isset($GLOBALS['error'])) {
$GLOBALS['error'] = __('Could not import configuration');
if ($error === null) {
$error = Message::error(__('Could not import configuration'));
}
} else {
// sanitize input values: treat them as though
@ -224,7 +222,7 @@ final class ManageController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
$error = $result;
}
} elseif ($request->hasBodyParam('submit_clear')) {
$result = $this->userPreferences->save([]);
@ -235,8 +233,6 @@ final class ManageController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
return $this->response->response();
}
@ -248,16 +244,8 @@ final class ManageController implements InvocableController
'has_config_storage' => $relationParameters->userPreferencesFeature !== null,
]);
if ($GLOBALS['error']) {
if (! $GLOBALS['error'] instanceof Message) {
$GLOBALS['error'] = Message::error($GLOBALS['error']);
}
$GLOBALS['error']->getDisplay();
}
$this->response->render('preferences/manage/main', [
'error' => $GLOBALS['error'],
'error' => $error instanceof Message ? $error->getDisplay() : '',
'max_upload_size' => Config::getInstance()->get('max_upload_size'),
'exists_setup_and_not_exists_config' => @file_exists(ROOT_PATH . 'setup/index.php')
&& ! @file_exists(CONFIG_FILE),

View File

@ -35,8 +35,6 @@ final class NavigationController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
@ -50,7 +48,7 @@ final class NavigationController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
@ -66,8 +64,6 @@ final class NavigationController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
}
$relationParameters = $this->relation->getRelationParameters();
@ -81,7 +77,7 @@ final class NavigationController implements InvocableController
$formErrors = $formDisplay->displayErrors();
$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(

View File

@ -35,8 +35,6 @@ final class SqlController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['error'] ??= null;
$configFile = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($configFile);
@ -50,7 +48,7 @@ final class SqlController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = null;
$result = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor(Config::getInstance()->selectedServer['user']);
@ -66,8 +64,6 @@ final class SqlController implements InvocableController
return $this->response->response();
}
$GLOBALS['error'] = $result;
}
$relationParameters = $this->relation->getRelationParameters();
@ -81,7 +77,7 @@ final class SqlController implements InvocableController
$formErrors = $formDisplay->displayErrors();
$this->response->render('preferences/forms/main', [
'error' => $GLOBALS['error'] instanceof Message ? $GLOBALS['error']->getDisplay() : '',
'error' => $result instanceof Message ? $result->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors,
'form' => $formDisplay->getDisplay(

View File

@ -61,6 +61,7 @@ use function trim;
class Import
{
private string|null $importRunBuffer = null;
public static bool $hasError = false;
public function __construct()
{
@ -100,7 +101,6 @@ class Import
*/
public function executeQuery(string $sql, array &$sqlData): void
{
$GLOBALS['error'] ??= null;
$dbi = DatabaseInterface::getInstance();
$GLOBALS['result'] = $dbi->tryQuery($sql);
@ -115,7 +115,7 @@ class Import
ImportSettings::$message .= __('Error');
if (! Config::getInstance()->settings['IgnoreMultiSubmitErrors']) {
$GLOBALS['error'] = true;
self::$hasError = true;
return;
}
@ -219,13 +219,13 @@ class Import
foreach ($queries as $query) {
$this->executeQuery($query, $sqlData);
if ($GLOBALS['error']) {
if (self::$hasError) {
break;
}
}
}
if (! $GLOBALS['error']) {
if (! self::$hasError) {
$this->executeQuery($this->importRunBuffer, $sqlData);
}
}

View File

@ -14,6 +14,7 @@ use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Import\ImportTable;
use PhpMyAdmin\Message;
@ -191,15 +192,13 @@ class ImportCsv extends AbstractImportCsv
*/
public function doImport(File|null $importHandle = null): array
{
$GLOBALS['error'] ??= null;
$replacements = ['\\n' => "\n", '\\t' => "\t", '\\r' => "\r"];
$this->terminated = strtr($this->terminated, $replacements);
$this->enclosed = strtr($this->enclosed, $replacements);
$this->escaped = strtr($this->escaped, $replacements);
$this->newLine = strtr($this->newLine, $replacements);
[$GLOBALS['error'], Current::$message] = $this->buildErrorsForParams(
[Import::$hasError, Current::$message] = $this->buildErrorsForParams(
$this->terminated,
$this->enclosed,
$this->escaped,
@ -235,7 +234,7 @@ class ImportCsv extends AbstractImportCsv
$maxCols = 0;
$csvTerminatedLen = mb_strlen($this->terminated);
$dbi = DatabaseInterface::getInstance();
while (! (ImportSettings::$finished && $i >= $len) && ! $GLOBALS['error'] && ! ImportSettings::$timeoutPassed) {
while (! (ImportSettings::$finished && $i >= $len) && ! Import::$hasError && ! ImportSettings::$timeoutPassed) {
$data = $this->import->getNextChunk($importHandle);
if ($data === false) {
// subtract data we didn't handle yet and stop processing
@ -288,7 +287,7 @@ class ImportCsv extends AbstractImportCsv
__('Invalid format of CSV input on line %d.'),
);
Current::$message->addParam($line);
$GLOBALS['error'] = true;
Import::$hasError = true;
break;
}
@ -496,7 +495,7 @@ class ImportCsv extends AbstractImportCsv
),
);
Current::$message->addParam($line);
$GLOBALS['error'] = true;
Import::$hasError = true;
break;
}
@ -604,7 +603,7 @@ class ImportCsv extends AbstractImportCsv
// Commit any possible data in buffers
$this->import->runQuery('', $sqlStatements);
if ($values === [] || $GLOBALS['error'] !== false) {
if ($values === [] || Import::$hasError !== false) {
return $sqlStatements;
}
@ -612,12 +611,12 @@ class ImportCsv extends AbstractImportCsv
__('Invalid format of CSV input on line %d.'),
);
Current::$message->addParam($line);
$GLOBALS['error'] = true;
Import::$hasError = true;
return $sqlStatements;
}
/** @return array{mixed, Message|null} */
/** @return array{bool, Message|null} */
private function buildErrorsForParams(
string $csvTerminated,
string $csvEnclosed,
@ -625,15 +624,13 @@ class ImportCsv extends AbstractImportCsv
string $csvNewLine,
string $errUrl,
): array {
$GLOBALS['error'] ??= null;
$paramError = false;
if ($csvTerminated === '') {
Current::$message = Message::error(
__('Invalid parameter for CSV import: %s'),
);
Current::$message->addParam(__('Columns terminated with'));
$GLOBALS['error'] = true;
Import::$hasError = true;
$paramError = true;
// The default dialog of MS Excel when generating a CSV produces a
// semi-colon-separated file with no chance of specifying the
@ -648,7 +645,7 @@ class ImportCsv extends AbstractImportCsv
__('Invalid parameter for CSV import: %s'),
);
Current::$message->addParam(__('Columns enclosed with'));
$GLOBALS['error'] = true;
Import::$hasError = true;
$paramError = true;
// I could not find a test case where having no escaping characters
// confuses this script.
@ -659,14 +656,14 @@ class ImportCsv extends AbstractImportCsv
__('Invalid parameter for CSV import: %s'),
);
Current::$message->addParam(__('Columns escaped with'));
$GLOBALS['error'] = true;
Import::$hasError = true;
$paramError = true;
} elseif (mb_strlen($csvNewLine) != 1 && $csvNewLine !== 'auto') {
Current::$message = Message::error(
__('Invalid parameter for CSV import: %s'),
);
Current::$message->addParam(__('Lines terminated with'));
$GLOBALS['error'] = true;
Import::$hasError = true;
$paramError = true;
}
@ -681,7 +678,7 @@ class ImportCsv extends AbstractImportCsv
);
}
return [$GLOBALS['error'], Current::$message];
return [Import::$hasError, Current::$message];
}
private function getTableNameFromImport(string $databaseName): string
@ -726,8 +723,6 @@ class ImportCsv extends AbstractImportCsv
string|null $table,
string $csvColumns,
): array {
$GLOBALS['error'] ??= null;
$sqlTemplate = '';
$fields = [];
if (! $this->analyze && $db !== null && $table !== null) {
@ -766,7 +761,7 @@ class ImportCsv extends AbstractImportCsv
),
);
Current::$message->addParam($val);
$GLOBALS['error'] = true;
Import::$hasError = true;
break;
}

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Message;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
@ -124,7 +125,7 @@ class ImportLdi extends AbstractImportCsv
Current::$message = Message::error(
__('This plugin does not support compressed imports!'),
);
$GLOBALS['error'] = true;
Import::$hasError = true;
return [];
}

View File

@ -10,6 +10,7 @@ namespace PhpMyAdmin\Plugins\Import;
use PhpMyAdmin\Current;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Import\ImportTable;
use PhpMyAdmin\Message;
@ -74,8 +75,6 @@ class ImportMediawiki extends ImportPlugin
*/
public function doImport(File|null $importHandle = null): array
{
$GLOBALS['error'] ??= null;
$sqlStatements = [];
// Defaults for parser
@ -106,7 +105,7 @@ class ImportMediawiki extends ImportPlugin
$inTableHeader = false;
/** @infection-ignore-all */
while (! ImportSettings::$finished && ! $GLOBALS['error'] && ! ImportSettings::$timeoutPassed) {
while (! ImportSettings::$finished && ! Import::$hasError && ! ImportSettings::$timeoutPassed) {
$data = $this->import->getNextChunk($importHandle);
if ($data === false) {
@ -278,7 +277,7 @@ class ImportMediawiki extends ImportPlugin
__('Invalid format of mediawiki input on line: <br>%s.'),
);
$message->addParam($curBufferLine);
$GLOBALS['error'] = true;
Import::$hasError = true;
}
}
}

View File

@ -13,6 +13,7 @@ namespace PhpMyAdmin\Plugins\Import;
use PhpMyAdmin\Current;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Import\ImportTable;
use PhpMyAdmin\Message;
@ -117,8 +118,6 @@ class ImportOds extends ImportPlugin
*/
public function doImport(File|null $importHandle = null): array
{
$GLOBALS['error'] ??= null;
$sqlStatements = [];
$buffer = '';
@ -126,7 +125,7 @@ class ImportOds extends ImportPlugin
* Read in the file via Import::getNextChunk so that
* it can process compressed files
*/
while (! ImportSettings::$finished && ! $GLOBALS['error'] && ! ImportSettings::$timeoutPassed) {
while (! ImportSettings::$finished && ! Import::$hasError && ! ImportSettings::$timeoutPassed) {
$data = $this->import->getNextChunk($importHandle);
if ($data === false) {
/* subtract data we didn't handle yet and stop processing */
@ -158,7 +157,7 @@ class ImportOds extends ImportPlugin
Current::$message = Message::error(__(
'The XML file specified was either malformed or incomplete. Please correct the issue and try again.',
));
$GLOBALS['error'] = true;
Import::$hasError = true;
} else {
$root = $xml->children('office', true)->body->spreadsheet;
if ($root === null) {
@ -166,7 +165,7 @@ class ImportOds extends ImportPlugin
Current::$message = Message::error(
__('Could not parse OpenDocument Spreadsheet!'),
);
$GLOBALS['error'] = true;
Import::$hasError = true;
} else {
$sheets = $root->children('table', true);
}

View File

@ -87,7 +87,6 @@ class ImportShp extends ImportPlugin
*/
public function doImport(File|null $importHandle = null): array
{
$GLOBALS['error'] ??= null;
ImportSettings::$finished = false;
if ($importHandle === null || $this->zipExtension === null) {
@ -173,7 +172,7 @@ class ImportShp extends ImportPlugin
}
if ($shp->lastError != '') {
$GLOBALS['error'] = true;
Import::$hasError = true;
Current::$message = Message::error(
__('There was an error importing the ESRI shape file: "%s".'),
);
@ -198,7 +197,7 @@ class ImportShp extends ImportPlugin
$gisType = 'multipoint';
break;
default:
$GLOBALS['error'] = true;
Import::$hasError = true;
Current::$message = Message::error(
__('MySQL Spatial Extension does not support ESRI type "%s".'),
);
@ -243,7 +242,7 @@ class ImportShp extends ImportPlugin
}
if ($rows === []) {
$GLOBALS['error'] = true;
Import::$hasError = true;
Current::$message = Message::error(
__('The imported file does not contain any data!'),
);
@ -296,7 +295,7 @@ class ImportShp extends ImportPlugin
$this->import->buildSql($dbName, [$table], [$analysis], sqlData: $sqlStatements);
ImportSettings::$finished = true;
$GLOBALS['error'] = false;
Import::$hasError = false;
// Commit any possible data in buffers
$this->import->runQuery('', $sqlStatements);

View File

@ -10,6 +10,7 @@ namespace PhpMyAdmin\Plugins\Import;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\ImportPlugin;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@ -95,8 +96,6 @@ class ImportSql extends ImportPlugin
*/
public function doImport(File|null $importHandle = null): array
{
$GLOBALS['error'] ??= null;
// Handle compatibility options.
$this->setSQLMode(DatabaseInterface::getInstance(), $_REQUEST);
@ -112,7 +111,7 @@ class ImportSql extends ImportPlugin
$sqlStatements = [];
while (! $GLOBALS['error'] && ! ImportSettings::$timeoutPassed) {
while (! Import::$hasError && ! ImportSettings::$timeoutPassed) {
// Getting the first statement, the remaining data and the last
// delimiter.
$statement = $bq->extract();
@ -148,7 +147,7 @@ class ImportSql extends ImportPlugin
// Extracting remaining statements.
/** @infection-ignore-all */
while (! $GLOBALS['error'] && ! ImportSettings::$timeoutPassed && ! empty($bq->query)) {
while (! Import::$hasError && ! ImportSettings::$timeoutPassed && ! empty($bq->query)) {
$statement = $bq->extract(true);
if ($statement === false || $statement === '') {
continue;
@ -157,7 +156,7 @@ class ImportSql extends ImportPlugin
$this->import->runQuery($statement, $sqlStatements);
}
if ($GLOBALS['error']) {
if (Import::$hasError) {
return $sqlStatements;
}

View File

@ -12,6 +12,7 @@ namespace PhpMyAdmin\Plugins\Import;
use PhpMyAdmin\Current;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Import\ImportTable;
use PhpMyAdmin\Message;
@ -63,8 +64,6 @@ class ImportXml extends ImportPlugin
*/
public function doImport(File|null $importHandle = null): array
{
$GLOBALS['error'] ??= null;
$xml = $this->getFileAsSimpleXmlElement($importHandle);
/**
@ -244,7 +243,7 @@ class ImportXml extends ImportPlugin
* it can process compressed files
*/
/** @infection-ignore-all */
while (! ImportSettings::$finished && ! $GLOBALS['error'] && ! ImportSettings::$timeoutPassed) {
while (! ImportSettings::$finished && ! Import::$hasError && ! ImportSettings::$timeoutPassed) {
$data = $this->import->getNextChunk($importHandle);
if ($data === false) {
/* subtract data we didn't handle yet and stop processing */

View File

@ -8,6 +8,7 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\Import\ImportCsv;
use PhpMyAdmin\Tests\AbstractTestCase;
@ -31,7 +32,7 @@ class ImportCsvTest extends AbstractTestCase
parent::setUp();
$GLOBALS['errorUrl'] = 'index.php?route=/';
$GLOBALS['error'] = false;
Import::$hasError = false;
Current::$database = '';
Current::$table = '';
Current::$sqlQuery = '';

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins\Import\ImportLdi;
@ -31,6 +32,7 @@ class ImportLdiTest extends AbstractTestCase
{
parent::setUp();
Import::$hasError = false;
ImportSettings::$charsetConversion = false;
ImportSettings::$maxSqlLength = 0;
Current::$sqlQuery = '';
@ -151,7 +153,7 @@ class ImportLdiTest extends AbstractTestCase
Current::$message->__toString(),
);
self::assertTrue($GLOBALS['error']);
self::assertTrue(Import::$hasError);
}
/**

View File

@ -7,6 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Import;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\Import\ImportMediawiki;
use PhpMyAdmin\Tests\AbstractTestCase;
@ -29,7 +30,7 @@ class ImportMediawikiTest extends AbstractTestCase
{
parent::setUp();
$GLOBALS['error'] = null;
Import::$hasError = false;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
ImportSettings::$charsetConversion = false;

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\Import\ImportOds;
use PhpMyAdmin\Tests\AbstractTestCase;
@ -35,7 +36,7 @@ class ImportOdsTest extends AbstractTestCase
{
parent::setUp();
$GLOBALS['error'] = null;
Import::$hasError = false;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
ImportSettings::$charsetConversion = false;

View File

@ -7,6 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Import;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\Import\ImportShp;
use PhpMyAdmin\Tests\AbstractTestCase;
@ -33,7 +34,6 @@ class ImportShpTest extends AbstractTestCase
{
parent::setUp();
$GLOBALS['error'] = null;
ImportSettings::$maximumTime = 0;
ImportSettings::$charsetConversion = false;
$GLOBALS['eof'] = null;
@ -75,10 +75,10 @@ class ImportShpTest extends AbstractTestCase
$importHandle->open();
Current::$message = null;
$GLOBALS['error'] = false;
Import::$hasError = false;
$this->object->doImport($importHandle);
self::assertNull(Current::$message);
self::assertFalse($GLOBALS['error']);
self::assertFalse(Import::$hasError);
}
/**

View File

@ -7,6 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Import;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\Import\ImportSql;
use PhpMyAdmin\Tests\AbstractTestCase;
@ -27,7 +28,7 @@ class ImportSqlTest extends AbstractTestCase
{
parent::setUp();
$GLOBALS['error'] = null;
Import::$hasError = false;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
ImportSettings::$charsetConversion = false;

View File

@ -7,6 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Import;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\Import\ImportXml;
use PhpMyAdmin\Tests\AbstractTestCase;
@ -32,7 +33,7 @@ class ImportXmlTest extends AbstractTestCase
{
parent::setUp();
$GLOBALS['error'] = null;
Import::$hasError = false;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
ImportSettings::$charsetConversion = false;