r69645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69644‎ | r69645 | r69646 >
Date:22:28, 20 July 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
* Split Mysql/Sqlite updates into their own files
* Rename Update -> DatabaseUpdaters to be more consistent with DatabaseInstaller
* Made DatabaseUpdaters abstract and merged the Updaters interface in, had Mysql/Oracle/Sqlite subclass it. Entry point is now factory DatabaseUpdaters::newForDB()
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (added) (history)
  • /trunk/phase3/includes/installer/MysqlUpdater.php (added) (history)
  • /trunk/phase3/includes/installer/SqliteUpdater.php (added) (history)
  • /trunk/phase3/includes/installer/Update.php (deleted) (history)
  • /trunk/phase3/includes/installer/Updaters.php (deleted) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -949,7 +949,7 @@
950950 }
951951
952952 global $wgDatabase;
953 - $up = new Update( $wgDatabase );
 953+ $up = DatabaseUpdater::newForDb( $wgDatabase );
954954 $up->doUpdates();
955955
956956 wfOut( "Deleting old default messages (this may take a long time!)..." );
Index: trunk/phase3/includes/installer/Update.php
@@ -1,153 +0,0 @@
2 -<?php
3 -
4 -/*
5 - * Class for handling database updates. Roughly based off of updaters.inc, with
6 - * a few improvements :)
7 - */
8 -class Update {
9 -
10 - /**
11 - * Array of updates to perform on the database
12 - *
13 - * @var array
14 - */
15 - protected $updates = array();
16 -
17 - protected $db;
18 -
19 - protected $updater;
20 -
21 - public function __construct( $db ) {
22 - $this->db = $db;
23 - switch( $this->db->getType() ) {
24 - case 'mysql':
25 - $this->updater = new MysqlUpdater();
26 - break;
27 - case 'sqlite':
28 - $this->updater = new SqliteUpdater();
29 - break;
30 - case 'oracle':
31 - $this->updater = new OracleUpdater();
32 - break;
33 - default:
34 - throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
35 - }
36 - }
37 -
38 - public function doUpdates() {
39 - global $IP;
40 - require_once( "$IP/maintenance/updaters.inc" );
41 - $this->loadUpdates();
42 - foreach ( $this->updates as $version => $updates ) {
43 - foreach( $updates as $params ) {
44 - $func = array_shift( $params );
45 - call_user_func_array( $func, $params );
46 - flush();
47 - }
48 - // some updates don't get recorded :(
49 - if( $version !== 'always' ) {
50 - $this->setAppliedUpdates( $version, $updates );
51 - }
52 - }
53 - }
54 -
55 - protected function loadUpdates() {
56 - // If the updatelog table hasn't been upgraded, we can't use the new
57 - // style of recording our steps. Run all to be safe
58 - if( !$this->canUseNewUpdatelog() ) {
59 - $this->updates = $this->updater->getUpdates();
60 - } else {
61 - foreach( $this->updater->getUpdates() as $version => $updates ) {
62 - $appliedUpdates = $this->getAppliedUpdates( $version );
63 - if( !$appliedUpdates || $appliedUpdates != $updates ) {
64 - $this->updates[ $version ] = $updates;
65 - }
66 - }
67 - }
68 - $this->getOldGlobalUpdates();
69 - }
70 -
71 - protected function getAppliedUpdates( $version ) {
72 - $key = "updatelist-$version";
73 - $val = $this->db->selectField( 'updatelog', 'ul_value',
74 - array( 'ul_key' => $key ), __METHOD__ );
75 - if( !$val ) {
76 - return null;
77 - } else {
78 - return unserialize( $val );
79 - }
80 - }
81 -
82 - protected function setAppliedUpdates( $version, $updates = array() ) {
83 - if( !$this->canUseNewUpdatelog() ) {
84 - return;
85 - }
86 - $key = "updatelist-$version";
87 - $this->db->delete( 'updatelog', array( 'ul_key' => $key ), __METHOD__ );
88 - $this->db->insert( 'updatelog',
89 - array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
90 - __METHOD__ );
91 - }
92 -
93 - /**
94 - * Updatelog was changed in 1.17 to have a ul_value column so we can record
95 - * more information about what kind of updates we've done (that's what this
96 - * class does). Pre-1.17 wikis won't have this column, and really old wikis
97 - * might not even have updatelog at all
98 - *
99 - * @return boolean
100 - */
101 - protected function canUseNewUpdatelog() {
102 - return $this->db->tableExists( 'updatelog' ) &&
103 - $this->db->fieldExists( 'updatelog', 'ul_value' );
104 - }
105 -
106 - /**
107 - * Before 1.17, we used to handle updates via stuff like $wgUpdates,
108 - * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
109 - * of this in 1.17 but we want to remain back-compatible for awhile. So
110 - * load up these old global-based things into our update list. We can't
111 - * version these like we do with our core updates, so they have to go
112 - * in 'always'
113 - */
114 - private function getOldGlobalUpdates() {
115 - global $wgUpdates, $wgExtNewFields, $wgExtNewTables,
116 - $wgExtModifiedFields, $wgExtNewIndexes;
117 -
118 - if( isset( $wgUpdates[ $this->db->getType() ] ) ) {
119 - foreach( $wgUpdates[ $this->db->getType() ] as $upd ) {
120 - $this->updates['always'][] = $upd;
121 - }
122 - }
123 -
124 - foreach ( $wgExtNewTables as $tableRecord ) {
125 - $this->updates['always'][] = array(
126 - 'add_table', $tableRecord[0], $tableRecord[1], true
127 - );
128 - }
129 -
130 - foreach ( $wgExtNewFields as $fieldRecord ) {
131 - if ( $fieldRecord[0] != 'user' || $doUser ) {
132 - $this->updates['always'][] = array(
133 - 'add_field', $fieldRecord[0], $fieldRecord[1],
134 - $fieldRecord[2], true
135 - );
136 - }
137 - }
138 -
139 - foreach ( $wgExtNewIndexes as $fieldRecord ) {
140 - $this->updates['always'][] = array(
141 - 'add_index', $fieldRecord[0], $fieldRecord[1],
142 - $fieldRecord[2], true
143 - );
144 - }
145 -
146 - foreach ( $wgExtModifiedFields as $fieldRecord ) {
147 - $this->updates['always'][] = array(
148 - 'modify_field', $fieldRecord[0], $fieldRecord[1],
149 - $fieldRecord[2], true
150 - );
151 - }
152 - }
153 -
154 -}
\ No newline at end of file
Index: trunk/phase3/includes/installer/Updaters.php
@@ -1,231 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * All DBs supported by MediaWiki need to implement this. Base interface for
6 - * Updaters, which is replacing updaters.inc
7 - */
8 -interface Updaters {
9 -
10 - /**
11 - * Get an array of updates to perform on the database. Should return a
12 - * mutli-dimensional array. The main key is the MediaWiki version (1.12,
13 - * 1.13...) with the values being arrays of updates, identical to how
14 - * updaters.inc did it (for now)
15 - *
16 - * @return Array
17 - */
18 - public function getUpdates();
19 -
20 -}
21 -
22 -/**
23 - * Mysql implementation.
24 - */
25 -class MysqlUpdater implements Updaters {
26 -
27 - public function getUpdates() {
28 - return array(
29 - '1.2' => array(
30 - array( 'add_field', 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ),
31 - array( 'add_field', 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
32 - array( 'do_interwiki_update' ),
33 - array( 'do_index_update' ),
34 - array( 'add_table', 'hitcounter', 'patch-hitcounter.sql' ),
35 - array( 'add_field', 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
36 - ),
37 - '1.3' => array(
38 - array( 'add_field', 'user', 'user_real_name', 'patch-user-realname.sql' ),
39 - array( 'add_table', 'querycache', 'patch-querycache.sql' ),
40 - array( 'add_table', 'objectcache', 'patch-objectcache.sql' ),
41 - array( 'add_table', 'categorylinks', 'patch-categorylinks.sql' ),
42 - array( 'do_old_links_update' ),
43 - array( 'fix_ancient_imagelinks' ),
44 - array( 'add_field', 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
45 - ),
46 - '1.4' => array(
47 - array( 'do_image_name_unique_update' ),
48 - array( 'add_field', 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
49 - array( 'add_field', 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
50 - array( 'add_table', 'logging', 'patch-logging.sql' ),
51 - array( 'add_field', 'user', 'user_token', 'patch-user_token.sql' ),
52 - array( 'do_watchlist_update' ),
53 - array( 'do_user_update' ),
54 - ),
55 - '1.5' => array(
56 - array( 'do_schema_restructuring' ),
57 - array( 'add_field', 'logging', 'log_params', 'patch-log_params.sql' ),
58 - array( 'check_bin', 'logging', 'log_title', 'patch-logging-title.sql', ),
59 - array( 'add_field', 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ),
60 - array( 'add_field', 'page', 'page_len', 'patch-page_len.sql' ),
61 - array( 'do_inverse_timestamp' ),
62 - array( 'do_text_id' ),
63 - array( 'add_field', 'revision', 'rev_deleted', 'patch-rev_deleted.sql' ),
64 - array( 'add_field', 'image', 'img_width', 'patch-img_width.sql' ),
65 - array( 'add_field', 'image', 'img_metadata', 'patch-img_metadata.sql' ),
66 - array( 'add_field', 'user', 'user_email_token', 'patch-user_email_token.sql' ),
67 - array( 'add_field', 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ),
68 - array( 'do_namespace_size' ),
69 - array( 'add_field', 'image', 'img_media_type', 'patch-img_media_type.sql' ),
70 - array( 'do_pagelinks_update' ),
71 - array( 'do_drop_img_type' ),
72 - array( 'do_user_unique_update' ),
73 - array( 'do_user_groups_update' ),
74 - array( 'add_field', 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ),
75 - array( 'add_table', 'user_newtalk', 'patch-usernewtalk2.sql' ),
76 - array( 'add_table', 'transcache', 'patch-transcache.sql' ),
77 - array( 'add_field', 'interwiki', 'iw_trans', 'patch-interwiki-trans.sql' ),
78 - array( 'add_table', 'trackbacks', 'patch-trackbacks.sql' ),
79 - ),
80 - '1.6' => array(
81 - array( 'do_watchlist_null' ),
82 - array( 'do_logging_timestamp_index' ),
83 - array( 'add_field', 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ),
84 - array( 'do_page_random_update' ),
85 - array( 'add_field', 'user', 'user_registration', 'patch-user_registration.sql' ),
86 - array( 'do_templatelinks_update' ),
87 - array( 'add_table', 'externallinks', 'patch-externallinks.sql' ),
88 - array( 'add_table', 'job', 'patch-job.sql' ),
89 - array( 'add_field', 'site_stats', 'ss_images', 'patch-ss_images.sql' ),
90 - array( 'add_table', 'langlinks', 'patch-langlinks.sql' ),
91 - array( 'add_table', 'querycache_info', 'patch-querycacheinfo.sql' ),
92 - array( 'add_table', 'filearchive', 'patch-filearchive.sql' ),
93 - array( 'add_field', 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ),
94 - array( 'do_rc_indices_update' ),
95 - ),
96 - '1.9' => array(
97 - array( 'add_field', 'user', 'user_newpass_time', 'patch-user_newpass_time.sql' ),
98 - array( 'add_table', 'redirect', 'patch-redirect.sql' ),
99 - array( 'add_table', 'querycachetwo', 'patch-querycachetwo.sql' ),
100 - array( 'add_field', 'ipblocks', 'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ),
101 - array( 'do_backlinking_indices_update' ),
102 - array( 'add_field', 'recentchanges', 'rc_old_len', 'patch-rc_len.sql' ),
103 - array( 'add_field', 'user', 'user_editcount', 'patch-user_editcount.sql' ),
104 - ),
105 - '1.10' => array(
106 - array( 'do_restrictions_update' ),
107 - array( 'add_field', 'logging', 'log_id', 'patch-log_id.sql' ),
108 - array( 'add_field', 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ),
109 - array( 'add_field', 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ),
110 - array( 'add_field', 'revision', 'rev_len', 'patch-rev_len.sql' ),
111 - array( 'add_field', 'recentchanges', 'rc_deleted', 'patch-rc_deleted.sql' ),
112 - array( 'add_field', 'logging', 'log_deleted', 'patch-log_deleted.sql' ),
113 - array( 'add_field', 'archive', 'ar_deleted', 'patch-ar_deleted.sql' ),
114 - array( 'add_field', 'ipblocks', 'ipb_deleted', 'patch-ipb_deleted.sql' ),
115 - array( 'add_field', 'filearchive', 'fa_deleted', 'patch-fa_deleted.sql' ),
116 - array( 'add_field', 'archive', 'ar_len', 'patch-ar_len.sql' ),
117 - ),
118 - '1.11' => array(
119 - array( 'add_field', 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ),
120 - array( 'do_categorylinks_indices_update' ),
121 - array( 'add_field', 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql' ),
122 - array( 'do_archive_user_index' ),
123 - array( 'do_image_user_index' ),
124 - array( 'do_oldimage_user_index' ),
125 - array( 'add_field', 'archive', 'ar_page_id', 'patch-archive-page_id.sql' ),
126 - array( 'add_field', 'image', 'img_sha1', 'patch-img_sha1.sql' ),
127 - ),
128 - '1.12' => array(
129 - array( 'add_table', 'protected_titles', 'patch-protected_titles.sql' ),
130 - ),
131 - '1.13' => array(
132 - array( 'add_field', 'ipblocks', 'ipb_by_text', 'patch-ipb_by_text.sql' ),
133 - array( 'add_table', 'page_props', 'patch-page_props.sql' ),
134 - array( 'add_table', 'updatelog', 'patch-updatelog.sql' ),
135 - array( 'add_table', 'category', 'patch-category.sql' ),
136 - array( 'do_category_population' ),
137 - array( 'add_field', 'archive', 'ar_parent_id', 'patch-ar_parent_id.sql' ),
138 - array( 'add_field', 'user_newtalk', 'user_last_timestamp', 'patch-user_last_timestamp.sql' ),
139 - array( 'do_populate_parent_id' ),
140 - array( 'check_bin', 'protected_titles', 'pt_title', 'patch-pt_title-encoding.sql', ),
141 - array( 'maybe_do_profiling_memory_update' ),
142 - array( 'do_filearchive_indices_update' ),
143 - ),
144 - '1.14' => array(
145 - array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ),
146 - array( 'do_active_users_init' ),
147 - array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ),
148 - ),
149 - '1.15' => array(
150 - array( 'do_unique_pl_tl_il' ),
151 - array( 'add_table', 'change_tag', 'patch-change_tag.sql' ),
152 - array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ),
153 - array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ),
154 - ),
155 - '1.16' => array(
156 - array( 'add_table', 'user_properties', 'patch-user_properties.sql' ),
157 - array( 'add_table', 'log_search', 'patch-log_search.sql' ),
158 - array( 'do_log_search_population' ),
159 - array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ),
160 - array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ),
161 - array( 'add_table', 'external_user', 'patch-external_user.sql' ),
162 - array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ),
163 - array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ),
164 - array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ),
165 - array( 'do_update_transcache_field' ),
166 - array( 'rename_eu_wiki_id' ),
167 - array( 'do_update_mime_minor_field' ),
168 - array( 'do_populate_rev_len' ),
169 - ),
170 - '1.17' => array(
171 - array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
172 - array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
173 - array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
174 - array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
175 - ),
176 - );
177 - }
178 -
179 -}
180 -
181 -/**
182 - * Sqlite implementation.
183 - */
184 -class SqliteUpdater implements Updaters {
185 -
186 - public function getUpdates() {
187 - return array(
188 - '1.14' => array(
189 - array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ),
190 - array( 'do_active_users_init' ),
191 - array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ),
192 - array( 'sqlite_initial_indexes' ),
193 - ),
194 - '1.15' => array(
195 - array( 'add_table', 'change_tag', 'patch-change_tag.sql' ),
196 - array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ),
197 - array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ),
198 - ),
199 - '1.16' => array(
200 - array( 'add_table', 'user_properties', 'patch-user_properties.sql' ),
201 - array( 'add_table', 'log_search', 'patch-log_search.sql' ),
202 - array( 'do_log_search_population' ),
203 - array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ),
204 - array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ),
205 - array( 'add_table', 'external_user', 'patch-external_user.sql' ),
206 - array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ),
207 - array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ),
208 - array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ),
209 - array( 'do_update_transcache_field' ),
210 - array( 'sqlite_setup_searchindex' ),
211 - ),
212 - '1.17' => array(
213 - array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
214 - array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
215 - array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
216 - array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
217 - ),
218 - );
219 - }
220 -
221 -}
222 -
223 -/**
224 - * Oracle implementation.
225 - */
226 -class OracleUpdater implements Updaters {
227 -
228 - public function getUpdates() {
229 - return array();
230 - }
231 -
232 -}
\ No newline at end of file
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -0,0 +1,166 @@
 2+<?php
 3+
 4+/*
 5+ * Class for handling database updates. Roughly based off of updaters.inc, with
 6+ * a few improvements :)
 7+ */
 8+abstract class DatabaseUpdater {
 9+
 10+ /**
 11+ * Array of updates to perform on the database
 12+ *
 13+ * @var array
 14+ */
 15+ protected $updates = array();
 16+
 17+ protected $db;
 18+
 19+ protected function __construct( $db ) {
 20+ $this->db = $db;
 21+ }
 22+
 23+ public static function newForDB( $db ) {
 24+ switch( $db->getType() ) {
 25+ case 'mysql':
 26+ return new MysqlUpdater( $db );
 27+ case 'sqlite':
 28+ return new SqliteUpdater( $db );
 29+ case 'oracle':
 30+ return new OracleUpdater( $db );
 31+ default:
 32+ throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
 33+ }
 34+ }
 35+
 36+ public function doUpdates() {
 37+ global $IP;
 38+ require_once( "$IP/maintenance/updaters.inc" );
 39+ $this->loadUpdates();
 40+ foreach ( $this->updates as $version => $updates ) {
 41+ foreach( $updates as $params ) {
 42+ $func = array_shift( $params );
 43+ call_user_func_array( $func, $params );
 44+ flush();
 45+ }
 46+ // some updates don't get recorded :(
 47+ if( $version !== 'always' ) {
 48+ $this->setAppliedUpdates( $version, $updates );
 49+ }
 50+ }
 51+ }
 52+
 53+ protected function loadUpdates() {
 54+ // If the updatelog table hasn't been upgraded, we can't use the new
 55+ // style of recording our steps. Run all to be safe
 56+ if( !$this->canUseNewUpdatelog() ) {
 57+ $this->updates = $this->getCoreUpdateList();
 58+ } else {
 59+ foreach( $this->getCoreUpdateList() as $version => $updates ) {
 60+ $appliedUpdates = $this->getAppliedUpdates( $version );
 61+ if( !$appliedUpdates || $appliedUpdates != $updates ) {
 62+ $this->updates[ $version ] = $updates;
 63+ }
 64+ }
 65+ }
 66+ $this->getOldGlobalUpdates();
 67+ }
 68+
 69+ protected function getAppliedUpdates( $version ) {
 70+ $key = "updatelist-$version";
 71+ $val = $this->db->selectField( 'updatelog', 'ul_value',
 72+ array( 'ul_key' => $key ), __METHOD__ );
 73+ if( !$val ) {
 74+ return null;
 75+ } else {
 76+ return unserialize( $val );
 77+ }
 78+ }
 79+
 80+ protected function setAppliedUpdates( $version, $updates = array() ) {
 81+ if( !$this->canUseNewUpdatelog() ) {
 82+ return;
 83+ }
 84+ $key = "updatelist-$version";
 85+ $this->db->delete( 'updatelog', array( 'ul_key' => $key ), __METHOD__ );
 86+ $this->db->insert( 'updatelog',
 87+ array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
 88+ __METHOD__ );
 89+ }
 90+
 91+ /**
 92+ * Updatelog was changed in 1.17 to have a ul_value column so we can record
 93+ * more information about what kind of updates we've done (that's what this
 94+ * class does). Pre-1.17 wikis won't have this column, and really old wikis
 95+ * might not even have updatelog at all
 96+ *
 97+ * @return boolean
 98+ */
 99+ protected function canUseNewUpdatelog() {
 100+ return $this->db->tableExists( 'updatelog' ) &&
 101+ $this->db->fieldExists( 'updatelog', 'ul_value' );
 102+ }
 103+
 104+ /**
 105+ * Before 1.17, we used to handle updates via stuff like $wgUpdates,
 106+ * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
 107+ * of this in 1.17 but we want to remain back-compatible for awhile. So
 108+ * load up these old global-based things into our update list. We can't
 109+ * version these like we do with our core updates, so they have to go
 110+ * in 'always'
 111+ */
 112+ private function getOldGlobalUpdates() {
 113+ global $wgUpdates, $wgExtNewFields, $wgExtNewTables,
 114+ $wgExtModifiedFields, $wgExtNewIndexes;
 115+
 116+ if( isset( $wgUpdates[ $this->db->getType() ] ) ) {
 117+ foreach( $wgUpdates[ $this->db->getType() ] as $upd ) {
 118+ $this->updates['always'][] = $upd;
 119+ }
 120+ }
 121+
 122+ foreach ( $wgExtNewTables as $tableRecord ) {
 123+ $this->updates['always'][] = array(
 124+ 'add_table', $tableRecord[0], $tableRecord[1], true
 125+ );
 126+ }
 127+
 128+ foreach ( $wgExtNewFields as $fieldRecord ) {
 129+ if ( $fieldRecord[0] != 'user' || $doUser ) {
 130+ $this->updates['always'][] = array(
 131+ 'add_field', $fieldRecord[0], $fieldRecord[1],
 132+ $fieldRecord[2], true
 133+ );
 134+ }
 135+ }
 136+
 137+ foreach ( $wgExtNewIndexes as $fieldRecord ) {
 138+ $this->updates['always'][] = array(
 139+ 'add_index', $fieldRecord[0], $fieldRecord[1],
 140+ $fieldRecord[2], true
 141+ );
 142+ }
 143+
 144+ foreach ( $wgExtModifiedFields as $fieldRecord ) {
 145+ $this->updates['always'][] = array(
 146+ 'modify_field', $fieldRecord[0], $fieldRecord[1],
 147+ $fieldRecord[2], true
 148+ );
 149+ }
 150+ }
 151+
 152+ /**
 153+ * Get an array of updates to perform on the database. Should return a
 154+ * mutli-dimensional array. The main key is the MediaWiki version (1.12,
 155+ * 1.13...) with the values being arrays of updates, identical to how
 156+ * updaters.inc did it (for now)
 157+ *
 158+ * @return Array
 159+ */
 160+ protected abstract function getCoreUpdateList();
 161+}
 162+
 163+class OracleUpdater extends DatabaseUpdater {
 164+ protected function getCoreUpdateList() {
 165+ return array();
 166+ }
 167+}
Property changes on: trunk/phase3/includes/installer/DatabaseUpdater.php
___________________________________________________________________
Added: svn:eol-style
1168 + native
Index: trunk/phase3/includes/installer/MysqlUpdater.php
@@ -0,0 +1,158 @@
 2+<?php
 3+
 4+/**
 5+ * Mysql update list and mysql-specific update functions
 6+ */
 7+class MysqlUpdater extends DatabaseUpdater {
 8+ protected function getCoreUpdateList() {
 9+ return array(
 10+ '1.2' => array(
 11+ array( 'add_field', 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ),
 12+ array( 'add_field', 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
 13+ array( 'do_interwiki_update' ),
 14+ array( 'do_index_update' ),
 15+ array( 'add_table', 'hitcounter', 'patch-hitcounter.sql' ),
 16+ array( 'add_field', 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
 17+ ),
 18+ '1.3' => array(
 19+ array( 'add_field', 'user', 'user_real_name', 'patch-user-realname.sql' ),
 20+ array( 'add_table', 'querycache', 'patch-querycache.sql' ),
 21+ array( 'add_table', 'objectcache', 'patch-objectcache.sql' ),
 22+ array( 'add_table', 'categorylinks', 'patch-categorylinks.sql' ),
 23+ array( 'do_old_links_update' ),
 24+ array( 'fix_ancient_imagelinks' ),
 25+ array( 'add_field', 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
 26+ ),
 27+ '1.4' => array(
 28+ array( 'do_image_name_unique_update' ),
 29+ array( 'add_field', 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
 30+ array( 'add_field', 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
 31+ array( 'add_table', 'logging', 'patch-logging.sql' ),
 32+ array( 'add_field', 'user', 'user_token', 'patch-user_token.sql' ),
 33+ array( 'do_watchlist_update' ),
 34+ array( 'do_user_update' ),
 35+ ),
 36+ '1.5' => array(
 37+ array( 'do_schema_restructuring' ),
 38+ array( 'add_field', 'logging', 'log_params', 'patch-log_params.sql' ),
 39+ array( 'check_bin', 'logging', 'log_title', 'patch-logging-title.sql', ),
 40+ array( 'add_field', 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ),
 41+ array( 'add_field', 'page', 'page_len', 'patch-page_len.sql' ),
 42+ array( 'do_inverse_timestamp' ),
 43+ array( 'do_text_id' ),
 44+ array( 'add_field', 'revision', 'rev_deleted', 'patch-rev_deleted.sql' ),
 45+ array( 'add_field', 'image', 'img_width', 'patch-img_width.sql' ),
 46+ array( 'add_field', 'image', 'img_metadata', 'patch-img_metadata.sql' ),
 47+ array( 'add_field', 'user', 'user_email_token', 'patch-user_email_token.sql' ),
 48+ array( 'add_field', 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ),
 49+ array( 'do_namespace_size' ),
 50+ array( 'add_field', 'image', 'img_media_type', 'patch-img_media_type.sql' ),
 51+ array( 'do_pagelinks_update' ),
 52+ array( 'do_drop_img_type' ),
 53+ array( 'do_user_unique_update' ),
 54+ array( 'do_user_groups_update' ),
 55+ array( 'add_field', 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ),
 56+ array( 'add_table', 'user_newtalk', 'patch-usernewtalk2.sql' ),
 57+ array( 'add_table', 'transcache', 'patch-transcache.sql' ),
 58+ array( 'add_field', 'interwiki', 'iw_trans', 'patch-interwiki-trans.sql' ),
 59+ array( 'add_table', 'trackbacks', 'patch-trackbacks.sql' ),
 60+ ),
 61+ '1.6' => array(
 62+ array( 'do_watchlist_null' ),
 63+ array( 'do_logging_timestamp_index' ),
 64+ array( 'add_field', 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ),
 65+ array( 'do_page_random_update' ),
 66+ array( 'add_field', 'user', 'user_registration', 'patch-user_registration.sql' ),
 67+ array( 'do_templatelinks_update' ),
 68+ array( 'add_table', 'externallinks', 'patch-externallinks.sql' ),
 69+ array( 'add_table', 'job', 'patch-job.sql' ),
 70+ array( 'add_field', 'site_stats', 'ss_images', 'patch-ss_images.sql' ),
 71+ array( 'add_table', 'langlinks', 'patch-langlinks.sql' ),
 72+ array( 'add_table', 'querycache_info', 'patch-querycacheinfo.sql' ),
 73+ array( 'add_table', 'filearchive', 'patch-filearchive.sql' ),
 74+ array( 'add_field', 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ),
 75+ array( 'do_rc_indices_update' ),
 76+ ),
 77+ '1.9' => array(
 78+ array( 'add_field', 'user', 'user_newpass_time', 'patch-user_newpass_time.sql' ),
 79+ array( 'add_table', 'redirect', 'patch-redirect.sql' ),
 80+ array( 'add_table', 'querycachetwo', 'patch-querycachetwo.sql' ),
 81+ array( 'add_field', 'ipblocks', 'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ),
 82+ array( 'do_backlinking_indices_update' ),
 83+ array( 'add_field', 'recentchanges', 'rc_old_len', 'patch-rc_len.sql' ),
 84+ array( 'add_field', 'user', 'user_editcount', 'patch-user_editcount.sql' ),
 85+ ),
 86+ '1.10' => array(
 87+ array( 'do_restrictions_update' ),
 88+ array( 'add_field', 'logging', 'log_id', 'patch-log_id.sql' ),
 89+ array( 'add_field', 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ),
 90+ array( 'add_field', 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ),
 91+ array( 'add_field', 'revision', 'rev_len', 'patch-rev_len.sql' ),
 92+ array( 'add_field', 'recentchanges', 'rc_deleted', 'patch-rc_deleted.sql' ),
 93+ array( 'add_field', 'logging', 'log_deleted', 'patch-log_deleted.sql' ),
 94+ array( 'add_field', 'archive', 'ar_deleted', 'patch-ar_deleted.sql' ),
 95+ array( 'add_field', 'ipblocks', 'ipb_deleted', 'patch-ipb_deleted.sql' ),
 96+ array( 'add_field', 'filearchive', 'fa_deleted', 'patch-fa_deleted.sql' ),
 97+ array( 'add_field', 'archive', 'ar_len', 'patch-ar_len.sql' ),
 98+ ),
 99+ '1.11' => array(
 100+ array( 'add_field', 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ),
 101+ array( 'do_categorylinks_indices_update' ),
 102+ array( 'add_field', 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql' ),
 103+ array( 'do_archive_user_index' ),
 104+ array( 'do_image_user_index' ),
 105+ array( 'do_oldimage_user_index' ),
 106+ array( 'add_field', 'archive', 'ar_page_id', 'patch-archive-page_id.sql' ),
 107+ array( 'add_field', 'image', 'img_sha1', 'patch-img_sha1.sql' ),
 108+ ),
 109+ '1.12' => array(
 110+ array( 'add_table', 'protected_titles', 'patch-protected_titles.sql' ),
 111+ ),
 112+ '1.13' => array(
 113+ array( 'add_field', 'ipblocks', 'ipb_by_text', 'patch-ipb_by_text.sql' ),
 114+ array( 'add_table', 'page_props', 'patch-page_props.sql' ),
 115+ array( 'add_table', 'updatelog', 'patch-updatelog.sql' ),
 116+ array( 'add_table', 'category', 'patch-category.sql' ),
 117+ array( 'do_category_population' ),
 118+ array( 'add_field', 'archive', 'ar_parent_id', 'patch-ar_parent_id.sql' ),
 119+ array( 'add_field', 'user_newtalk', 'user_last_timestamp', 'patch-user_last_timestamp.sql' ),
 120+ array( 'do_populate_parent_id' ),
 121+ array( 'check_bin', 'protected_titles', 'pt_title', 'patch-pt_title-encoding.sql', ),
 122+ array( 'maybe_do_profiling_memory_update' ),
 123+ array( 'do_filearchive_indices_update' ),
 124+ ),
 125+ '1.14' => array(
 126+ array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ),
 127+ array( 'do_active_users_init' ),
 128+ array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ),
 129+ ),
 130+ '1.15' => array(
 131+ array( 'do_unique_pl_tl_il' ),
 132+ array( 'add_table', 'change_tag', 'patch-change_tag.sql' ),
 133+ array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ),
 134+ array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ),
 135+ ),
 136+ '1.16' => array(
 137+ array( 'add_table', 'user_properties', 'patch-user_properties.sql' ),
 138+ array( 'add_table', 'log_search', 'patch-log_search.sql' ),
 139+ array( 'do_log_search_population' ),
 140+ array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ),
 141+ array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ),
 142+ array( 'add_table', 'external_user', 'patch-external_user.sql' ),
 143+ array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ),
 144+ array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ),
 145+ array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ),
 146+ array( 'do_update_transcache_field' ),
 147+ array( 'rename_eu_wiki_id' ),
 148+ array( 'do_update_mime_minor_field' ),
 149+ array( 'do_populate_rev_len' ),
 150+ ),
 151+ '1.17' => array(
 152+ array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
 153+ array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
 154+ array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
 155+ array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
 156+ ),
 157+ );
 158+ }
 159+}
Property changes on: trunk/phase3/includes/installer/MysqlUpdater.php
___________________________________________________________________
Added: svn:eol-style
1160 + native
Index: trunk/phase3/includes/installer/SqliteUpdater.php
@@ -0,0 +1,40 @@
 2+<?php
 3+/**
 4+ * Sqlite
 5+ */
 6+class SqliteUpdater extends DatabaseUpdater {
 7+ protected function getCoreUpdateList() {
 8+ return array(
 9+ '1.14' => array(
 10+ array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ),
 11+ array( 'do_active_users_init' ),
 12+ array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ),
 13+ array( 'sqlite_initial_indexes' ),
 14+ ),
 15+ '1.15' => array(
 16+ array( 'add_table', 'change_tag', 'patch-change_tag.sql' ),
 17+ array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ),
 18+ array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ),
 19+ ),
 20+ '1.16' => array(
 21+ array( 'add_table', 'user_properties', 'patch-user_properties.sql' ),
 22+ array( 'add_table', 'log_search', 'patch-log_search.sql' ),
 23+ array( 'do_log_search_population' ),
 24+ array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ),
 25+ array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ),
 26+ array( 'add_table', 'external_user', 'patch-external_user.sql' ),
 27+ array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ),
 28+ array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ),
 29+ array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ),
 30+ array( 'do_update_transcache_field' ),
 31+ array( 'sqlite_setup_searchindex' ),
 32+ ),
 33+ '1.17' => array(
 34+ array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
 35+ array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ),
 36+ array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
 37+ array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
 38+ ),
 39+ );
 40+ }
 41+}
Property changes on: trunk/phase3/includes/installer/SqliteUpdater.php
___________________________________________________________________
Added: svn:eol-style
142 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -416,20 +416,20 @@
417417 'CliInstaller' => 'includes/installer/CliInstaller.php',
418418 'Installer' => 'includes/installer/Installer.php',
419419 'DatabaseInstaller' => 'includes/installer/DatabaseInstaller.php',
 420+ 'DatabaseUpdater' => 'includes/installer/DatabaseUpdater.php',
420421 'LBFactory_InstallerFake' => 'includes/installer/Installer.php',
421422 'LocalSettingsGenerator' => 'includes/installer/LocalSettingsGenerator.php',
422423 'WebInstaller' => 'includes/installer/WebInstaller.php',
423424 'WebInstallerPage' => 'includes/installer/WebInstallerPage.php',
424425 'WebInstallerOutput' => 'includes/installer/WebInstallerOutput.php',
425426 'MysqlInstaller' => 'includes/installer/MysqlInstaller.php',
426 - 'MysqlUpdater' => 'includes/installer/Updaters.php',
 427+ 'MysqlUpdater' => 'includes/installer/MysqlUpdater.php',
427428 'PostgresInstaller' => 'includes/installer/PostgresInstaller.php',
428429 'SqliteInstaller' => 'includes/installer/SqliteInstaller.php',
429 - 'SqliteUpdater' => 'includes/installer/Updaters.php',
 430+ 'SqliteUpdater' => 'includes/installer/SqliteUpdate.php',
430431 'OracleInstaller' => 'includes/installer/OracleInstaller.php',
431 - 'OracleUpdater' => 'includes/installer/Updaters.php',
 432+ 'OracleUpdater' => 'includes/installer/DatabaseUpdater.php',
432433 'Update' => 'includes/installer/Update.php',
433 - 'Updaters' => 'includes/installer/Updaters.php',
434434
435435 # includes/job
436436 'DoubleRedirectJob' => 'includes/job/DoubleRedirectJob.php',

Comments

#Comment by Nikerabbit (talk | contribs)   08:27, 21 July 2010
Entry point is now factory DatabaseUpdaters::newForDB()

Why not ::factory akin to Language::factory?

#Comment by 😂 (talk | contribs)   12:01, 21 July 2010

I don't like the name factory() :p

#Comment by 😂 (talk | contribs)   12:18, 21 July 2010

Just realized I typo'd all over this commit. They're all called *Updater now. Not *Updaters. I went crazy from changing all those names half a dozen times.

#Comment by 😂 (talk | contribs)   12:19, 21 July 2010

All over the commit summary that is. The commit is correct. I think.

Status & tagging log