Fix web frontend crash on socket setups without DB_SERVER_PORT
env_string('DB_SERVER_PORT') returns '' when the variable is unset, and that
empty string is passed to mysqli::real_connect()'s ?int $port argument in
MysqlDbBackend::connect(), throwing a fatal TypeError under PHP 8 that breaks
every frontend page (HTTP 500) on socket / no-port setups. Regressed in the
web config redesign, which replaced getenv() (returns false -> int 0) with
env_string() (returns '').
Add an env_int() helper that maps both unset and empty to the default and
returns an int, and use it for the DB port.
This commit is contained in:
parent
acfd59eac4
commit
cc028ed792
|
|
@ -6,6 +6,12 @@ function env_string(string $name, string $default = ''): string {
|
|||
return ($value === false) ? $default : $value;
|
||||
}
|
||||
|
||||
function env_int(string $name, int $default = 0): int {
|
||||
$value = getenv($name);
|
||||
|
||||
return ($value === false || $value === '') ? $default : (int) $value;
|
||||
}
|
||||
|
||||
function env_bool(string $name, bool $default = false): bool {
|
||||
$value = getenv($name);
|
||||
|
||||
|
|
@ -40,7 +46,7 @@ function resolve_file(string $default_path, string $env_name): string {
|
|||
|
||||
$DB['TYPE'] = env_string('DB_SERVER_TYPE');
|
||||
$DB['SERVER'] = env_string('DB_SERVER_HOST');
|
||||
$DB['PORT'] = env_string('DB_SERVER_PORT');
|
||||
$DB['PORT'] = env_int('DB_SERVER_PORT');
|
||||
$DB['DATABASE'] = env_string('DB_SERVER_DBNAME');
|
||||
$DB['SCHEMA'] = env_string('DB_SERVER_SCHEMA');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue