r71202 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71201‎ | r71202 | r71203 >
Date:13:36, 17 August 2010
Author:demon
Status:ok
Tags:
Comment:
Moved first of the updaters functions to the appropriate classes (addTable is shared, doNamespaceSize was mySQL-only) to give an idea of what the grand scheme is. Still using nasty wfOut()s, need to use Status objects or *something* else here other than just throwing up output
Modified paths:
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/SqliteUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -43,21 +43,6 @@
4444 return (bool)$row;
4545 }
4646
47 -function add_table( $name, $patch, $fullpath = false ) {
48 - global $wgDatabase;
49 - if ( $wgDatabase->tableExists( $name ) ) {
50 - wfOut( "...$name table already exists.\n" );
51 - } else {
52 - wfOut( "Creating $name table..." );
53 - if ( $fullpath ) {
54 - $wgDatabase->sourceFile( $patch );
55 - } else {
56 - $wgDatabase->sourceFile( archive( $patch ) );
57 - }
58 - wfOut( "ok\n" );
59 - }
60 -}
61 -
6247 function modify_field( $table, $field, $patch, $fullpath = false ) {
6348 global $wgDatabase;
6449 if ( !$wgDatabase->tableExists( $table ) ) {
@@ -508,43 +493,6 @@
509494 }
510495 }
511496
512 -function do_namespace_size() {
513 - $tables = array(
514 - 'page' => 'page',
515 - 'archive' => 'ar',
516 - 'recentchanges' => 'rc',
517 - 'watchlist' => 'wl',
518 - 'querycache' => 'qc',
519 - 'logging' => 'log',
520 - );
521 - foreach ( $tables as $table => $prefix ) {
522 - do_namespace_size_on( $table, $prefix );
523 - flush();
524 - }
525 -}
526 -
527 -function do_namespace_size_on( $table, $prefix ) {
528 - global $wgDatabase, $wgDBtype;
529 - if ( $wgDBtype != 'mysql' )
530 - return;
531 - $field = $prefix . '_namespace';
532 -
533 - $tablename = $wgDatabase->tableName( $table );
534 - $result = $wgDatabase->query( "SHOW COLUMNS FROM $tablename LIKE '$field'" );
535 - $info = $wgDatabase->fetchObject( $result );
536 -
537 - if ( substr( $info->Type, 0, 3 ) == 'int' ) {
538 - wfOut( "...$field is already a full int ($info->Type).\n" );
539 - } else {
540 - wfOut( "Promoting $field from $info->Type to int... " );
541 -
542 - $sql = "ALTER TABLE $tablename MODIFY $field int NOT NULL";
543 - $wgDatabase->query( $sql );
544 -
545 - wfOut( "ok\n" );
546 - }
547 -}
548 -
549497 function do_pagelinks_update() {
550498 global $wgDatabase;
551499 if ( $wgDatabase->tableExists( 'pagelinks' ) ) {
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -52,6 +52,9 @@
5353 $this->getOldGlobalUpdates() );
5454 foreach ( $this->updates as $params ) {
5555 $func = array_shift( $params );
 56+ if( method_exists( $this, $func ) ) {
 57+ $func = array( $this, $func );
 58+ }
5659 call_user_func_array( $func, $params );
5760 flush();
5861 }
@@ -107,7 +110,7 @@
108111
109112 foreach ( $wgExtNewTables as $tableRecord ) {
110113 $updates[] = array(
111 - 'add_table', $tableRecord[0], $tableRecord[1], true
 114+ 'addTable', $tableRecord[0], $tableRecord[1], true
112115 );
113116 }
114117
@@ -146,6 +149,26 @@
147150 * @return Array
148151 */
149152 protected abstract function getCoreUpdateList();
 153+
 154+ /**
 155+ * Add a new table to the database
 156+ * @param $name String Name of the new table
 157+ * @param $patch String Path to the patch file
 158+ * @param $fullpath Boolean Whether to treat $fullPath as a relative or not
 159+ */
 160+ protected function addTable( $name, $patch, $fullpath = false ) {
 161+ if ( $this->db->tableExists( $name ) ) {
 162+ wfOut( "...$name table already exists.\n" );
 163+ } else {
 164+ wfOut( "Creating $name table..." );
 165+ if ( $fullpath ) {
 166+ $this->db->sourceFile( $patch );
 167+ } else {
 168+ $this->db->sourceFile( archive( $patch ) );
 169+ }
 170+ wfOut( "ok\n" );
 171+ }
 172+ }
150173 }
151174
152175 class OracleUpdater extends DatabaseUpdater {
Index: trunk/phase3/includes/installer/MysqlUpdater.php
@@ -15,14 +15,14 @@
1616 array( 'add_field', 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
1717 array( 'do_interwiki_update' ),
1818 array( 'do_index_update' ),
19 - array( 'add_table', 'hitcounter', 'patch-hitcounter.sql' ),
 19+ array( 'addTable', 'hitcounter', 'patch-hitcounter.sql' ),
2020 array( 'add_field', 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
2121
2222 // 1.3
2323 array( 'add_field', 'user', 'user_real_name', 'patch-user-realname.sql' ),
24 - array( 'add_table', 'querycache', 'patch-querycache.sql' ),
25 - array( 'add_table', 'objectcache', 'patch-objectcache.sql' ),
26 - array( 'add_table', 'categorylinks', 'patch-categorylinks.sql' ),
 24+ array( 'addTable', 'querycache', 'patch-querycache.sql' ),
 25+ array( 'addTable', 'objectcache', 'patch-objectcache.sql' ),
 26+ array( 'addTable', 'categorylinks', 'patch-categorylinks.sql' ),
2727 array( 'do_old_links_update' ),
2828 array( 'fix_ancient_imagelinks' ),
2929 array( 'add_field', 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
@@ -31,7 +31,7 @@
3232 array( 'do_image_name_unique_update' ),
3333 array( 'add_field', 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
3434 array( 'add_field', 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
35 - array( 'add_table', 'logging', 'patch-logging.sql' ),
 35+ array( 'addTable', 'logging', 'patch-logging.sql' ),
3636 array( 'add_field', 'user', 'user_token', 'patch-user_token.sql' ),
3737 array( 'do_watchlist_update' ),
3838 array( 'do_user_update' ),
@@ -49,17 +49,17 @@
5050 array( 'add_field', 'image', 'img_metadata', 'patch-img_metadata.sql' ),
5151 array( 'add_field', 'user', 'user_email_token', 'patch-user_email_token.sql' ),
5252 array( 'add_field', 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ),
53 - array( 'do_namespace_size' ),
 53+ array( 'doNamespaceSize' ),
5454 array( 'add_field', 'image', 'img_media_type', 'patch-img_media_type.sql' ),
5555 array( 'do_pagelinks_update' ),
5656 array( 'do_drop_img_type' ),
5757 array( 'do_user_unique_update' ),
5858 array( 'do_user_groups_update' ),
5959 array( 'add_field', 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ),
60 - array( 'add_table', 'user_newtalk', 'patch-usernewtalk2.sql' ),
61 - array( 'add_table', 'transcache', 'patch-transcache.sql' ),
 60+ array( 'addTable', 'user_newtalk', 'patch-usernewtalk2.sql' ),
 61+ array( 'addTable', 'transcache', 'patch-transcache.sql' ),
6262 array( 'add_field', 'interwiki', 'iw_trans', 'patch-interwiki-trans.sql' ),
63 - array( 'add_table', 'trackbacks', 'patch-trackbacks.sql' ),
 63+ array( 'addTable', 'trackbacks', 'patch-trackbacks.sql' ),
6464
6565 // 1.6
6666 array( 'do_watchlist_null' ),
@@ -68,19 +68,19 @@
6969 array( 'do_page_random_update' ),
7070 array( 'add_field', 'user', 'user_registration', 'patch-user_registration.sql' ),
7171 array( 'do_templatelinks_update' ),
72 - array( 'add_table', 'externallinks', 'patch-externallinks.sql' ),
73 - array( 'add_table', 'job', 'patch-job.sql' ),
 72+ array( 'addTable', 'externallinks', 'patch-externallinks.sql' ),
 73+ array( 'addTable', 'job', 'patch-job.sql' ),
7474 array( 'add_field', 'site_stats', 'ss_images', 'patch-ss_images.sql' ),
75 - array( 'add_table', 'langlinks', 'patch-langlinks.sql' ),
76 - array( 'add_table', 'querycache_info', 'patch-querycacheinfo.sql' ),
77 - array( 'add_table', 'filearchive', 'patch-filearchive.sql' ),
 75+ array( 'addTable', 'langlinks', 'patch-langlinks.sql' ),
 76+ array( 'addTable', 'querycache_info', 'patch-querycacheinfo.sql' ),
 77+ array( 'addTable', 'filearchive', 'patch-filearchive.sql' ),
7878 array( 'add_field', 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ),
7979 array( 'do_rc_indices_update' ),
8080
8181 // 1.9
8282 array( 'add_field', 'user', 'user_newpass_time', 'patch-user_newpass_time.sql' ),
83 - array( 'add_table', 'redirect', 'patch-redirect.sql' ),
84 - array( 'add_table', 'querycachetwo', 'patch-querycachetwo.sql' ),
 83+ array( 'addTable', 'redirect', 'patch-redirect.sql' ),
 84+ array( 'addTable', 'querycachetwo', 'patch-querycachetwo.sql' ),
8585 array( 'add_field', 'ipblocks', 'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ),
8686 array( 'do_backlinking_indices_update' ),
8787 array( 'add_field', 'recentchanges', 'rc_old_len', 'patch-rc_len.sql' ),
@@ -110,13 +110,13 @@
111111 array( 'add_field', 'image', 'img_sha1', 'patch-img_sha1.sql' ),
112112
113113 // 1.12
114 - array( 'add_table', 'protected_titles', 'patch-protected_titles.sql' ),
 114+ array( 'addTable', 'protected_titles', 'patch-protected_titles.sql' ),
115115
116116 // 1.13
117117 array( 'add_field', 'ipblocks', 'ipb_by_text', 'patch-ipb_by_text.sql' ),
118 - array( 'add_table', 'page_props', 'patch-page_props.sql' ),
119 - array( 'add_table', 'updatelog', 'patch-updatelog.sql' ),
120 - array( 'add_table', 'category', 'patch-category.sql' ),
 118+ array( 'addTable', 'page_props', 'patch-page_props.sql' ),
 119+ array( 'addTable', 'updatelog', 'patch-updatelog.sql' ),
 120+ array( 'addTable', 'category', 'patch-category.sql' ),
121121 array( 'do_category_population' ),
122122 array( 'add_field', 'archive', 'ar_parent_id', 'patch-ar_parent_id.sql' ),
123123 array( 'add_field', 'user_newtalk', 'user_last_timestamp', 'patch-user_last_timestamp.sql' ),
@@ -132,17 +132,17 @@
133133
134134 // 1.15
135135 array( 'do_unique_pl_tl_il' ),
136 - array( 'add_table', 'change_tag', 'patch-change_tag.sql' ),
137 - array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ),
138 - array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ),
 136+ array( 'addTable', 'change_tag', 'patch-change_tag.sql' ),
 137+ array( 'addTable', 'tag_summary', 'patch-change_tag.sql' ),
 138+ array( 'addTable', 'valid_tag', 'patch-change_tag.sql' ),
139139
140140 // 1.16
141 - array( 'add_table', 'user_properties', 'patch-user_properties.sql' ),
142 - array( 'add_table', 'log_search', 'patch-log_search.sql' ),
 141+ array( 'addTable', 'user_properties', 'patch-user_properties.sql' ),
 142+ array( 'addTable', 'log_search', 'patch-log_search.sql' ),
143143 array( 'do_log_search_population' ),
144144 array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ),
145 - array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ),
146 - array( 'add_table', 'external_user', 'patch-external_user.sql' ),
 145+ array( 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ),
 146+ array( 'addTable', 'external_user', 'patch-external_user.sql' ),
147147 array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ),
148148 array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ),
149149 array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ),
@@ -152,7 +152,7 @@
153153 array( 'do_populate_rev_len' ),
154154
155155 // 1.17
156 - array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
 156+ array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ),
157157 array( 'add_index', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ),
158158 array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
159159 array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),
@@ -162,4 +162,33 @@
163163 array( 'do_collation_update' ),
164164 );
165165 }
 166+
 167+ protected function doNamespaceSize() {
 168+ $tables = array(
 169+ 'page' => 'page',
 170+ 'archive' => 'ar',
 171+ 'recentchanges' => 'rc',
 172+ 'watchlist' => 'wl',
 173+ 'querycache' => 'qc',
 174+ 'logging' => 'log',
 175+ );
 176+ foreach ( $tables as $table => $prefix ) {
 177+ $field = $prefix . '_namespace';
 178+
 179+ $tablename = $this->db->tableName( $table );
 180+ $result = $this->db->query( "SHOW COLUMNS FROM $tablename LIKE '$field'" );
 181+ $info = $this->db->fetchObject( $result );
 182+
 183+ if ( substr( $info->Type, 0, 3 ) == 'int' ) {
 184+ wfOut( "...$field is already a full int ($info->Type).\n" );
 185+ } else {
 186+ wfOut( "Promoting $field from $info->Type to int... " );
 187+
 188+ $sql = "ALTER TABLE $tablename MODIFY $field int NOT NULL";
 189+ $this->db->query( $sql );
 190+
 191+ wfOut( "ok\n" );
 192+ }
 193+ }
 194+ }
166195 }
Index: trunk/phase3/includes/installer/SqliteUpdater.php
@@ -17,17 +17,17 @@
1818 array( 'sqlite_initial_indexes' ),
1919
2020 // 1.15
21 - array( 'add_table', 'change_tag', 'patch-change_tag.sql' ),
22 - array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ),
23 - array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ),
 21+ array( 'addTable', 'change_tag', 'patch-change_tag.sql' ),
 22+ array( 'addTable', 'tag_summary', 'patch-change_tag.sql' ),
 23+ array( 'addTable', 'valid_tag', 'patch-change_tag.sql' ),
2424
2525 // 1.16
26 - array( 'add_table', 'user_properties', 'patch-user_properties.sql' ),
27 - array( 'add_table', 'log_search', 'patch-log_search.sql' ),
 26+ array( 'addTable', 'user_properties', 'patch-user_properties.sql' ),
 27+ array( 'addTable', 'log_search', 'patch-log_search.sql' ),
2828 array( 'do_log_search_population' ),
2929 array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ),
30 - array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ),
31 - array( 'add_table', 'external_user', 'patch-external_user.sql' ),
 30+ array( 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ),
 31+ array( 'addTable', 'external_user', 'patch-external_user.sql' ),
3232 array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ),
3333 array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ),
3434 array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ),
@@ -35,7 +35,7 @@
3636 array( 'sqlite_setup_searchindex' ),
3737
3838 // 1.17
39 - array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ),
 39+ array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ),
4040 array( 'add_index', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ),
4141 array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ),
4242 array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ),

Status & tagging log