<?php
/**
- * Convert from the old links schema (string->ID) to the new schema (ID->ID)
- * The wiki should be put into read-only mode while this script executes
+ * Convert from the old links schema (string->ID) to the new schema (ID->ID).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* @ingroup Maintenance
*/
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once( __DIR__ . '/Maintenance.php' );
+/**
+ * Maintenance script to convert from the old links schema (string->ID)
+ * to the new schema (ID->ID).
+ *
+ * The wiki should be put into read-only mode while this script executes.
+ *
+ * @ingroup Maintenance
+ */
class ConvertLinks extends Maintenance {
private $logPerformance;
public function __construct() {
parent::__construct();
- $this->mDescription = "Convert from the old links schema (string->ID) to the new schema (ID->ID)
+ $this->mDescription = "Convert from the old links schema (string->ID) to the new schema (ID->ID).
The wiki should be put into read-only mode while this script executes";
$this->addArg( 'logperformance', "Log performance to perfLogFilename.", false );
}
global $wgContLang;
-
+
$numBadLinks = $curRowsRead = 0; # counters etc
$totalTuplesInserted = 0; # total tuples INSERTed into links_temp
$overwriteLinksTable = !$this->hasOption( 'keep-links-table' );
$noKeys = $this->hasOption( 'noKeys' );
- $this->logPerformance = $this->hasOption( 'logperformance' );
+ $this->logPerformance = $this->hasOption( 'logperformance' );
$perfLogFilename = $this->getArg( 'perfLogFilename', "convLinksPerf.txt" );
# --------------------------------------------------------------------
$this->output( "...have pagelinks; skipping old links table updates\n" );
return;
}
-
+
$res = $dbw->query( "SELECT l_from FROM $links LIMIT 1" );
if ( $dbw->fieldType( $res, 0 ) == "int" ) {
$this->output( "Schema already converted\n" );
return;
}
-
+
$res = $dbw->query( "SELECT COUNT(*) AS count FROM $links" );
$row = $dbw->fetchObject( $res );
$numRows = $row->count;
$dbw->freeResult( $res );
-
+
if ( $numRows == 0 ) {
$this->output( "Updating schema (no rows to convert)...\n" );
$this->createTempTable();
$res = $dbw->query( "SELECT cur_namespace,cur_title,cur_id FROM $cur" );
$ids = array();
- while ( $row = $dbw->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
$title = $row->cur_title;
if ( $row->cur_namespace ) {
$title = $wgContLang->getNsText( $row->cur_namespace ) . ":$title";
$this->output( "Processing $numRows rows from $links table...\n" );
$this->performanceLog( $fh, "Processing $numRows rows from $links table...\n" );
$this->performanceLog( $fh, "rows inserted vs seconds elapsed:\n" );
-
+
for ( $rowOffset = $initialRowOffset; $rowOffset < $numRows; $rowOffset += $linksConvInsertInterval ) {
$sqlRead = "SELECT * FROM $links ";
$sqlRead = $dbw->limitResult( $sqlRead, $linksConvInsertInterval, $rowOffset );
} else {
$sqlWrite = array( "INSERT IGNORE INTO $links_temp (l_from,l_to) VALUES " );
}
-
+
$tuplesAdded = 0; # no tuples added to INSERT yet
- while ( $row = $dbw->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
$fromTitle = $row->l_from;
if ( array_key_exists( $fromTitle, $ids ) ) { # valid title
$from = $ids[$fromTitle];
if ( $overwriteLinksTable ) {
# Check for existing links_backup, and delete it if it exists.
$this->output( "Dropping backup links table if it exists..." );
- $dbw->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER );
+ $dbw->query( "DROP TABLE IF EXISTS $links_backup", __METHOD__ );
$this->output( " done.\n" );
-
+
# Swap in the new table, and move old links table to links_backup
$this->output( "Swapping tables '$links' to '$links_backup'; '$links_temp' to '$links'..." );
- $dbw->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", DB_MASTER );
+ $dbw->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", __METHOD__ );
$this->output( " done.\n\n" );
-
+
$dbw->close();
$this->output( "Conversion complete. The old table remains at $links_backup;\n" );
$this->output( "delete at your leisure.\n" );
}
$maintClass = "ConvertLinks";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );