connectionPool ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME); $platform = $defaultConnection->getDatabasePlatform(); if (!($platform instanceof DoctrinePostgreSQLPlatform)) { return $this->messageQueue; } $this->checkPostgreSqlVersion($defaultConnection); $this->checkLibpqVersion(); $this->checkDefaultDatabaseCharset($defaultConnection); $this->checkDefaultDatabaseServerCharset($defaultConnection); $this->checkDatabaseName($defaultConnection); return $this->messageQueue; } /** * Check minimum PostgreSQL version * * @param Connection $connection to the database to be checked */ protected function checkPostgreSqlVersion(Connection $connection) { preg_match('/PostgreSQL ((\d+\.)*(\d+\.)*\d+)/', $connection->getPlatformServerVersion(), $match); $currentPostgreSqlVersion = $match[1]; if (version_compare($currentPostgreSqlVersion, $this->minimumPostgreSQLVerion, '<')) { $this->messageQueue->enqueue(new FlashMessage( 'Your PostgreSQL version ' . $currentPostgreSqlVersion . ' is not supported. TYPO3 CMS does not run' . ' with this version. The minimum supported PostgreSQL version is ' . $this->minimumPostgreSQLVerion, 'PostgreSQL Server version is unsupported', ContextualFeedbackSeverity::ERROR )); } else { $this->messageQueue->enqueue(new FlashMessage( '', 'PostgreSQL Server version is supported' )); } } /** * Check the version of ligpq within the PostgreSQL driver */ protected function checkLibpqVersion() { if (!defined('PGSQL_LIBPQ_VERSION')) { $this->messageQueue->enqueue(new FlashMessage( 'It is not possible to retrieve your PostgreSQL libpq version. Please check the version' . ' in the "phpinfo" area of the "System environment" module in the install tool manually.' . ' This should be found in section "pdo_pgsql".' . ' You should have at least the following version of PostgreSQL libpq installed: ' . $this->minimumLibPQVersion, 'PostgreSQL libpq version cannot be determined', ContextualFeedbackSeverity::WARNING )); } else { preg_match('/((\d+\.)*(\d+\.)*\d+)/', \PGSQL_LIBPQ_VERSION, $match); $currentPostgreSqlLibpqVersion = $match[1]; if (version_compare($currentPostgreSqlLibpqVersion, $this->minimumLibPQVersion, '<')) { $this->messageQueue->enqueue(new FlashMessage( 'Your PostgreSQL libpq version "' . $currentPostgreSqlLibpqVersion . '" is unsupported.' . ' TYPO3 CMS does not run with this version. The minimum supported libpq version is ' . $this->minimumLibPQVersion, 'PostgreSQL libpq version is unsupported', ContextualFeedbackSeverity::ERROR )); } else { $this->messageQueue->enqueue(new FlashMessage( '', 'PostgreSQL libpq version is supported' )); } } } /** * Checks the character set of the database and reports an error if it is not utf-8. * * @param Connection $connection to the database to be checked */ public function checkDefaultDatabaseCharset(Connection $connection): void { $defaultDatabaseCharset = $connection->executeQuery( 'SELECT pg_catalog.pg_encoding_to_char(pg_database.encoding) from pg_database where datname = ?', [$connection->getDatabase()], [Connection::PARAM_STR] )->fetchAssociative(); if (!in_array(strtolower($defaultDatabaseCharset['pg_encoding_to_char']), $this->databaseCharsetToCheck, true)) { $this->messageQueue->enqueue(new FlashMessage( sprintf( 'Checking database character set failed, got key "%s" instead of "%s"', $defaultDatabaseCharset['pg_encoding_to_char'], implode(' or ', $this->databaseCharsetToCheck) ), 'PostgreSQL database character set check failed', ContextualFeedbackSeverity::ERROR )); } else { $this->messageQueue->enqueue(new FlashMessage( '', sprintf('PostgreSQL database uses %s. All good.', implode(' or ', $this->databaseCharsetToCheck)) )); } } /** * Checks the character set of the database server and reports an info if it is not utf-8. * * @param Connection $connection to the database to be checked */ public function checkDefaultDatabaseServerCharset(Connection $connection): void { $defaultServerCharset = $connection->executeQuery('SHOW SERVER_ENCODING')->fetchAssociative(); if (!in_array(strtolower($defaultServerCharset['server_encoding']), $this->databaseCharsetToCheck, true)) { $this->messageQueue->enqueue(new FlashMessage( sprintf( 'Checking server character set failed, got key "%s" instead of "%s"', $defaultServerCharset['server_encoding'], implode(' or ', $this->databaseServerCharsetToCheck) ), 'PostgreSQL database character set check failed', ContextualFeedbackSeverity::INFO )); } else { $this->messageQueue->enqueue(new FlashMessage( '', sprintf('PostgreSQL server default uses %s. All good.', implode(' or ', $this->databaseCharsetToCheck)) )); } } /** * Validate the database name */ public static function isValidDatabaseName(string $databaseName): bool { return strlen($databaseName) <= static::SCHEMA_NAME_MAX_LENGTH && preg_match('/^(?!pg_)[a-zA-Z0-9\$_]*$/', $databaseName); } protected function checkDatabaseName(Connection $connection): void { if (static::isValidDatabaseName((string)$connection->getDatabase())) { return; } $this->messageQueue->enqueue( new FlashMessage( 'The given database name must not be longer than ' . static::SCHEMA_NAME_MAX_LENGTH . ' characters' . ' and consist solely of basic latin letters (a-z), digits (0-9), dollar signs ($)' . ' and underscores (_) and does not start with "pg_".', 'Database name not valid', ContextualFeedbackSeverity::ERROR ) ); } }