From 957eeac7855578d81777ac6a254a7167c1668d12 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sat, 17 Jul 2010 12:55:52 +0000 Subject: [PATCH] Refactor some more of the ugly b/c update logic out of updaters.inc --- includes/installer/Update.php | 66 +++++++++++++++++++++++++++++++---- maintenance/updaters.inc | 35 ------------------- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/includes/installer/Update.php b/includes/installer/Update.php index b4e8dc8fd5..ebe98308ce 100644 --- a/includes/installer/Update.php +++ b/includes/installer/Update.php @@ -39,7 +39,10 @@ class Update { call_user_func_array( $func, $params ); flush(); } - $this->setAppliedUpdates( $version, $updates ); + // some updates don't get recorded :( + if( $version !== 'always' ) { + $this->setAppliedUpdates( $version, $updates ); + } } } @@ -48,14 +51,15 @@ class Update { // style of recording our steps. Run all to be safe if( !$this->canUseNewUpdatelog() ) { $this->updates = $this->updater->getUpdates(); - return; - } - foreach( $this->updater->getUpdates() as $version => $updates ) { - $appliedUpdates = $this->getAppliedUpdates( $version ); - if( !$appliedUpdates || $appliedUpdates != $updates ) { - $this->updates[ $version ] = $updates; + } else { + foreach( $this->updater->getUpdates() as $version => $updates ) { + $appliedUpdates = $this->getAppliedUpdates( $version ); + if( !$appliedUpdates || $appliedUpdates != $updates ) { + $this->updates[ $version ] = $updates; + } } } + $this->getOldGlobalUpdates(); } protected function getAppliedUpdates( $version ) { @@ -92,4 +96,52 @@ class Update { return $this->db->tableExists( 'updatelog' ) && $this->db->fieldExists( 'updatelog', 'ul_value' ); } + + /** + * Before 1.17, we used to handle updates via stuff like $wgUpdates, + * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot + * of this in 1.17 but we want to remain back-compatible for awhile. So + * load up these old global-based things into our update list. We can't + * version these like we do with our core updates, so they have to go + * in 'always' + */ + private function getOldGlobalUpdates() { + global $wgUpdates, $wgExtNewFields, $wgExtNewTables, + $wgExtModifiedFields, $wgExtNewIndexes; + + if( isset( $wgUpdates[ $this->db->getType() ] ) ) { + foreach( $wgUpdates[ $this->db->getType() ] as $upd ) { + $this->updates['always'][] = $upd; + } + } + + foreach ( $wgExtNewTables as $tableRecord ) { + $this->updates['always'][] = array( + 'add_table', $tableRecord[0], $tableRecord[1], true + ); + } + + foreach ( $wgExtNewFields as $fieldRecord ) { + if ( $fieldRecord[0] != 'user' || $doUser ) { + $this->updates['always'][] = array( + 'add_field', $fieldRecord[0], $fieldRecord[1], + $fieldRecord[2], true + ); + } + } + + foreach ( $wgExtNewIndexes as $fieldRecord ) { + $this->updates['always'][] = array( + 'add_index', $fieldRecord[0], $fieldRecord[1], + $fieldRecord[2], true + ); + } + + foreach ( $wgExtModifiedFields as $fieldRecord ) { + $this->updates['always'][] = array( + 'modify_field', $fieldRecord[0], $fieldRecord[1], + $fieldRecord[2], true + ); + } + } } diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 33b0cd8707..9535260228 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -952,41 +952,6 @@ function do_all_updates( $shared = false, $purge = true ) { $up = new Update( $wgDatabase ); $up->doUpdates(); - // OpenID is still using this stupid thing, or we could kill this too - global $wgUpdates; - if ( isset( $wgUpdates[$wgDBtype] ) ) { - foreach ( $wgUpdates[$wgDBtype] as $params ) { - $func = array_shift( $params ); - call_user_func_array( $func, $params ); - flush(); - } - } - - // / @fixme clean up this mess too! - global $wgExtNewTables, $wgExtNewFields, $wgExtNewIndexes; - # Add missing extension tables - foreach ( $wgExtNewTables as $tableRecord ) { - add_table( $tableRecord[0], $tableRecord[1], true ); - flush(); - } - # Add missing extension fields - foreach ( $wgExtNewFields as $fieldRecord ) { - if ( $fieldRecord[0] != 'user' || $doUser ) { - add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true ); - } - flush(); - } - # Add missing extension indexes - foreach ( $wgExtNewIndexes as $fieldRecord ) { - add_index( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true ); - flush(); - } - # Add modified extension fields - foreach ( $wgExtModifiedFields as $fieldRecord ) { - modify_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true ); - flush(); - } - wfOut( "Deleting old default messages (this may take a long time!)..." ); if ( !defined( 'MW_NO_SETUP' ) ) { define( 'MW_NO_SETUP', true ); -- 2.20.1