Skip to content
Snippets Groups Projects
Commit 7b665c58 authored by Helmut Hummel's avatar Helmut Hummel Committed by Jigal van Hemert
Browse files

[BUGFIX] Harden database select step

Currently this step does not do precautions, when
the selected database does not exist. Additionally the step
silently skips when the chosen database already has tables.

Although the UI currently does not allow to select a non
empty database, there are situations imaginable, where the database
is empty during generation of the input form but is filled directly after that,
or a database was empty but then got deleted,
which previously ended up with a fatal error.

This change now takes care of both cases and outputs a nice error message accordingly.

Resolves: #75964
Releases: 7.6, master
Change-Id: Ibc7083aa120f420d6201e512f3f41699f55c5f7f
Reviewed-on: https://review.typo3.org/47950


Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: default avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Tested-by: default avatarDaniel Goerz <ervaude@gmail.com>
Reviewed-by: default avatarJigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: default avatarJigal van Hemert <jigal.van.hemert@typo3.org>
parent 3db4a3e8
Branches
Tags
No related merge requests found
......@@ -74,10 +74,29 @@ class DatabaseSelect extends AbstractStepAction
} elseif ($postValues['type'] === 'existing' && !empty($postValues['existing'])) {
// Only store database information when it's empty
$this->databaseConnection->setDatabaseName($postValues['existing']);
$this->databaseConnection->sql_select_db();
$existingTables = $this->databaseConnection->admin_get_tables();
try {
$this->databaseConnection->sql_select_db();
$existingTables = $this->databaseConnection->admin_get_tables();
if (!empty($existingTables)) {
$errorStatus = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\ErrorStatus::class);
$errorStatus->setTitle('Selected database is not empty!');
$errorStatus->setMessage(
sprintf('Cannot use database "%s"', $postValues['existing'])
. ', because it has tables already. Please select a different database or choose to create one!'
);
$result[] = $errorStatus;
}
} catch (\RuntimeException $e) {
$errorStatus = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\ErrorStatus::class);
$errorStatus->setTitle('Could not connect to selected database!');
$errorStatus->setMessage(
sprintf('Could not connect to database "%s"', $postValues['existing'])
. '! Make sure it really exists and your database user has the permissions to select it!'
);
$result[] = $errorStatus;
}
$isInitialInstallation = $configurationManager->getConfigurationValueByPath('SYS/isInitialInstallationInProgress');
if (!$isInitialInstallation || empty($existingTables)) {
if (!$isInitialInstallation || empty($result)) {
$localConfigurationPathValuePairs['DB/Connections/Default/dbname'] = $postValues['existing'];
}
// check if database charset is utf-8
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment