r69479 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69478‎ | r69479 | r69480 >
Date:12:55, 17 July 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Refactor some more of the ugly b/c update logic out of updaters.inc
Modified paths:
  • /trunk/phase3/includes/installer/Update.php (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -952,41 +952,6 @@
953953 $up = new Update( $wgDatabase );
954954 $up->doUpdates();
955955
956 - // OpenID is still using this stupid thing, or we could kill this too
957 - global $wgUpdates;
958 - if ( isset( $wgUpdates[$wgDBtype] ) ) {
959 - foreach ( $wgUpdates[$wgDBtype] as $params ) {
960 - $func = array_shift( $params );
961 - call_user_func_array( $func, $params );
962 - flush();
963 - }
964 - }
965 -
966 - // / @fixme clean up this mess too!
967 - global $wgExtNewTables, $wgExtNewFields, $wgExtNewIndexes;
968 - # Add missing extension tables
969 - foreach ( $wgExtNewTables as $tableRecord ) {
970 - add_table( $tableRecord[0], $tableRecord[1], true );
971 - flush();
972 - }
973 - # Add missing extension fields
974 - foreach ( $wgExtNewFields as $fieldRecord ) {
975 - if ( $fieldRecord[0] != 'user' || $doUser ) {
976 - add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
977 - }
978 - flush();
979 - }
980 - # Add missing extension indexes
981 - foreach ( $wgExtNewIndexes as $fieldRecord ) {
982 - add_index( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
983 - flush();
984 - }
985 - # Add modified extension fields
986 - foreach ( $wgExtModifiedFields as $fieldRecord ) {
987 - modify_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
988 - flush();
989 - }
990 -
991956 wfOut( "Deleting old default messages (this may take a long time!)..." );
992957 if ( !defined( 'MW_NO_SETUP' ) ) {
993958 define( 'MW_NO_SETUP', true );
Index: trunk/phase3/includes/installer/Update.php
@@ -39,7 +39,10 @@
4040 call_user_func_array( $func, $params );
4141 flush();
4242 }
43 - $this->setAppliedUpdates( $version, $updates );
 43+ // some updates don't get recorded :(
 44+ if( $version !== 'always' ) {
 45+ $this->setAppliedUpdates( $version, $updates );
 46+ }
4447 }
4548 }
4649
@@ -48,14 +51,15 @@
4952 // style of recording our steps. Run all to be safe
5053 if( !$this->canUseNewUpdatelog() ) {
5154 $this->updates = $this->updater->getUpdates();
52 - return;
53 - }
54 - foreach( $this->updater->getUpdates() as $version => $updates ) {
55 - $appliedUpdates = $this->getAppliedUpdates( $version );
56 - if( !$appliedUpdates || $appliedUpdates != $updates ) {
57 - $this->updates[ $version ] = $updates;
 55+ } else {
 56+ foreach( $this->updater->getUpdates() as $version => $updates ) {
 57+ $appliedUpdates = $this->getAppliedUpdates( $version );
 58+ if( !$appliedUpdates || $appliedUpdates != $updates ) {
 59+ $this->updates[ $version ] = $updates;
 60+ }
5861 }
5962 }
 63+ $this->getOldGlobalUpdates();
6064 }
6165
6266 protected function getAppliedUpdates( $version ) {
@@ -92,4 +96,52 @@
9397 return $this->db->tableExists( 'updatelog' ) &&
9498 $this->db->fieldExists( 'updatelog', 'ul_value' );
9599 }
 100+
 101+ /**
 102+ * Before 1.17, we used to handle updates via stuff like $wgUpdates,
 103+ * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
 104+ * of this in 1.17 but we want to remain back-compatible for awhile. So
 105+ * load up these old global-based things into our update list. We can't
 106+ * version these like we do with our core updates, so they have to go
 107+ * in 'always'
 108+ */
 109+ private function getOldGlobalUpdates() {
 110+ global $wgUpdates, $wgExtNewFields, $wgExtNewTables,
 111+ $wgExtModifiedFields, $wgExtNewIndexes;
 112+
 113+ if( isset( $wgUpdates[ $this->db->getType() ] ) ) {
 114+ foreach( $wgUpdates[ $this->db->getType() ] as $upd ) {
 115+ $this->updates['always'][] = $upd;
 116+ }
 117+ }
 118+
 119+ foreach ( $wgExtNewTables as $tableRecord ) {
 120+ $this->updates['always'][] = array(
 121+ 'add_table', $tableRecord[0], $tableRecord[1], true
 122+ );
 123+ }
 124+
 125+ foreach ( $wgExtNewFields as $fieldRecord ) {
 126+ if ( $fieldRecord[0] != 'user' || $doUser ) {
 127+ $this->updates['always'][] = array(
 128+ 'add_field', $fieldRecord[0], $fieldRecord[1],
 129+ $fieldRecord[2], true
 130+ );
 131+ }
 132+ }
 133+
 134+ foreach ( $wgExtNewIndexes as $fieldRecord ) {
 135+ $this->updates['always'][] = array(
 136+ 'add_index', $fieldRecord[0], $fieldRecord[1],
 137+ $fieldRecord[2], true
 138+ );
 139+ }
 140+
 141+ foreach ( $wgExtModifiedFields as $fieldRecord ) {
 142+ $this->updates['always'][] = array(
 143+ 'modify_field', $fieldRecord[0], $fieldRecord[1],
 144+ $fieldRecord[2], true
 145+ );
 146+ }
 147+ }
96148 }

Comments

#Comment by Nikerabbit (talk | contribs)   04:36, 5 August 2010
+	/**
+	 * 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'
+	 */

The first part only applies to core, right? It sure confused me. Or if there is new way also for extensions, it should be mentioned somewhere how to use it.

#Comment by 😂 (talk | contribs)   16:07, 6 August 2010

There will be a new way for extensions (probably somehow using LoadExtensionSchemaUpdates). I just haven't finalized how I'm doing that yet. $wgExtNewTables/Fields/Indexes should continue working.

Status & tagging log