From 74f81512ab2fb09d22f14290c7b73d17e05f20d8 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 6 Mar 2004 09:04:25 +0000 Subject: [PATCH] Moved database update functions into maintenance/updater.inc, to be used by both update.php and config/index.php. Check path separator to get the include path right in Windows for the in-place LocalSettings.php. --- config/index.php | 20 ++++++- maintenance/updaters.inc | 126 +++++++++++++++++++++++++++++++++++++++ update.php | 124 +------------------------------------- 3 files changed, 145 insertions(+), 125 deletions(-) create mode 100644 maintenance/updaters.inc diff --git a/config/index.php b/config/index.php index 4a5acaa7b7..e8a0568ae2 100644 --- a/config/index.php +++ b/config/index.php @@ -143,6 +143,7 @@ if( !is_writable( "." ) ) { include( "../install-utils.inc" ); +include( "../maintenance/updaters.inc" ); class ConfigData { function getEncoded( $data ) { # Hackish @@ -319,7 +320,21 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { $wgDatabase->selectDB( $wgDBname ); if( $wgDatabase->tableExists( "cur" ) ) { - print "
  • There are already MediaWiki tables in this database. Skipping rest of database setup...
  • \n"; + print "
  • There are already MediaWiki tables in this database. Checking if updates are needed...
  • \n
    ";
    +			
    +			chdir( ".." );
    +			flush();
    +			do_ipblocks_update(); flush();
    +			do_interwiki_update(); flush();
    +			do_index_update(); flush();
    +			do_linkscc_update(); flush();
    +			do_hitcounter_update(); flush();
    +			do_recentchanges_update(); flush();
    +			initialiseMessages(); flush();
    +			chdir( "config" );
    +			
    +			print "
    \n"; + print "
  • Finished update checks.
  • \n"; } else { # FIXME: Check for errors print "
  • Creating tables..."; @@ -557,13 +572,14 @@ function writeLocalSettings( $conf ) { $conf->LanguageCode = "en"; $conf->Encoding = "UTF-8"; } + $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":"; return " # This file was automatically generated. Don't touch unless you # know what you're doing; see LocalSettings.sample for an edit- # friendly file. \$IP = \"{$conf->IP}\"; -ini_set( \"include_path\", \"\$IP/includes:\$IP/languages:\" . ini_get(\"include_path\") ); +ini_set( \"include_path\", \"\$IP/includes$sep\$IP/languages$sep\" . ini_get(\"include_path\") ); include_once( \"DefaultSettings.php\" ); if( \$wgCommandLineMode ) { diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc new file mode 100644 index 0000000000..e390903fb0 --- /dev/null +++ b/maintenance/updaters.inc @@ -0,0 +1,126 @@ +query( $sql, $fname ); + + while ( $row = $wgDatabase->fetchObject( $source ) ) { + $id = $row->user_id; + $oldpass = $row->user_password; + $newpass = md5( "{$id}-{$oldpass}" ); + + $sql = "UPDATE user SET user_password='{$newpass}' " . + "WHERE user_id={$id}"; + $wgDatabase->query( $sql, $fname ); + } +} + +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; + if( $wgDatabase->tableExists( "interwiki" ) ) { + echo "...already have interwiki table\n"; + return true; + } + echo "Creating interwiki table: "; + dbsource( "maintenance/archives/patch-interwiki.sql" ); + echo "ok\n"; + echo "Adding default interwiki definitions: "; + dbsource( "maintenance/interwiki.sql" ); + echo "ok\n"; +} + +function do_index_update() { + # Check that proper indexes are in place + global $wgDatabase; + $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" ); + if( $meta->multiple_key == 0 ) { + echo "Updating indexes to 20031107: "; + dbsource( "maintenance/archives/patch-indexes.sql" ); + echo "ok\n"; + return true; + } + echo "...indexes seem up to 20031107 standards\n"; + 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_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"; + } +} + +?> \ No newline at end of file diff --git a/update.php b/update.php index 01dd7cfd57..4775f602ea 100644 --- a/update.php +++ b/update.php @@ -4,6 +4,7 @@ # include( "./install-utils.inc" ); +include_once( "./maintenance/updaters.inc" ); install_version_checks(); if ( ! ( is_readable( "./LocalSettings.php" ) @@ -130,127 +131,4 @@ function do_update_files() { print "ok\n"; } -function do_revision_updates() { - global $wgSoftwareRevision; - if ( $wgSoftwareRevision < 1001 ) { - update_passwords(); - } -} - -function update_passwords() { - global $wgDatabase; - $fname = "Update script: update_passwords()"; - print "\nIt appears that you need to update the user passwords in your\n" . - "database. If you have already done this (if you've run this update\n" . - "script once before, for example), doing so again will make all your\n" . - "user accounts inaccessible, so be sure you only do this once.\n" . - "Update user passwords? (yes/no)"; - - $resp = readconsole(); - if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; } - - $sql = "SELECT user_id,user_password FROM user"; - $source = $wgDatabase->query( $sql, $fname ); - - while ( $row = $wgDatabase->fetchObject( $source ) ) { - $id = $row->user_id; - $oldpass = $row->user_password; - $newpass = md5( "{$id}-{$oldpass}" ); - - $sql = "UPDATE user SET user_password='{$newpass}' " . - "WHERE user_id={$id}"; - $wgDatabase->query( $sql, $fname ); - } -} - -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; - if( $wgDatabase->tableExists( "interwiki" ) ) { - echo "...already have interwiki table\n"; - return true; - } - echo "Creating interwiki table: "; - dbsource( "maintenance/archives/patch-interwiki.sql" ); - echo "ok\n"; - echo "Adding default interwiki definitions: "; - dbsource( "maintenance/interwiki.sql" ); - echo "ok\n"; -} - -function do_index_update() { - # Check that proper indexes are in place - global $wgDatabase; - $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" ); - if( $meta->multiple_key == 0 ) { - echo "Updating indexes to 20031107: "; - dbsource( "maintenance/archives/patch-indexes.sql" ); - echo "ok\n"; - return true; - } - echo "...indexes seem up to 20031107 standards\n"; - 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_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"; - } -} - ?> -- 2.20.1