Skip to content

Commit 5c5e8c2

Browse files
committed
Replace $GLOBALS['cfg']['MysqlMinVersion'] in Common class
Replaces with PhpMyAdmin\Config\Settings::$mysqlMinVersion access. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 92abb0c commit 5c5e8c2

8 files changed

Lines changed: 59 additions & 15 deletions

File tree

‎libraries/classes/Common.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public static function run(bool $isSetupPage = false): void
184184
self::setCurrentServerGlobal($container, $config);
185185

186186
$GLOBALS['cfg'] = $config->settings;
187+
$settings = $config->getSettings();
187188

188189
/* setup themes LABEL_theme_setup */
189190

@@ -253,11 +254,11 @@ public static function run(bool $isSetupPage = false): void
253254
/* Log success */
254255
Logging::logUser($GLOBALS['cfg']['Server']['user']);
255256

256-
if ($GLOBALS['dbi']->getVersion() < $GLOBALS['cfg']['MysqlMinVersion']['internal']) {
257+
if ($GLOBALS['dbi']->getVersion() < $settings->mysqlMinVersion['internal']) {
257258
echo self::getGenericError(sprintf(
258259
__('You should upgrade to %s %s or later.'),
259260
'MySQL',
260-
(string) $GLOBALS['cfg']['MysqlMinVersion']['human'],
261+
$settings->mysqlMinVersion['human'],
261262
));
262263

263264
return;

‎libraries/classes/Config.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class Config
9292
/** @var array */
9393
public array $defaultServer = [];
9494

95+
private Settings|null $config = null;
96+
9597
/**
9698
* @param string|null $source source to read config from
9799
*
@@ -1320,4 +1322,13 @@ public function getLoginCookieValidityFromCache(int $server): void
13201322
$this->set('LoginCookieValidity', $value);
13211323
$GLOBALS['cfg']['LoginCookieValidity'] = $value;
13221324
}
1325+
1326+
public function getSettings(): Settings
1327+
{
1328+
if ($this->config === null) {
1329+
$this->config = new Settings($this->settings);
1330+
}
1331+
1332+
return $this->config;
1333+
}
13231334
}

‎libraries/classes/Config/Settings.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ final class Settings
23672367
* @var array<string, int|string>
23682368
* @psalm-var array{internal: int, human: string}
23692369
*/
2370-
public array $MysqlMinVersion;
2370+
public array $mysqlMinVersion;
23712371

23722372
/**
23732373
* Disable shortcuts
@@ -2596,7 +2596,7 @@ public function __construct(array $settings)
25962596
$this->DefaultFunctions = $this->setDefaultFunctions($settings);
25972597
$this->maxRowPlotLimit = $this->setMaxRowPlotLimit($settings);
25982598
$this->ShowGitRevision = $this->setShowGitRevision($settings);
2599-
$this->MysqlMinVersion = $this->setMysqlMinVersion($settings);
2599+
$this->mysqlMinVersion = $this->setMysqlMinVersion($settings);
26002600
$this->DisableShortcutKeys = $this->setDisableShortcutKeys($settings);
26012601
$this->Console = $this->setConsole($settings);
26022602
$this->DefaultTransformations = $this->setDefaultTransformations($settings);
@@ -2793,7 +2793,7 @@ public function asArray(): array
27932793
'DefaultFunctions' => $this->DefaultFunctions,
27942794
'maxRowPlotLimit' => $this->maxRowPlotLimit,
27952795
'ShowGitRevision' => $this->ShowGitRevision,
2796-
'MysqlMinVersion' => $this->MysqlMinVersion,
2796+
'MysqlMinVersion' => $this->mysqlMinVersion,
27972797
'DisableShortcutKeys' => $this->DisableShortcutKeys,
27982798
'Console' => $this->Console->asArray(),
27992799
'DefaultTransformations' => $this->DefaultTransformations->asArray(),

‎psalm-baseline.xml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@
238238
<code>$sqlDelimiter</code>
239239
</MixedArgument>
240240
<MixedArrayAccess>
241-
<code><![CDATA[$GLOBALS['cfg']['MysqlMinVersion']['human']]]></code>
242-
<code><![CDATA[$GLOBALS['cfg']['MysqlMinVersion']['internal']]]></code>
243241
<code><![CDATA[$GLOBALS['cfg']['Server']['user']]]></code>
244242
</MixedArrayAccess>
245243
<MixedAssignment>

‎psalm.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
MaxRows: positive-int,
111111
MaxSizeForInputField: positive-int,
112112
MinSizeForInputField: 0|positive-int,
113-
MysqlMinVersion: array{internal: int, human: string},
114113
MysqlSslWarningSafeHosts: string[],
115114
NaturalOrder: bool,
116115
NavigationLinkWithMainPanel: bool,

‎test/classes/Config/SettingsTest.php‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ class SettingsTest extends TestCase
266266
],
267267
'maxRowPlotLimit' => 500,
268268
'ShowGitRevision' => true,
269-
'MysqlMinVersion' => ['internal' => 50500, 'human' => '5.5.0'],
270269
'DisableShortcutKeys' => false,
271270
'Console' => null,
272271
'DefaultTransformations' => null,
@@ -553,7 +552,6 @@ public static function providerForTestConstructor(): array
553552
['DefaultFunctions', null, ['FUNC_CHAR' => '', 'FUNC_DATE' => '', 'FUNC_NUMBER' => '', 'FUNC_SPATIAL' => 'GeomFromText', 'FUNC_UUID' => 'UUID', 'first_timestamp' => 'NOW']],
554553
['maxRowPlotLimit', null, 500],
555554
['ShowGitRevision', null, true],
556-
['MysqlMinVersion', null, ['internal' => 50500, 'human' => '5.5.0']],
557555
['DisableShortcutKeys', null, false],
558556
['Console', null, null],
559557
['DefaultTransformations', null, null],
@@ -748,7 +746,6 @@ public static function providerForTestConstructor(): array
748746
['DefaultFunctions', ['key' => 'value', 'key2' => 'value2'], ['key' => 'value', 'key2' => 'value2']],
749747
['maxRowPlotLimit', 1, 1],
750748
['ShowGitRevision', false, false],
751-
['MysqlMinVersion', ['internal' => 80026, 'human' => '8.0.26'], ['internal' => 80026, 'human' => '8.0.26']],
752749
['DisableShortcutKeys', true, true],
753750
['Console', [], null],
754751
['DefaultTransformations', [], null],
@@ -786,7 +783,6 @@ public static function providerForTestConstructor(): array
786783
['SendErrorReports', 'ask', 'ask'],
787784
['environment', 'production', 'production'],
788785
['DefaultFunctions', [], []],
789-
['MysqlMinVersion', [], ['internal' => 50500, 'human' => '5.5.0']],
790786
['FirstDayOfCalendar', 0, 0],
791787
],
792788
],
@@ -1038,7 +1034,6 @@ public static function providerForTestConstructor(): array
10381034
['DefaultFunctions', ['test' => 1234], ['test' => '1234']],
10391035
['maxRowPlotLimit', '1', 1],
10401036
['ShowGitRevision', 0, false],
1041-
['MysqlMinVersion', ['internal' => '50500', 'human' => 550], ['internal' => 50500, 'human' => '550']],
10421037
['DisableShortcutKeys', 1, true],
10431038
['FirstDayOfCalendar', '1', 1],
10441039
],
@@ -1115,7 +1110,6 @@ public static function providerForTestConstructor(): array
11151110
['environment', 'invalid', 'production'],
11161111
['DefaultFunctions', 'invalid', ['FUNC_CHAR' => '', 'FUNC_DATE' => '', 'FUNC_NUMBER' => '', 'FUNC_SPATIAL' => 'GeomFromText', 'FUNC_UUID' => 'UUID', 'first_timestamp' => 'NOW']],
11171112
['maxRowPlotLimit', 0, 500],
1118-
['MysqlMinVersion', 'invalid', ['internal' => 50500, 'human' => '5.5.0']],
11191113
['Console', 'invalid', null],
11201114
['FirstDayOfCalendar', 8, 0],
11211115
],
@@ -1139,4 +1133,36 @@ public static function providerForTestConstructor(): array
11391133
'invalid values 4' => [[['ForeignKeyDropdownOrder', [1 => 'content-id'], ['content-id', 'id-content']]]],
11401134
];
11411135
}
1136+
1137+
/**
1138+
* @param array{internal: int, human: string} $expected
1139+
*
1140+
* @dataProvider valuesForMysqlMinVersionProvider
1141+
*/
1142+
public function testMysqlMinVersion(mixed $actual, array $expected): void
1143+
{
1144+
$settings = new Settings(['MysqlMinVersion' => $actual]);
1145+
$settingsArray = $settings->asArray();
1146+
$this->assertSame($expected, $settings->mysqlMinVersion);
1147+
$this->assertArrayHasKey('MysqlMinVersion', $settingsArray);
1148+
$this->assertSame($expected, $settingsArray['MysqlMinVersion']);
1149+
}
1150+
1151+
/** @return iterable<string, array{mixed, array{internal: int, human: string}}> */
1152+
public static function valuesForMysqlMinVersionProvider(): iterable
1153+
{
1154+
yield 'null value' => [null, ['internal' => 50500, 'human' => '5.5.0']];
1155+
yield 'valid value' => [
1156+
['internal' => 80026, 'human' => '8.0.26'],
1157+
['internal' => 80026, 'human' => '8.0.26'],
1158+
];
1159+
1160+
yield 'valid value 2' => [[], ['internal' => 50500, 'human' => '5.5.0']];
1161+
yield 'valid value with type coercion' => [
1162+
['internal' => '50500', 'human' => 550],
1163+
['internal' => 50500, 'human' => '550'],
1164+
];
1165+
1166+
yield 'invalid value' => ['invalid', ['internal' => 50500, 'human' => '5.5.0']];
1167+
}
11421168
}

‎test/classes/ConfigTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,4 +1379,12 @@ public static function connectionParams(): array
13791379
],
13801380
];
13811381
}
1382+
1383+
public function testGetSettings(): void
1384+
{
1385+
$config = new Config();
1386+
$firstCall = $config->getSettings();
1387+
$secondCall = $config->getSettings();
1388+
$this->assertSame($firstCall, $secondCall);
1389+
}
13821390
}

‎test/classes/DatabaseInterfaceTest.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ public function testVersion(string $version, int $expected, int $major, bool $up
377377
$ver_int = Utilities::versionToInt($version);
378378
$this->assertEquals($expected, $ver_int);
379379
$this->assertEquals($major, (int) ($ver_int / 10000));
380-
$this->assertEquals($upgrade, $ver_int < $GLOBALS['cfg']['MysqlMinVersion']['internal']);
380+
$mysqlMinVersion = 50500;
381+
$this->assertEquals($upgrade, $ver_int < $mysqlMinVersion);
381382
}
382383

383384
public static function versionData(): array

0 commit comments

Comments
 (0)