Skip to content

Commit

Permalink
Fix issue with DATABASE_URL
Browse files Browse the repository at this point in the history
Unavailable wp_parse_url() method was causing it fail.

Also adds expllicit SSL support.
  • Loading branch information
edjeavons committed Mar 12, 2024
1 parent 9295fde commit 4111ccc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions config/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@
$table_prefix = $_ENV['DB_PREFIX'] ?? 'wp_';

if ( isset( $_ENV['DATABASE_URL'] ) ) {
$dsn = (object) wp_parse_url( $_ENV['DATABASE_URL'] );

Config::define( 'DB_NAME', substr( $dsn->path, 1 ) );
Config::define( 'DB_USER', $dsn->user );
Config::define( 'DB_PASSWORD', isset( $dsn->pass ) ? $dsn->pass : null );
Config::define( 'DB_HOST', isset( $dsn->port ) ? "{$dsn->host}:{$dsn->port}" : $dsn->host );
$dsn = parse_url( $_ENV['DATABASE_URL'] );
Config::define( 'DB_NAME', substr( $dsn['path'], 1 ) );
Config::define( 'DB_USER', $dsn['user'] );
Config::define( 'DB_PASSWORD', $dsn['pass'] ?? null );
Config::define( 'DB_HOST', isset( $dsn['port'] ) ? "{$dsn['host']}:{$dsn['port']}" : $dsn['host'] );
if ( str_contains( $dsn['query'] ?? '', 'ssl-mode=REQUIRED' ) ) {
Config::define( 'MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL );
}
}

/**
Expand Down

0 comments on commit 4111ccc

Please sign in to comment.