From: Aaron Schulz Date: Sat, 25 Aug 2018 05:49:15 +0000 (-0700) Subject: Make MysqlInstaller check if DB exists in a cleaner way X-Git-Tag: 1.34.0-rc.0~4305^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=0a07c38936652044ef0700278d5e1eec77dc9890;p=lhc%2Fweb%2Fwiklou.git Make MysqlInstaller check if DB exists in a cleaner way Query the information schema rather than seeing if selectDB() returns false. This makes the installer able to handle an exception based failure mode. Change-Id: I7912b9d3b8501fbc92cb731547ae10fa2b0176db --- diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 45f932a83b..1b0780bc8c 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -485,18 +485,32 @@ class MysqlInstaller extends DatabaseInstaller { /** @var Database $conn */ $conn = $status->value; $dbName = $this->getVar( 'wgDBname' ); - if ( !$conn->selectDB( $dbName ) ) { + if ( !$this->databaseExists( $dbName ) ) { $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8", __METHOD__ ); - $conn->selectDB( $dbName ); } + $conn->selectDB( $dbName ); $this->setupSchemaVars(); return $status; } + /** + * Try to see if a given database exists + * @param string $dbName Database name to check + * @return bool + */ + private function databaseExists( $dbName ) { + $encDatabase = $this->db->addQuotes( $dbName ); + + return $this->db->query( + "SELECT 1 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = $encDatabase", + __METHOD__ + )->numRows() > 0; + } + /** * @return Status */