X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Finstaller%2FDatabaseInstaller.php;h=8a01b32b28fe0e0eebc05ee8c083fb59e2be2e2f;hb=4b35513ef16a125a9ccb39054150e17c5bd8b218;hp=321884bd5547feaee7d7d14c585545d3fecbb010;hpb=f73c54a0a47585f4baf1aee38a4a1a059bfb259c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index 321884bd55..6ccf2d55d3 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -163,19 +163,26 @@ abstract class DatabaseInstaller { } /** - * Create database tables from scratch. + * Apply a SQL source file to the database as part of running an installation step. * + * @param string $sourceFileMethod + * @param string $stepName + * @param string $archiveTableMustNotExist * @return Status */ - public function createTables() { + private function stepApplySourceFile( + $sourceFileMethod, + $stepName, + $archiveTableMustNotExist = false + ) { $status = $this->getConnection(); if ( !$status->isOK() ) { return $status; } $this->db->selectDB( $this->getVar( 'wgDBname' ) ); - if ( $this->db->tableExists( 'archive', __METHOD__ ) ) { - $status->warning( 'config-install-tables-exist' ); + if ( $archiveTableMustNotExist && $this->db->tableExists( 'archive', __METHOD__ ) ) { + $status->warning( "config-$stepName-tables-exist" ); $this->enableLB(); return $status; @@ -184,11 +191,13 @@ abstract class DatabaseInstaller { $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files $this->db->begin( __METHOD__ ); - $error = $this->db->sourceFile( $this->db->getSchemaPath() ); + $error = $this->db->sourceFile( + call_user_func( array( $this->db, $sourceFileMethod ) ) + ); if ( $error !== true ) { $this->db->reportQueryError( $error, 0, '', __METHOD__ ); $this->db->rollback( __METHOD__ ); - $status->fatal( 'config-install-tables-failed', $error ); + $status->fatal( "config-$stepName-tables-failed", $error ); } else { $this->db->commit( __METHOD__ ); } @@ -200,6 +209,24 @@ abstract class DatabaseInstaller { return $status; } + /** + * Create database tables from scratch. + * + * @return Status + */ + public function createTables() { + return $this->stepApplySourceFile( 'getSchemaPath', 'install', true ); + } + + /** + * Insert update keys into table to prevent running unneded updates. + * + * @return Status + */ + public function insertUpdateKeys() { + return $this->stepApplySourceFile( 'getUpdateKeysPath', 'updates', false ); + } + /** * Create the tables for each extension the user enabled * @return Status @@ -219,7 +246,7 @@ abstract class DatabaseInstaller { /** * Get the DBMS-specific options for LocalSettings.php generation. * - * @return String + * @return string */ abstract public function getLocalSettings(); @@ -267,7 +294,7 @@ abstract class DatabaseInstaller { /** * Perform database upgrades * - * @return Boolean + * @return bool */ public function doUpgrade() { $this->setupSchemaVars(); @@ -278,7 +305,7 @@ abstract class DatabaseInstaller { $up = DatabaseUpdater::newForDB( $this->db ); try { $up->doUpdates(); - } catch ( MWException $e ) { + } catch ( Exception $e ) { echo "\nAn error occurred:\n"; echo $e->getText(); $ret = false; @@ -314,7 +341,7 @@ abstract class DatabaseInstaller { /** * Construct and initialise parent. * This is typically only called from Installer::getDBInstaller() - * @param $parent + * @param WebInstaller $parent */ public function __construct( $parent ) { $this->parent = $parent; @@ -324,7 +351,7 @@ abstract class DatabaseInstaller { * Convenience function. * Check if a named extension is present. * - * @param $name + * @param string $name * @return bool */ protected static function checkExtension( $name ) { @@ -333,7 +360,7 @@ abstract class DatabaseInstaller { /** * Get the internationalised name for this DBMS. - * @return String + * @return string */ public function getReadableName() { // Messages: config-type-mysql, config-type-postgres, config-type-sqlite, @@ -342,12 +369,17 @@ abstract class DatabaseInstaller { } /** - * Get a name=>value map of MW configuration globals that overrides. - * DefaultSettings.php + * Get a name=>value map of MW configuration globals for the default values. * @return array */ public function getGlobalDefaults() { - return array(); + $defaults = array(); + foreach ( $this->getGlobalNames() as $var ) { + if ( isset( $GLOBALS[$var] ) ) { + $defaults[$var] = $GLOBALS[$var]; + } + } + return $defaults; } /** @@ -360,8 +392,8 @@ abstract class DatabaseInstaller { /** * Get a variable, taking local defaults into account. - * @param $var string - * @param $default null + * @param string $var + * @param mixed|null $default * @return mixed */ public function getVar( $var, $default = null ) { @@ -378,8 +410,8 @@ abstract class DatabaseInstaller { /** * Convenience alias for $this->parent->setVar() - * @param $name string - * @param $value mixed + * @param string $name + * @param mixed $value */ public function setVar( $name, $value ) { $this->parent->setVar( $name, $value ); @@ -388,10 +420,10 @@ abstract class DatabaseInstaller { /** * Get a labelled text box to configure a local variable. * - * @param $var string - * @param $label string - * @param $attribs array - * @param $helpData string + * @param string $var + * @param string $label + * @param array $attribs + * @param string $helpData * @return string */ public function getTextBox( $var, $label, $attribs = array(), $helpData = "" ) { @@ -415,10 +447,10 @@ abstract class DatabaseInstaller { * Get a labelled password box to configure a local variable. * Implements password hiding. * - * @param $var string - * @param $label string - * @param $attribs array - * @param $helpData string + * @param string $var + * @param string $label + * @param array $attribs + * @param string $helpData * @return string */ public function getPasswordBox( $var, $label, $attribs = array(), $helpData = "" ) { @@ -464,8 +496,7 @@ abstract class DatabaseInstaller { /** * Get a set of labelled radio buttons. * - * @param $params Array: - * Parameters are: + * @param array $params Parameters are: * var: The variable to be configured (required) * label: The message name for the label (required) * itemLabelPrefix: The message name prefix for the item labels (required) @@ -485,7 +516,7 @@ abstract class DatabaseInstaller { * Convenience function to set variables based on form data. * Assumes that variables containing "password" in the name are (potentially * fake) passwords. - * @param $varNames Array + * @param array $varNames * @return array */ public function setVarsFromRequest( $varNames ) { @@ -500,7 +531,7 @@ abstract class DatabaseInstaller { * Traditionally, this is done by testing for the existence of either * the revision table or the cur table. * - * @return Boolean + * @return bool */ public function needsUpgrade() { $status = $this->getConnection(); @@ -519,7 +550,7 @@ abstract class DatabaseInstaller { /** * Get a standard install-user fieldset. * - * @return String + * @return string */ public function getInstallUserBox() { return Html::openElement( 'fieldset' ) . @@ -554,7 +585,7 @@ abstract class DatabaseInstaller { * @param string|bool $noCreateMsg Message to display instead of the creation checkbox. * Set this to false to show a creation checkbox (default). * - * @return String + * @return string */ public function getWebUserBox( $noCreateMsg = false ) { $wrapperStyle = $this->getVar( '_SameAccount' ) ? 'display: none' : ''; @@ -631,7 +662,7 @@ abstract class DatabaseInstaller { if ( $row == "" ) { continue; } - $row .= "||"; + $row .= "|"; $interwikis[] = array_combine( array( 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ), explode( '|', $row )