Remove the errno global variable
Replaces it with DatabaseInterface::$errorNumber static property. Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
parent
0669a17827
commit
f5d99cec89
@ -10845,12 +10845,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Plugins/Auth/AuthenticationConfig.php
|
||||
|
||||
-
|
||||
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
|
||||
identifier: notEqual.notAllowed
|
||||
count: 2
|
||||
path: src/Plugins/Auth/AuthenticationConfig.php
|
||||
|
||||
-
|
||||
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
|
||||
identifier: equal.notAllowed
|
||||
@ -11034,12 +11028,6 @@ parameters:
|
||||
count: 4
|
||||
path: src/Plugins/Auth/AuthenticationHttp.php
|
||||
|
||||
-
|
||||
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
|
||||
identifier: notEqual.notAllowed
|
||||
count: 1
|
||||
path: src/Plugins/Auth/AuthenticationHttp.php
|
||||
|
||||
-
|
||||
message: '#^Only booleans are allowed in &&, string given on the left side\.$#'
|
||||
identifier: booleanAnd.leftNotBoolean
|
||||
@ -11127,12 +11115,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Plugins/Auth/AuthenticationSignon.php
|
||||
|
||||
-
|
||||
message: '#^Binary operation "\." between ''\#'' and mixed results in an error\.$#'
|
||||
identifier: binaryOp.invalid
|
||||
count: 1
|
||||
path: src/Plugins/AuthenticationPlugin.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
|
||||
|
||||
@ -43,7 +43,6 @@
|
||||
charset: string,
|
||||
complete_query: string,
|
||||
compression: 'none'|'zip'|'gzip',
|
||||
errno: int,
|
||||
file_handle: resource|null,
|
||||
from_cookie: bool,
|
||||
knjenc: string,
|
||||
|
||||
@ -1450,7 +1450,7 @@ class Relation
|
||||
|
||||
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'
|
||||
|
||||
@ -142,6 +142,8 @@ class DatabaseInterface
|
||||
/** @var int|numeric-string */
|
||||
private static int|string $cachedAffectedRows = -1;
|
||||
|
||||
public static int|null $errorNumber = null;
|
||||
|
||||
/** @param DbiExtension $extension Object to be used for database queries */
|
||||
private function __construct(private DbiExtension $extension, private readonly Config $config)
|
||||
{
|
||||
@ -665,7 +667,7 @@ class DatabaseInterface
|
||||
$databases = $this->fetchResult($sql, 'SCHEMA_NAME', null, $connectionType);
|
||||
|
||||
$mysqlError = $this->getError($connectionType);
|
||||
if ($databases === [] && isset($GLOBALS['errno'])) {
|
||||
if ($databases === [] && self::$errorNumber !== null) {
|
||||
Generator::mysqlDie($mysqlError, $sql);
|
||||
}
|
||||
|
||||
|
||||
@ -235,7 +235,7 @@ class DbiMysqli implements DbiExtension
|
||||
*/
|
||||
public function getError(Connection $connection): string
|
||||
{
|
||||
$GLOBALS['errno'] = 0;
|
||||
DatabaseInterface::$errorNumber = 0;
|
||||
|
||||
/** @var mysqli $mysqli */
|
||||
$mysqli = $connection->connection;
|
||||
@ -249,7 +249,7 @@ class DbiMysqli implements DbiExtension
|
||||
|
||||
// keep the error number for further check after
|
||||
// the call to getError()
|
||||
$GLOBALS['errno'] = $errorNumber;
|
||||
DatabaseInterface::$errorNumber = $errorNumber;
|
||||
|
||||
return Utilities::formatError($errorNumber, $errorMessage);
|
||||
}
|
||||
|
||||
@ -111,9 +111,9 @@ class AuthenticationConfig extends AuthenticationPlugin
|
||||
'</a>',
|
||||
) , '</p>' , "\n";
|
||||
} elseif (
|
||||
! isset($GLOBALS['errno'])
|
||||
|| $GLOBALS['errno'] != 2002
|
||||
&& $GLOBALS['errno'] != 2003
|
||||
DatabaseInterface::$errorNumber === null
|
||||
|| DatabaseInterface::$errorNumber !== 2002
|
||||
&& DatabaseInterface::$errorNumber !== 2003
|
||||
) {
|
||||
// if we display the "Server not responding" error, do not confuse
|
||||
// users by telling them they have a settings problem
|
||||
|
||||
@ -177,7 +177,7 @@ class AuthenticationHttp extends AuthenticationPlugin
|
||||
$this->logFailure($failure);
|
||||
|
||||
$error = DatabaseInterface::getInstance()->getError();
|
||||
if ($error && $GLOBALS['errno'] != 1045) {
|
||||
if ($error && DatabaseInterface::$errorNumber !== 1045) {
|
||||
$responseRenderer = ResponseRenderer::getInstance();
|
||||
$responseRenderer->addHTML($this->template->render('error/generic', [
|
||||
'lang' => Current::$lang,
|
||||
|
||||
@ -170,8 +170,8 @@ abstract class AuthenticationPlugin
|
||||
return htmlspecialchars($dbiError);
|
||||
}
|
||||
|
||||
if (isset($GLOBALS['errno'])) {
|
||||
return '#' . $GLOBALS['errno'] . ' ' . $failure->getMessage();
|
||||
if (DatabaseInterface::$errorNumber !== null) {
|
||||
return '#' . DatabaseInterface::$errorNumber . ' ' . $failure->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -958,7 +958,7 @@ class RelationTest extends AbstractTestCase
|
||||
$dummyDbi->addErrorCode('MYSQL_ERROR');
|
||||
$dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', false);
|
||||
|
||||
$GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR
|
||||
DatabaseInterface::$errorNumber = 1044;// ER_DBACCESS_DENIED_ERROR
|
||||
|
||||
self::assertFalse(
|
||||
$relation->createPmaDatabase('phpmyadmin'),
|
||||
@ -986,7 +986,7 @@ class RelationTest extends AbstractTestCase
|
||||
$dummyDbi->addErrorCode('Too many connections');
|
||||
$dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `pma_1040`', false);
|
||||
|
||||
$GLOBALS['errno'] = 1040;
|
||||
DatabaseInterface::$errorNumber = 1040;
|
||||
|
||||
self::assertFalse(
|
||||
$relation->createPmaDatabase('pma_1040'),
|
||||
|
||||
@ -770,7 +770,7 @@ class AuthenticationCookieTest extends AbstractTestCase
|
||||
->willReturn('');
|
||||
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
$GLOBALS['errno'] = 42;
|
||||
DatabaseInterface::$errorNumber = 42;
|
||||
|
||||
$responseStub = new ResponseRendererStub();
|
||||
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub);
|
||||
@ -811,7 +811,7 @@ class AuthenticationCookieTest extends AbstractTestCase
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
$_COOKIE['pmaAuth-2'] = 'pass';
|
||||
|
||||
unset($GLOBALS['errno']);
|
||||
DatabaseInterface::$errorNumber = null;
|
||||
|
||||
$responseStub = new ResponseRendererStub();
|
||||
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub);
|
||||
|
||||
@ -265,7 +265,7 @@ class AuthenticationHttpTest extends AbstractTestCase
|
||||
->willReturn('error 123', 'error 321', '');
|
||||
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
$GLOBALS['errno'] = 31;
|
||||
DatabaseInterface::$errorNumber = 31;
|
||||
|
||||
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
|
||||
ResponseRenderer::getInstance()->setAjax(false);
|
||||
@ -277,7 +277,7 @@ class AuthenticationHttpTest extends AbstractTestCase
|
||||
|
||||
// case 2
|
||||
$config->selectedServer['host'] = 'host';
|
||||
$GLOBALS['errno'] = 1045;
|
||||
DatabaseInterface::$errorNumber = 1045;
|
||||
|
||||
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
|
||||
ResponseRenderer::getInstance()->setAjax(false);
|
||||
@ -290,7 +290,7 @@ class AuthenticationHttpTest extends AbstractTestCase
|
||||
ResponseRenderer::getInstance()->setAjax(false);
|
||||
|
||||
// case 3
|
||||
$GLOBALS['errno'] = 1043;
|
||||
DatabaseInterface::$errorNumber = 1043;
|
||||
$response = $this->object->showFailure(AuthenticationFailure::deniedByDatabaseServer());
|
||||
$result = (string) $response->getBody();
|
||||
self::assertStringContainsString('Wrong username/password. Access denied.', $result);
|
||||
|
||||
@ -344,7 +344,7 @@ class AuthenticationSignonTest extends AbstractTestCase
|
||||
{
|
||||
Config::getInstance()->selectedServer['SignonSession'] = 'newSession';
|
||||
$_COOKIE['newSession'] = '42';
|
||||
unset($GLOBALS['errno']);
|
||||
DatabaseInterface::$errorNumber = null;
|
||||
|
||||
$this->object = $this->getMockBuilder(AuthenticationSignon::class)
|
||||
->disableOriginalConstructor()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user