From: Tim Starling Date: Sun, 26 Sep 2004 09:22:49 +0000 (+0000) Subject: Refactored updaters.inc. With all those functions doing virtually the same thing... X-Git-Tag: 1.5.0alpha1~1777 X-Git-Url: http://git.cyclocoop.org///%22%40url%40//%22?a=commitdiff_plain;h=8f61d0007ecb7c043763224d8259e1579a058e64;p=lhc%2Fweb%2Fwiklou.git Refactored updaters.inc. With all those functions doing virtually the same thing, it was getting kind of silly --- diff --git a/config/index.php b/config/index.php index 7565439c3b..9ce8c170d9 100644 --- a/config/index.php +++ b/config/index.php @@ -465,21 +465,25 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { chdir( ".." ); flush(); - do_ipblocks_update(); flush(); + + # Add missing tables + foreach ( $wgNewTables as $tableRecord ) { + add_table( $tableRecord[0], $tableRecord[1] ); + flush(); + } + + # Add missing fields + foreach ( $wgNewFields as $fieldRecord ) { + add_table( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] ); + flush(); + } + + # Do schema updates which require special handling do_interwiki_update(); flush(); do_index_update(); flush(); - do_linkscc_update(); flush(); do_linkscc_1_3_update(); flush(); - do_hitcounter_update(); flush(); - do_recentchanges_update(); flush(); convertLinks(); flush(); - do_user_real_name_update(); flush(); - do_querycache_update(); flush(); - do_objectcache_update(); flush(); - do_categorylinks_update(); flush(); do_image_name_unique_update(); flush(); - do_logging_update(); flush(); - do_user_rights_update(); flush(); if ( isTemplateInitialised() ) { print "Template namespace already initialised\n"; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index ee64362eb0..78bfbfaf9b 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -5,6 +5,52 @@ */ /** */ + +$wgNewTables = array( +# table patch file (in maintenance/archives) + array( 'linkscc', 'patch-linkscc.sql' ), + array( 'hitcounter', 'patch-hitcounter.sql' ), + array( 'querycache', 'patch-querycache.sql' ), + array( 'objectcache', 'patch-objectcache.sql' ), + array( 'categorylinks', 'patch-categorylinks.sql' ), + array( 'logging', 'patch-logging.sql' ), + array( 'user_rights', 'patch-user_rights.sql' ), +); + +$wgNewFields = array( +# table field patch file (in maintenance/archives) + array( 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ), + array( 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ), + array( 'recentchanges', 'rc_type', 'patch-rc_type.sql' ), + array( 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ), + array( 'recentchanges', 'rc_id', 'patch-rc_id.sql' ), + array( 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ), + array( 'user', 'user_real_name', 'patch-user-realname.sql' ), + array( 'user', 'user_token', 'patch-user_token.sql' ), +); + +function add_table( $name, $patch ) { + global $wgDatabase; + if ( $wgDatabase->tableExists( $name ) ) { + echo "...$name table already exists.\n"; + } else { + echo "Creating $name table..."; + dbsource( "maintenance/archives/$patch", $wgDatabase ); + echo "ok\n"; + } +} + +function add_field( $table, $field, $patch ) { + global $wgDatabase; + if ( $wgDatabase->fieldExists( $table, $field ) ) { + echo "...have $field field in $table table.\n"; + } else { + echo "Adding $field field to table $table..."; + dbsource( "maintenance/archives/$patch" , $wgDatabase ); + echo "ok\n"; + } +} + function do_revision_updates() { global $wgSoftwareRevision; if ( $wgSoftwareRevision < 1001 ) { @@ -38,34 +84,6 @@ function update_passwords() { } } -function do_ipblocks_update() { - global $wgDatabase; - - $do1 = $do2 = false; - - if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) { - $do1 = true; - } - if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_expiry" ) ) { - $do2 = true; - } - - if ( $do1 || $do2 ) { - echo "Updating ipblocks table... "; - if ( $do1 ) { - dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase ); - } - if ( $do2 ) { - dbsource( "maintenance/archives/patch-ipb_expiry.sql", $wgDatabase ); - } - echo "ok\n"; - } else { - echo "...ipblocks is up to date.\n"; - } - -} - - function do_interwiki_update() { # Check that interwiki table exists; if it doesn't source it global $wgDatabase; @@ -95,18 +113,6 @@ function do_index_update() { return false; } -function do_linkscc_update() { - // Create linkscc if necessary - global $wgDatabase; - if( $wgDatabase->tableExists( "linkscc" ) ) { - echo "...have linkscc table.\n"; - } else { - echo "Adding linkscc table... "; - dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase ); - echo "ok\n"; - } -} - function do_linkscc_1_3_update() { // Update linkscc table to 1.3 schema if necessary global $wgDatabase, $wgVersion; @@ -120,86 +126,6 @@ function do_linkscc_1_3_update() { } } -function do_hitcounter_update() { - // Create hitcounter if necessary - global $wgDatabase; - if( $wgDatabase->tableExists( "hitcounter" ) ) { - echo "...have hitcounter table.\n"; - } else { - echo "Adding hitcounter table... "; - dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase ); - echo "ok\n"; - } -} - -function do_recentchanges_update() { - global $wgDatabase; - if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) { - echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title..."; - dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase ); - echo "ok\n"; - } - if ( !$wgDatabase->fieldExists( "recentchanges", "rc_ip" ) ) { - echo "Adding rc_ip..."; - dbsource( "maintenance/archives/patch-rc_ip.sql", $wgDatabase ); - echo "ok\n"; - } - if ( !$wgDatabase->fieldExists( "recentchanges", "rc_id" ) ) { - echo "Adding rc_id..."; - dbsource( "maintenance/archives/patch-rc_id.sql", $wgDatabase ); - echo "ok\n"; - } - if ( !$wgDatabase->fieldExists( "recentchanges", "rc_patrolled" ) ) { - echo "Adding rc_patrolled..."; - dbsource( "maintenance/archives/patch-rc-patrol.sql", $wgDatabase ); - echo "ok\n"; - } -} - -function do_user_real_name_update() { - global $wgDatabase; - if ( $wgDatabase->fieldExists( "user", "user_real_name" ) ) { - echo "...have user_real_name field in user table.\n"; - } else { - echo "Adding user_real_name field to table user..."; - dbsource( "maintenance/archives/patch-user-realname.sql" , $wgDatabase ); - echo "ok\n"; - } -} - -function do_querycache_update() { - global $wgDatabase; - if( $wgDatabase->tableExists( "querycache" ) ) { - echo "...have special page querycache table.\n"; - } else { - echo "Adding querycache table for slow special pages... "; - dbsource( "maintenance/archives/patch-querycache.sql", $wgDatabase ); - echo "ok\n"; - } -} - -function do_objectcache_update() { - global $wgDatabase; - if( $wgDatabase->tableExists( "objectcache" ) ) { - echo "...have objectcache table.\n"; - } else { - echo "Adding objectcache table for message caching... "; - dbsource( "maintenance/archives/patch-objectcache.sql", $wgDatabase ); - echo "ok\n"; - } -} - -function do_categorylinks_update() { - global $wgDatabase; - if( $wgDatabase->tableExists( "categorylinks" ) ) { - echo "...have categorylinks table.\n"; - } else { - echo "Adding categorylinks table for category management... "; - dbsource( "maintenance/archives/patch-categorylinks.sql", $wgDatabase ); - echo "ok\n"; - } -} - function do_image_name_unique_update() { global $wgDatabase; if ( $wgDatabase->indexUnique( 'image', 'img_name' ) ) { @@ -211,26 +137,4 @@ function do_image_name_unique_update() { } } -function do_logging_update() { - global $wgDatabase; - if ( $wgDatabase->tableExists( 'logging' ) ) { - echo "...logging table already exists.\n"; - } else { - echo "Creating logging table and adjusting recentchanges... "; - dbsource( "maintenance/archives/patch-logging.sql", $wgDatabase ); - echo "ok\n"; - } -} - -function do_user_rights_update() { - global $wgDatabase; - if ( $wgDatabase->tableExists( 'user_rights' ) ) { - echo "...user_rights table already exists.\n"; - } else { - echo 'Creating user rights table...'; - dbsource( 'maintenance/archives/patch-user_rights.sql', $wgDatabase ); - echo "ok\n"; - } -} - ?>