From cdb027c119dbd0596d3f8ac8cc0e970f911d5501 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 27 Aug 2021 16:23:40 +0200 Subject: [PATCH] Ref #16906 - Allow to create the pma storage db using a different name than "phpmyadmin" Signed-off-by: William Desportes --- .../Controllers/CheckRelationsController.php | 6 ++- libraries/classes/Relation.php | 38 ++++++++++++++----- test/classes/RelationTest.php | 8 ++-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/libraries/classes/Controllers/CheckRelationsController.php b/libraries/classes/Controllers/CheckRelationsController.php index af897e90ea..2232107587 100644 --- a/libraries/classes/Controllers/CheckRelationsController.php +++ b/libraries/classes/Controllers/CheckRelationsController.php @@ -35,9 +35,11 @@ class CheckRelationsController extends AbstractController 'fix_pmadb' => $_POST['fix_pmadb'] ?? null, ]; + $cfgStorageDbName = $this->relation->getConfigurationStorageDbName(); + // If request for creating the pmadb - if (isset($params['create_pmadb']) && $this->relation->createPmaDatabase()) { - $this->relation->fixPmaTables('phpmyadmin'); + if (isset($params['create_pmadb']) && $this->relation->createPmaDatabase($cfgStorageDbName)) { + $this->relation->fixPmaTables($cfgStorageDbName); } // If request for creating all PMA tables. diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index df778d359b..f0d052f90d 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -2018,13 +2018,13 @@ class Relation } /** - * Create a table named phpmyadmin to be used as configuration storage - * - * @return bool + * Create a database to be used as configuration storage */ - public function createPmaDatabase() + public function createPmaDatabase(string $configurationStorageDbName): bool { - $this->dbi->tryQuery('CREATE DATABASE IF NOT EXISTS `phpmyadmin`'); + $this->dbi->tryQuery( + 'CREATE DATABASE IF NOT EXISTS ' . Util::backquote($configurationStorageDbName) + ); $error = $this->dbi->getError(); if (! $error) { @@ -2034,10 +2034,13 @@ class Relation $GLOBALS['message'] = $error; if ($GLOBALS['errno'] === 1044) { - $GLOBALS['message'] = __( - 'You do not have necessary privileges to create a database named' - . ' \'phpmyadmin\'. You may go to \'Operations\' tab of any' - . ' database to set up the phpMyAdmin configuration storage there.' + $GLOBALS['message'] = sprintf( + __( + 'You do not have necessary privileges to create a database named' + . ' \'%s\'. You may go to \'Operations\' tab of any' + . ' database to set up the phpMyAdmin configuration storage there.' + ), + $configurationStorageDbName ); } @@ -2157,7 +2160,7 @@ class Relation $params['create_pmadb'] = 1; $message = Message::notice( __( - '%sCreate%s a database named \'phpmyadmin\' and setup ' + '%sCreate%s a database named \'%s\' and setup ' . 'the phpMyAdmin configuration storage there.' ) ); @@ -2181,6 +2184,12 @@ class Relation ); $message->addParamHtml(''); + if ($allTables && $createDb) { + $message->addParam( + $this->getConfigurationStorageDbName() + ); + } + return $retval . $message->getDisplay(); } @@ -2273,4 +2282,13 @@ class Relation return $tables; } + + public function getConfigurationStorageDbName(): string + { + global $cfg; + + $cfgStorageDbName = $cfg['Server']['pmadb'] ?? ''; + // Use "phpmyadmin" as a default database name to check to keep the behavior consistent + return empty($cfgStorageDbName) ? 'phpmyadmin' : $cfgStorageDbName; + } } diff --git a/test/classes/RelationTest.php b/test/classes/RelationTest.php index e8fa6f457b..fd7e768025 100644 --- a/test/classes/RelationTest.php +++ b/test/classes/RelationTest.php @@ -811,7 +811,7 @@ class RelationTest extends AbstractTestCase $this->assertArrayNotHasKey('errno', $GLOBALS); $this->assertTrue( - $this->relation->createPmaDatabase() + $this->relation->createPmaDatabase('phpmyadmin') ); $this->assertArrayNotHasKey('message', $GLOBALS); @@ -836,7 +836,7 @@ class RelationTest extends AbstractTestCase $GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR $this->assertFalse( - $this->relation->createPmaDatabase() + $this->relation->createPmaDatabase('phpmyadmin') ); $this->assertArrayHasKey('message', $GLOBALS); @@ -860,14 +860,14 @@ class RelationTest extends AbstractTestCase $this->dummyDbi->removeDefaultResults(); $this->dummyDbi->addErrorCode('Too many connections'); $this->dummyDbi->addResult( - 'CREATE DATABASE IF NOT EXISTS `phpmyadmin`', + 'CREATE DATABASE IF NOT EXISTS `pma_1040`', false ); $GLOBALS['errno'] = 1040; $this->assertFalse( - $this->relation->createPmaDatabase() + $this->relation->createPmaDatabase('pma_1040') ); $this->assertArrayHasKey('message', $GLOBALS);