Allow reset of global services.
[lhc/web/wiklou.git] / maintenance / convertLinks.php
index 11a81eb..54c0eda 100644 (file)
@@ -36,9 +36,9 @@ class ConvertLinks extends Maintenance {
 
        public function __construct() {
                parent::__construct();
-               $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->addDescription(
+                       '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 );
                $this->addArg(
@@ -66,7 +66,7 @@ class ConvertLinks extends Maintenance {
        }
 
        public function execute() {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
 
                $type = $dbw->getType();
                if ( $type != 'mysql' ) {
@@ -140,7 +140,7 @@ class ConvertLinks extends Maintenance {
                                        $this->logPerformance = false;
                                }
                        }
-                       $baseTime = $startTime = $this->getMicroTime();
+                       $baseTime = $startTime = microtime( true );
                        # Create a title -> cur_id map
                        $this->output( "Loading IDs from $cur table...\n" );
                        $this->performanceLog( $fh, "Reading $numRows rows from cur table...\n" );
@@ -148,7 +148,7 @@ class ConvertLinks extends Maintenance {
 
                        $dbw->bufferResults( false );
                        $res = $dbw->query( "SELECT cur_namespace,cur_title,cur_id FROM $cur" );
-                       $ids = array();
+                       $ids = [];
 
                        foreach ( $res as $row ) {
                                $title = $row->cur_title;
@@ -161,7 +161,7 @@ class ConvertLinks extends Maintenance {
                                        if ( ( $curRowsRead % $curReadReportInterval ) == 0 ) {
                                                $this->performanceLog(
                                                        $fh,
-                                                       $curRowsRead . " " . ( $this->getMicroTime() - $baseTime ) . "\n"
+                                                       $curRowsRead . " " . ( microtime( true ) - $baseTime ) . "\n"
                                                );
                                                $this->output( "\t$curRowsRead rows of $cur table read.\n" );
                                        }
@@ -172,7 +172,7 @@ class ConvertLinks extends Maintenance {
                        $this->output( "Finished loading IDs.\n\n" );
                        $this->performanceLog(
                                $fh,
-                               "Took " . ( $this->getMicroTime() - $baseTime ) . " seconds to load IDs.\n\n"
+                               "Took " . ( microtime( true ) - $baseTime ) . " seconds to load IDs.\n\n"
                        );
 
                        # --------------------------------------------------------------------
@@ -181,7 +181,7 @@ class ConvertLinks extends Maintenance {
                        # convert, and write to the new table.
                        $this->createTempTable();
                        $this->performanceLog( $fh, "Resetting timer.\n\n" );
-                       $baseTime = $this->getMicroTime();
+                       $baseTime = microtime( true );
                        $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" );
@@ -193,9 +193,9 @@ class ConvertLinks extends Maintenance {
                                $sqlRead = $dbw->limitResult( $sqlRead, $linksConvInsertInterval, $rowOffset );
                                $res = $dbw->query( $sqlRead );
                                if ( $noKeys ) {
-                                       $sqlWrite = array( "INSERT INTO $links_temp (l_from,l_to) VALUES " );
+                                       $sqlWrite = [ "INSERT INTO $links_temp (l_from,l_to) VALUES " ];
                                } else {
-                                       $sqlWrite = array( "INSERT IGNORE INTO $links_temp (l_from,l_to) VALUES " );
+                                       $sqlWrite = [ "INSERT IGNORE INTO $links_temp (l_from,l_to) VALUES " ];
                                }
 
                                $tuplesAdded = 0; # no tuples added to INSERT yet
@@ -215,7 +215,7 @@ class ConvertLinks extends Maintenance {
                                }
                                $dbw->freeResult( $res );
                                # $this->output( "rowOffset: $rowOffset\ttuplesAdded: "
-                               #       . "$tuplesAdded\tnumBadLinks: $numBadLinks\n" );
+                               #       . "$tuplesAdded\tnumBadLinks: $numBadLinks\n" );
                                if ( $tuplesAdded != 0 ) {
                                        if ( $reportLinksConvProgress ) {
                                                $this->output( "Inserting $tuplesAdded tuples into $links_temp..." );
@@ -226,7 +226,7 @@ class ConvertLinks extends Maintenance {
                                                $this->output( " done. Total $totalTuplesInserted tuples inserted.\n" );
                                                $this->performanceLog(
                                                        $fh,
-                                                       $totalTuplesInserted . " " . ( $this->getMicroTime() - $baseTime ) . "\n"
+                                                       $totalTuplesInserted . " " . ( microtime( true ) - $baseTime ) . "\n"
                                                );
                                        }
                                }
@@ -239,7 +239,7 @@ class ConvertLinks extends Maintenance {
                        );
                        $this->performanceLog(
                                $fh,
-                               "Total execution time: " . ( $this->getMicroTime() - $startTime ) . " seconds.\n"
+                               "Total execution time: " . ( microtime( true ) - $startTime ) . " seconds.\n"
                        );
                        if ( $this->logPerformance ) {
                                fclose( $fh );
@@ -267,7 +267,7 @@ class ConvertLinks extends Maintenance {
        }
 
        private function createTempTable() {
-               $dbConn = wfGetDB( DB_MASTER );
+               $dbConn = $this->getDB( DB_MASTER );
 
                if ( !( $dbConn->isOpen() ) ) {
                        $this->output( "Opening connection to database failed.\n" );
@@ -300,12 +300,6 @@ class ConvertLinks extends Maintenance {
                        fwrite( $fh, $text );
                }
        }
-
-       private function getMicroTime() { # return time in seconds, with microsecond accuracy
-               list( $usec, $sec ) = explode( " ", microtime() );
-
-               return ( (float)$usec + (float)$sec );
-       }
 }
 
 $maintClass = "ConvertLinks";