From 39f8a5753dd51da3b2551eb05f756aa0a170e29c Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 12 Apr 2004 07:16:43 +0000 Subject: [PATCH] links schema conversion script, alterations to config/index.php and commandLine.inc to allow it to work --- config/index.php | 6 ++- maintenance/commandLine.inc | 1 + maintenance/convertLinks.php | 88 ++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 maintenance/convertLinks.php diff --git a/config/index.php b/config/index.php index 8509393e93..bd8e62936e 100644 --- a/config/index.php +++ b/config/index.php @@ -633,8 +633,10 @@ function writeLocalSettings( $conf ) { ini_set( \"include_path\", \"\$IP/includes$sep\$IP/languages$sep\" . ini_get(\"include_path\") ); include_once( \"DefaultSettings.php\" ); -if( \$wgCommandLineMode ) { - die( \"Can't use command-line utils with in-place install yet, sorry.\" ); +if ( \$wgCommandLineMode ) { + if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) { + die( \"This script must be run from the command line\\n\" ); + } } else { ## Compress output if the browser supports it {$zlib}if( !ini_get( 'zlib.output_compression' ) ) ob_start( 'ob_gzhandler' ); diff --git a/maintenance/commandLine.inc b/maintenance/commandLine.inc index a103d11755..d43bc0daab 100644 --- a/maintenance/commandLine.inc +++ b/maintenance/commandLine.inc @@ -30,6 +30,7 @@ $DP = "../includes"; include_once( $settingsFile ); ini_set( "include_path", "../includes$sep../languages$sep$newpath$IP$sep$include_path" ); +$wgUsePHPTal = false; include_once( "Setup.php" ); include_once( "./InitialiseMessages.inc" ); include_once( "../install-utils.inc" ); diff --git a/maintenance/convertLinks.php b/maintenance/convertLinks.php new file mode 100644 index 0000000000..5f55541ab8 --- /dev/null +++ b/maintenance/convertLinks.php @@ -0,0 +1,88 @@ +ID) to the new schema (ID->ID) +# This hasn't been tested yet, so expect bugs + +# The wiki should be put into read-only mode while this script executes + +include_once( "commandLine.inc" ); + +# Check if it's already done + +$res = wfQuery( "SELECT * FROM links LIMIT 1", DB_WRITE ); +if ( !wfNumRows( $res ) ) { + print "No rows to convert. Updating schema...\n"; + createTable(); +} else { + $row = wfFetchObject( $res ); + if ( is_numeric( $row->l_from ) ) { + print "Schema already converted\n"; + exit; + } + + # Create a title -> cur_id map + + print "Loading IDs..."; + + wfBufferSQLResults( false ); + $res = wfQuery( "SELECT cur_namespace,cur_title,cur_id FROM cur", DB_WRITE ); + $ids = array(); + + while ( $row = wfFetchObject( $res ) ) { + $title = $row->cur_title; + if ( $row->cur_namespace ) { + $title = $wgLang->getNsText( $row->cur_namespace ) . ":$title"; + } + $ids[$title] = $row->cur_id; + } + wfFreeResult( $res ); + + print "done\n"; + + # Now, load in all the links and create a links table in RAM + print "Processing links...\n"; + $res = wfQuery( "SELECT * FROM links", DB_WRITE ); + $links = array(); + $numBad = 0; + + while ( $row = wfFetchObject( $res ) ) { + if ( array_key_exists( $row->l_from, $ids ) ) { + $links[$ids[$row->l_from]] = $row->l_to; + } else { + $numBad ++; + } + } + + print "Done, $numBad invalid titles\n"; + + # Save it to a new table + createTable(); + $sql = "INSERT INTO links_temp(l_from,l_to) VALUES "; + + $first = true; + foreach( $links as $from => $to ) { + if ( $first ) { + $first = false; + } else { + $sql .= ","; + } + $sql .= "($from,$to)"; + } + + wfQuery( $sql, DB_WRITE ); +} + +# Swap in the new table +wfQuery( "RENAME TABLE links TO links_backup, links_temp TO links" ); + +print "Conversion complete. The old table remains at links_backup, delete at your leisure.\n"; + +function createTable() { + wfQuery( "CREATE TABLE links_temp ( + l_from int(8) unsigned NOT NULL default '0', + l_to int(8) unsigned NOT NULL default '0', + UNIQUE KEY l_from(l_from,l_to), + KEY (l_to))", DB_WRITE); +} + +?> -- 2.20.1