Use "try-catch" block instead of "if" block to prevent interruption of new installation
authorRazeSoldier <razesoldier@outlook.com>
Mon, 11 Feb 2019 11:49:38 +0000 (19:49 +0800)
committerRazeSoldier <razesoldier@outlook.com>
Tue, 12 Feb 2019 05:38:32 +0000 (13:38 +0800)
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
includes/installer/DatabaseInstaller.php

index 284d19f..101a986 100644 (file)
@@ -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.
index a146ae4..bb30d3d 100644 (file)
@@ -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;
                }