Skip to content

Commit 9d2f4c7

Browse files
committed
Merge #20262 - Fix #18204 - Remove getInnodbPluginVersion() and refactor getInnodbFileFormat() for MariaDB compatibility
Pull-request: #20262 Co-Authored-By: William Desportes <williamdes@wdes.fr> Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents fa168ab + 4bf3505 commit 9d2f4c7

5 files changed

Lines changed: 38 additions & 49 deletions

File tree

libraries/classes/Engines/Innodb.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\Engines;
99

10+
use PhpMyAdmin\DatabaseInterface;
1011
use PhpMyAdmin\StorageEngine;
1112
use PhpMyAdmin\Util;
1213

@@ -281,18 +282,6 @@ public function getMysqlHelpPage()
281282
return 'innodb-storage-engine';
282283
}
283284

284-
/**
285-
* Gets the InnoDB plugin version number
286-
*
287-
* @return string the version number, or empty if not running as a plugin
288-
*/
289-
public function getInnodbPluginVersion()
290-
{
291-
global $dbi;
292-
293-
return $dbi->fetchValue('SELECT @@innodb_version;') ?: '';
294-
}
295-
296285
/**
297286
* Gets the InnoDB file format
298287
*
@@ -302,17 +291,22 @@ public function getInnodbPluginVersion()
302291
*/
303292
public function getInnodbFileFormat(): ?string
304293
{
294+
/** @var DatabaseInterface $dbi */// phpcs:ignore
305295
global $dbi;
306296

307-
$value = $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';", 1);
297+
if (
298+
($dbi->isMariaDB() && $dbi->getVersion() >= 100600)
299+
|| ($dbi->isMySql() && $dbi->getVersion() >= 80000)
300+
) {
301+
return '';
302+
}
308303

304+
$value = $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';", 1);
309305
if ($value === false) {
310-
// This variable does not exist anymore on MariaDB >= 10.6.0
311-
// This variable does not exist anymore on MySQL >= 8.0.0
312306
return null;
313307
}
314308

315-
return (string) $value;
309+
return $value;
316310
}
317311

318312
/**

libraries/classes/Operations.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,7 @@ public function getPossibleRowFormat()
519519

520520
/** @var Innodb $innodbEnginePlugin */
521521
$innodbEnginePlugin = StorageEngine::getEngine('Innodb');
522-
$innodbPluginVersion = $innodbEnginePlugin->getInnodbPluginVersion();
523-
$innodb_file_format = '';
524-
if (! empty($innodbPluginVersion)) {
525-
$innodb_file_format = $innodbEnginePlugin->getInnodbFileFormat() ?? '';
526-
}
522+
$innodb_file_format = $innodbEnginePlugin->getInnodbFileFormat() ?? '';
527523

528524
/**
529525
* Newer MySQL/MariaDB always return empty a.k.a '' on $innodb_file_format otherwise

phpstan-baseline.neon

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16777,21 +16777,16 @@ parameters:
1677716777

1677816778
-
1677916779
message: "#^Cannot call method fetchValue\\(\\) on mixed\\.$#"
16780-
count: 4
16781-
path: libraries/classes/Engines/Innodb.php
16782-
16783-
-
16784-
message: "#^Cannot cast mixed to string\\.$#"
1678516780
count: 2
1678616781
path: libraries/classes/Engines/Innodb.php
1678716782

1678816783
-
16789-
message: "#^Method PhpMyAdmin\\\\Engines\\\\Innodb\\:\\:getInfoPages\\(\\) return type has no value type specified in iterable type array\\.$#"
16784+
message: "#^Cannot cast mixed to string\\.$#"
1679016785
count: 1
1679116786
path: libraries/classes/Engines/Innodb.php
1679216787

1679316788
-
16794-
message: "#^Method PhpMyAdmin\\\\Engines\\\\Innodb\\:\\:getInnodbPluginVersion\\(\\) should return string but returns mixed\\.$#"
16789+
message: "#^Method PhpMyAdmin\\\\Engines\\\\Innodb\\:\\:getInfoPages\\(\\) return type has no value type specified in iterable type array\\.$#"
1679516790
count: 1
1679616791
path: libraries/classes/Engines/Innodb.php
1679716792

@@ -16810,11 +16805,6 @@ parameters:
1681016805
count: 1
1681116806
path: libraries/classes/Engines/Innodb.php
1681216807

16813-
-
16814-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
16815-
count: 1
16816-
path: libraries/classes/Engines/Innodb.php
16817-
1681816808
-
1681916809
message: "#^Method PhpMyAdmin\\\\Engines\\\\Memory\\:\\:getVariables\\(\\) return type has no value type specified in iterable type array\\.$#"
1682016810
count: 1
@@ -23892,7 +23882,7 @@ parameters:
2389223882

2389323883
-
2389423884
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
23895-
count: 11
23885+
count: 10
2389623886
path: libraries/classes/Operations.php
2389723887

2389823888
-

test/classes/Engines/InnodbTest.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,6 @@ public function testGetMysqlHelpPage(): void
226226
self::assertSame('innodb-storage-engine', $this->object->getMysqlHelpPage());
227227
}
228228

229-
/**
230-
* Test for getInnodbPluginVersion
231-
*/
232-
public function testGetInnodbPluginVersion(): void
233-
{
234-
self::assertSame('1.1.8', $this->object->getInnodbPluginVersion());
235-
}
236-
237229
/**
238230
* Test for supportsFilePerTable
239231
*/
@@ -260,7 +252,9 @@ public function testGetInnodbFileFormatOnMySQL8(): void
260252
$dbi = $this->createStub(DatabaseInterface::class);
261253

262254
$dbi->method('isMariaDB')->willReturn(false);
255+
$dbi->method('isMySql')->willReturn(true);
263256
$dbi->method('getVersion')->willReturn(80000);
257+
$dbi->method('fetchValue')->willReturn('Barracuda');
264258

265259
self::assertSame('', $this->object->getInnodbFileFormat());
266260
}
@@ -275,9 +269,28 @@ public function testGetInnodbFileFormatOnMySQL5(): void
275269
$dbi = $this->createStub(DatabaseInterface::class);
276270

277271
$dbi->method('isMariaDB')->willReturn(false);
272+
$dbi->method('isMySql')->willReturn(true);
278273
$dbi->method('getVersion')->willReturn(50000);
274+
$dbi->method('fetchValue')->willReturn('Barracuda');
279275

280-
self::assertSame('', $this->object->getInnodbFileFormat());
276+
self::assertSame('Barracuda', $this->object->getInnodbFileFormat());
277+
}
278+
279+
/**
280+
* Test for getInnodbFileFormat on MySQL 5 with error
281+
*/
282+
public function testGetInnodbFileFormatOnMySQL5WithError(): void
283+
{
284+
global $dbi;
285+
286+
$dbi = $this->createStub(DatabaseInterface::class);
287+
288+
$dbi->method('isMariaDB')->willReturn(false);
289+
$dbi->method('isMySql')->willReturn(true);
290+
$dbi->method('getVersion')->willReturn(50000);
291+
$dbi->method('fetchValue')->willReturn(false);
292+
293+
self::assertNull($this->object->getInnodbFileFormat());
281294
}
282295

283296
/**
@@ -290,7 +303,9 @@ public function testGetInnodbFileFormatOnMariaDB106(): void
290303
$dbi = $this->createStub(DatabaseInterface::class);
291304

292305
$dbi->method('isMariaDB')->willReturn(true);
306+
$dbi->method('isMySql')->willReturn(false);
293307
$dbi->method('getVersion')->willReturn(100600);
308+
$dbi->method('fetchValue')->willReturn('Barracuda');
294309

295310
self::assertSame('', $this->object->getInnodbFileFormat());
296311
}

test/classes/Stubs/DbiDummy.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,6 @@ private function init(): void
705705
'query' => 'SHOW ENGINE INNODB STATUS;',
706706
'result' => false,
707707
],
708-
[
709-
'query' => 'SELECT @@innodb_version;',
710-
'result' => [
711-
['1.1.8'],
712-
],
713-
],
714708
[
715709
'query' => 'SELECT @@disabled_storage_engines',
716710
'result' => [

0 commit comments

Comments
 (0)