From acdfb5806a619f9d28c83e802f00ca1aaea834f4 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 15 Sep 2016 02:25:16 -0700 Subject: [PATCH 1/1] Move updater/installer specific methods out of DatabaseBase Change-Id: I995799fc15d2797ce7ab9ce2aca8beeef409447c --- includes/db/Database.php | 56 ------------------------ includes/installer/DatabaseInstaller.php | 43 +++++++++++++++++- includes/installer/DatabaseUpdater.php | 24 +++++++++- 3 files changed, 64 insertions(+), 59 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 0c357cc9ed..6c93f6c01c 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -681,43 +681,6 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { } } - /** - * Return a path to the DBMS-specific SQL file if it exists, - * otherwise default SQL file - * - * @param string $filename - * @return string - */ - private function getSqlFilePath( $filename ) { - global $IP; - $dbmsSpecificFilePath = "$IP/maintenance/" . $this->getType() . "/$filename"; - if ( file_exists( $dbmsSpecificFilePath ) ) { - return $dbmsSpecificFilePath; - } else { - return "$IP/maintenance/$filename"; - } - } - - /** - * Return a path to the DBMS-specific schema file, - * otherwise default to tables.sql - * - * @return string - */ - public function getSchemaPath() { - return $this->getSqlFilePath( 'tables.sql' ); - } - - /** - * Return a path to the DBMS-specific update key file, - * otherwise default to update-keys.sql - * - * @return string - */ - public function getUpdateKeysPath() { - return $this->getSqlFilePath( 'update-keys.sql' ); - } - /** * Get information about an index into an object * @param string $table Table name @@ -3380,25 +3343,6 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { return $error; } - /** - * Get the full path of a patch file. Originally based on archive() - * from updaters.inc. Keep in mind this always returns a patch, as - * it fails back to MySQL if no DB-specific patch can be found - * - * @param string $patch The name of the patch, like patch-something.sql - * @return string Full path to patch file - */ - public function patchPath( $patch ) { - global $IP; - - $dbType = $this->getType(); - if ( file_exists( "$IP/maintenance/$dbType/archives/$patch" ) ) { - return "$IP/maintenance/$dbType/archives/$patch"; - } else { - return "$IP/maintenance/archives/$patch"; - } - } - public function setSchemaVars( $vars ) { $this->mSchemaVars = $vars; } diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index 701403ea8f..ded2bd8aba 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -192,7 +192,7 @@ abstract class DatabaseInstaller { $this->db->begin( __METHOD__ ); $error = $this->db->sourceFile( - call_user_func( [ $this->db, $sourceFileMethod ] ) + call_user_func( [ $this, $sourceFileMethod ], $this->db ) ); if ( $error !== true ) { $this->db->reportQueryError( $error, 0, '', __METHOD__ ); @@ -227,6 +227,47 @@ abstract class DatabaseInstaller { return $this->stepApplySourceFile( 'getUpdateKeysPath', 'updates', false ); } + /** + * Return a path to the DBMS-specific SQL file if it exists, + * otherwise default SQL file + * + * @param IDatabase $db + * @param string $filename + * @return string + */ + private function getSqlFilePath( $db, $filename ) { + global $IP; + + $dbmsSpecificFilePath = "$IP/maintenance/" . $db->getType() . "/$filename"; + if ( file_exists( $dbmsSpecificFilePath ) ) { + return $dbmsSpecificFilePath; + } else { + return "$IP/maintenance/$filename"; + } + } + + /** + * Return a path to the DBMS-specific schema file, + * otherwise default to tables.sql + * + * @param IDatabase $db + * @return string + */ + public function getSchemaPath( $db ) { + return $this->getSqlFilePath( $db, 'tables.sql' ); + } + + /** + * Return a path to the DBMS-specific update key file, + * otherwise default to update-keys.sql + * + * @param IDatabase $db + * @return string + */ + public function getUpdateKeysPath( $db ) { + return $this->getSqlFilePath( $db, 'update-keys.sql' ); + } + /** * Create the tables for each extension the user enabled * @return Status diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 86b2f3bde4..0e4b098aeb 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -659,7 +659,7 @@ abstract class DatabaseUpdater { $this->output( "$msg ..." ); if ( !$isFullPath ) { - $path = $this->db->patchPath( $path ); + $path = $this->patchPath( $this->db, $path ); } if ( $this->fileHandle !== null ) { $this->copyFile( $path ); @@ -671,6 +671,26 @@ abstract class DatabaseUpdater { return true; } + /** + * Get the full path of a patch file. Originally based on archive() + * from updaters.inc. Keep in mind this always returns a patch, as + * it fails back to MySQL if no DB-specific patch can be found + * + * @param IDatabase $db + * @param string $patch The name of the patch, like patch-something.sql + * @return string Full path to patch file + */ + public function patchPath( IDatabase $db, $patch ) { + global $IP; + + $dbType = $db->getType(); + if ( file_exists( "$IP/maintenance/$dbType/archives/$patch" ) ) { + return "$IP/maintenance/$dbType/archives/$patch"; + } else { + return "$IP/maintenance/archives/$patch"; + } + } + /** * Add a new table to the database * @@ -1078,7 +1098,7 @@ abstract class DatabaseUpdater { global $wgProfiler; if ( !$this->doTable( 'profiling' ) ) { - return true; + return; } $profileToDb = false; -- 2.20.1