Ref #16906 - Allow to create the pma storage db using a different name than "phpmyadmin"
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
parent
2f041b2c7e
commit
cdb027c119
@ -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.
|
||||
|
||||
@ -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('</a>');
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user