Skip to content

Commit

Permalink
Merge pull request #49 from beheist/dev-bh-fix-postgres-installation
Browse files Browse the repository at this point in the history
BUGFIX: Fix setup with postgres
  • Loading branch information
kdambekalns authored Sep 3, 2018
2 parents d559510 + f95e4df commit 9af0a19
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Classes/Step/DatabaseStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public function postProcessFormValues(array $formValues)
$this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.user', $formValues['user']);
$this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.password', $formValues['password']);
$this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.host', $formValues['host']);
// Postgres natively supports multibyte-UTF8. It does not know utf8mb4, which is the default now
if ($formValues['driver'] === 'pdo_pgsql') {
$this->distributionSettings = Arrays::setValueByPath($this->distributionSettings, 'Neos.Flow.persistence.backendOptions.charset', 'utf8');
}
$this->configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->distributionSettings);

$this->configurationManager->refreshConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public function getMetadataAction($driver, $user, $password, $host, $databaseNam
$connection = $this->getConnectionAndConnect($connectionSettings);
$databasePlatform = $connection->getDatabasePlatform();
if ($databasePlatform instanceof MySqlPlatform) {
$queryResult = $connection->executeQuery('SHOW VARIABLES LIKE \'character_set_database\'')->fetch();
$databaseCharacterSet = strtolower($queryResult['Value']);
$databaseVersionQueryResult = $connection->executeQuery('SELECT VERSION()')->fetch();
$databaseVersion = isset($databaseVersionQueryResult['VERSION()']) ? $databaseVersionQueryResult['VERSION()'] : null;
if (isset($databaseVersion) && $this->databaseSupportsUtf8Mb4($databaseVersion) === false) {
Expand All @@ -102,22 +100,35 @@ public function getMetadataAction($driver, $user, $password, $host, $databaseNam
'message' => sprintf('The minimum required version for MySQL is "%s" or "%s" for MariaDB.', self::MINIMUM_MYSQL_VERSION, self::MINIMUM_MARIA_DB_VERSION)
];
}

$charsetQueryResult = $connection->executeQuery('SHOW VARIABLES LIKE \'character_set_database\'')->fetch();
$databaseCharacterSet = strtolower($charsetQueryResult['Value']);
if (isset($databaseCharacterSet)) {
if ($databaseCharacterSet === 'utf8mb4') {
$result[] = ['level' => 'notice', 'message' => 'The selected database\'s character set is set to "utf8mb4" which is the recommended setting for MySQL/MariaDB databases.'];
} else {
$result[] = [
'level' => 'warning',
'message' => sprintf('The selected database\'s character set is "%s", however changing it to "utf8mb4" is urgently recommended. This setup tool won\'t do this for you.', $databaseCharacterSet)
];
}
}
} elseif ($databasePlatform instanceof PostgreSqlPlatform) {
$queryResult = $connection->executeQuery('SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = ?', [$databaseName])->fetch();
$databaseCharacterSet = strtolower($queryResult['pg_encoding_to_char']);
$charsetQueryResult = $connection->executeQuery('SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = ?', [$databaseName])->fetch();
$databaseCharacterSet = strtolower($charsetQueryResult['pg_encoding_to_char']);
if (isset($databaseCharacterSet)) {
if ($databaseCharacterSet === 'utf8') {
$result[] = ['level' => 'notice', 'message' => 'The selected database\'s character set is set to "utf8" which is the recommended setting for PostgreSQL databases.'];
} else {
$result[] = [
'level' => 'warning',
'message' => sprintf('The selected database\'s character set is "%s", however changing it to "utf8" is urgently recommended. This setup tool won\'t do this for you.', $databaseCharacterSet)
];
}
}
} else {
$result[] = ['level' => 'error', 'message' => sprintf('Only MySQL/MariaDB and PostgreSQL are supported, the selected database is "%s".', $databasePlatform->getName())];
}
if (isset($databaseCharacterSet)) {
if ($databaseCharacterSet === 'utf8mb4') {
$result[] = ['level' => 'notice', 'message' => 'The selected database\'s character set is set to "utf8mb4" which is the recommended setting.'];
} else {
$result[] = [
'level' => 'warning',
'message' => sprintf('The selected database\'s character set is "%s", however changing it to "utf8mb4" is urgently recommended. This setup tool won\'t do this for you.', $databaseCharacterSet)
];
}
}
} catch (\PDOException $exception) {
$result = ['level' => 'error', 'message' => $exception->getMessage(), 'errorCode' => $exception->getCode()];
} catch (\Doctrine\DBAL\DBALException $exception) {
Expand Down Expand Up @@ -146,6 +157,8 @@ protected function buildConnectionSettingsArray($driver, $user, $password, $host
$connectionSettings['host'] = $host;
if ($connectionSettings['driver'] === 'pdo_pgsql') {
$connectionSettings['dbname'] = 'template1';
// Postgres natively supports multibyte-UTF8. It does not know utf8mb4
$connectionSettings['charset'] = 'utf8';

return $connectionSettings;
} else {
Expand Down

0 comments on commit 9af0a19

Please sign in to comment.