Issue Bug Closed

#103826setup command with TYPO3_INSTALL_DB_* ENV vars does not work.

Rafael Kähm 05/13/24, 13:06 updated 07/04/24, 13:17

Description

There is a trouble within \TYPO3\CMS\Install\Service\SetupDatabaseService::getDatabaseConfigurationFromEnvironment() method.
The port is not casted to int after fetching it from ENV. See: https://github.com/TYPO3/typo3/blob/90e286e56eb55a1e0f5888b0f8f65917d97eedf4/typo3/sysext/install/Classes/Service/SetupDatabaseService.php#L220

Exception:

Uncaught TYPO3 Exception mysqli::real_connect(): Argument #5 ($port) must be of type ?int, string given
thrown in file /var/www/html/vendor/doctrine/dbal/src/Driver/Mysqli/Driver.php
in line 44

How to reproduce:

Try to run typo3 setup command with defined TYPO3_INSTALL_DB_* variables.

—-

Proposed fix:

public function getDatabaseConfigurationFromEnvironment(): array
    {
        /** @var Params $envCredentials */
        $envCredentials = [];
        foreach (['driver', 'host', 'user', 'password', 'port', 'dbname', 'unix_socket'] as $value) {
            $envVar = 'TYPO3_INSTALL_DB_' . strtoupper($value);
            if (getenv($envVar) !== false) {
                $envCredentials[$value] = getenv($envVar);
                if($value === 'port') {
                    $envCredentials[$value] = (int)$envCredentials[$value];
                }
            }
        }

Reviews 2