From 56d2fc8081502ebcc793e17cc9c7083c8b9d2126 Mon Sep 17 00:00:00 2001 From: RazeSoldier Date: Mon, 11 Feb 2019 19:49:38 +0800 Subject: [PATCH] Use "try-catch" block instead of "if" block to prevent interruption of new installation New installation blocked when checking if the DB exists, because when select DB, if it fails, it will throw an exception. So I modify the checking logic to determine if there is an exception thrown instead of detecting the return value. Bug: T215566 Change-Id: I6817997434df7adc79fbc1b224b77c0daa8cc11d --- RELEASE-NOTES-1.33 | 2 ++ includes/installer/DatabaseInstaller.php | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index 284d19f10b..101a9861fe 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -78,6 +78,8 @@ production. === Bug fixes in 1.33 === * (T164211) Special:UserRights could sometimes fail with a "conflict detected" error when there weren't any conflicts. +* (T215566) Unable to determine if the database exists + during a fresh installation. === Action API changes in 1.33 === * (T198913) Added 'ApiOptions' hook. diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index a146ae4ae8..bb30d3d1ef 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -23,6 +23,8 @@ use Wikimedia\Rdbms\LBFactorySingle; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IDatabase; +use Wikimedia\Rdbms\DBExpectedError; +use Wikimedia\Rdbms\DBConnectionError; /** * Base class for DBMS-specific installation helper classes. @@ -620,7 +622,12 @@ abstract class DatabaseInstaller { return false; } - if ( !$this->db->selectDB( $this->getVar( 'wgDBname' ) ) ) { + try { + $this->db->selectDB( $this->getVar( 'wgDBname' ) ); + } catch ( DBConnectionError $e ) { + // Don't catch DBConnectionError + throw $e; + } catch ( DBExpectedError $e ) { return false; } -- 2.20.1