@@ -25,6 +25,7 @@ class InstallCommand extends Command
2525
2626 protected ?OutputInterface $ logSection = null ;
2727 protected ?TuiRenderer $ tui = null ;
28+ protected ?string $ lastDatabaseConnectionError = null ;
2829 protected array $ composerCommandCache = [];
2930 protected array $ steps = [
3031 'php ' => ['label ' => 'Step 1: Validate PHP version ' , 'completed ' => false ],
@@ -220,6 +221,13 @@ protected function gatherInputs(InputInterface $input, OutputInterface $output):
220221 if ($ this ->testDatabaseConnection ($ inputs ['database ' ])) {
221222 $ databaseConnected = true ;
222223 } else {
224+ if (!$ input ->isInteractive ()) {
225+ $ msg = is_string ($ this ->lastDatabaseConnectionError ) ? trim ($ this ->lastDatabaseConnectionError ) : '' ;
226+ if ($ msg === '' ) {
227+ $ msg = 'Unknown database connection error. ' ;
228+ }
229+ throw new \RuntimeException ('Database connection failed: ' . $ msg );
230+ }
223231 // Connection failed, ask user what to do
224232 if (!$ this ->askRetryDatabaseConnection ()) {
225233 throw new \RuntimeException ('Installation cancelled by user. ' );
@@ -436,6 +444,7 @@ protected function askDatabasePassword(): string
436444 */
437445 protected function testDatabaseConnection (array $ config ): bool
438446 {
447+ $ this ->lastDatabaseConnectionError = null ;
439448 $ this ->tui ->addLog ('Testing database connection... ' );
440449
441450 try {
@@ -464,13 +473,15 @@ protected function testDatabaseConnection(array $config): bool
464473 'Please install PHP extension: ' . ($ type === 'sqlite ' ? 'pdo_sqlite ' : 'pdo_ ' . $ type ) . '. ' ,
465474 2
466475 );
476+ $ this ->lastDatabaseConnectionError = 'PDO driver for ' . $ driverName . ' is not available. ' ;
467477 return false ;
468478 }
469479
470480 if ($ type === 'sqlite ' ) {
471481 // SQLite: Connect directly to the database file
472482 if (empty ($ config ['name ' ])) {
473483 $ this ->tui ->replaceLastLogs ('<fg=red>✗</> Database connection failed: SQLite database path is required. ' , 2 );
484+ $ this ->lastDatabaseConnectionError = 'SQLite database path is required. ' ;
474485 return false ;
475486 }
476487 $ this ->createConnection ($ config );
@@ -536,6 +547,7 @@ protected function testDatabaseConnection(array $config): bool
536547 $ errorMessage = "PDO driver for {$ driverName } is not installed. Please install PHP extension: {$ extensionName }" ;
537548 }
538549
550+ $ this ->lastDatabaseConnectionError = $ errorMessage ;
539551 $ this ->tui ->replaceLastLogs ('<fg=red>✗</> Database connection failed: ' . $ errorMessage , 2 );
540552 return false ;
541553 }
0 commit comments