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,
|
'fix_pmadb' => $_POST['fix_pmadb'] ?? null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$cfgStorageDbName = $this->relation->getConfigurationStorageDbName();
|
||||||
|
|
||||||
// If request for creating the pmadb
|
// If request for creating the pmadb
|
||||||
if (isset($params['create_pmadb']) && $this->relation->createPmaDatabase()) {
|
if (isset($params['create_pmadb']) && $this->relation->createPmaDatabase($cfgStorageDbName)) {
|
||||||
$this->relation->fixPmaTables('phpmyadmin');
|
$this->relation->fixPmaTables($cfgStorageDbName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If request for creating all PMA tables.
|
// If request for creating all PMA tables.
|
||||||
|
|||||||
@ -2018,13 +2018,13 @@ class Relation
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a table named phpmyadmin to be used as configuration storage
|
* Create a database to be used as configuration storage
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
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();
|
$error = $this->dbi->getError();
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
@ -2034,10 +2034,13 @@ class Relation
|
|||||||
$GLOBALS['message'] = $error;
|
$GLOBALS['message'] = $error;
|
||||||
|
|
||||||
if ($GLOBALS['errno'] === 1044) {
|
if ($GLOBALS['errno'] === 1044) {
|
||||||
$GLOBALS['message'] = __(
|
$GLOBALS['message'] = sprintf(
|
||||||
'You do not have necessary privileges to create a database named'
|
__(
|
||||||
. ' \'phpmyadmin\'. You may go to \'Operations\' tab of any'
|
'You do not have necessary privileges to create a database named'
|
||||||
. ' database to set up the phpMyAdmin configuration storage there.'
|
. ' \'%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;
|
$params['create_pmadb'] = 1;
|
||||||
$message = Message::notice(
|
$message = Message::notice(
|
||||||
__(
|
__(
|
||||||
'%sCreate%s a database named \'phpmyadmin\' and setup '
|
'%sCreate%s a database named \'%s\' and setup '
|
||||||
. 'the phpMyAdmin configuration storage there.'
|
. 'the phpMyAdmin configuration storage there.'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -2181,6 +2184,12 @@ class Relation
|
|||||||
);
|
);
|
||||||
$message->addParamHtml('</a>');
|
$message->addParamHtml('</a>');
|
||||||
|
|
||||||
|
if ($allTables && $createDb) {
|
||||||
|
$message->addParam(
|
||||||
|
$this->getConfigurationStorageDbName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $retval . $message->getDisplay();
|
return $retval . $message->getDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2273,4 +2282,13 @@ class Relation
|
|||||||
|
|
||||||
return $tables;
|
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->assertArrayNotHasKey('errno', $GLOBALS);
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$this->relation->createPmaDatabase()
|
$this->relation->createPmaDatabase('phpmyadmin')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertArrayNotHasKey('message', $GLOBALS);
|
$this->assertArrayNotHasKey('message', $GLOBALS);
|
||||||
@ -836,7 +836,7 @@ class RelationTest extends AbstractTestCase
|
|||||||
$GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR
|
$GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$this->relation->createPmaDatabase()
|
$this->relation->createPmaDatabase('phpmyadmin')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertArrayHasKey('message', $GLOBALS);
|
$this->assertArrayHasKey('message', $GLOBALS);
|
||||||
@ -860,14 +860,14 @@ class RelationTest extends AbstractTestCase
|
|||||||
$this->dummyDbi->removeDefaultResults();
|
$this->dummyDbi->removeDefaultResults();
|
||||||
$this->dummyDbi->addErrorCode('Too many connections');
|
$this->dummyDbi->addErrorCode('Too many connections');
|
||||||
$this->dummyDbi->addResult(
|
$this->dummyDbi->addResult(
|
||||||
'CREATE DATABASE IF NOT EXISTS `phpmyadmin`',
|
'CREATE DATABASE IF NOT EXISTS `pma_1040`',
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
$GLOBALS['errno'] = 1040;
|
$GLOBALS['errno'] = 1040;
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$this->relation->createPmaDatabase()
|
$this->relation->createPmaDatabase('pma_1040')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertArrayHasKey('message', $GLOBALS);
|
$this->assertArrayHasKey('message', $GLOBALS);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user