From: Brion Vibber Date: Tue, 29 Jan 2008 00:13:33 +0000 (+0000) Subject: Applying live hack from Wikimedia code base: option and reporting tweaks for populate... X-Git-Tag: 1.31.0-rc.0~49741 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=c12fc4fc45e5e5d1e9cdb6ac7286d7d0cc3a594b;p=lhc%2Fweb%2Fwiklou.git Applying live hack from Wikimedia code base: option and reporting tweaks for populateSha1.php --- diff --git a/maintenance/archives/populateSha1.php b/maintenance/archives/populateSha1.php index a34d36d312..45f29c4376 100644 --- a/maintenance/archives/populateSha1.php +++ b/maintenance/archives/populateSha1.php @@ -4,7 +4,7 @@ $optionsWithArgs = array( 'method' ); require_once( dirname(__FILE__).'/../commandLine.inc' ); -$method = isset( $args['method'] ) ? $args['method'] : 'normal'; +$method = isset( $options['method'] ) ? $options['method'] : 'normal'; $t = -microtime( true ); $fname = 'populateSha1.php'; @@ -14,30 +14,42 @@ $imageTable = $dbw->tableName( 'image' ); $oldimageTable = $dbw->tableName( 'oldimage' ); $batch = array(); -$cmd = 'mysql -u ' . wfEscapeShellArg( $wgDBuser ) . ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname ); +$cmd = 'mysql -u' . wfEscapeShellArg( $wgDBuser ) . + ' -h' . wfEscapeShellArg( $wgDBserver ) . + ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname ); if ( $method == 'pipe' ) { + echo "Using pipe method\n"; $pipe = popen( $cmd, 'w' ); - fwrite( $pipe, "-- hello\n" ); } +$numRows = $res->numRows(); +$i = 0; foreach ( $res as $row ) { + if ( $i % 100 == 0 ) { + printf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ); + wfWaitForSlaves( 5 ); + } $file = wfLocalFile( $row->img_name ); + if ( !$file ) { + continue; + } $sha1 = File::sha1Base36( $file->getPath() ); if ( strval( $sha1 ) !== '' ) { $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) . " WHERE img_name=" . $dbw->addQuotes( $row->img_name ); if ( $method == 'pipe' ) { - fwrite( $pipe, $sql ); + fwrite( $pipe, "$sql;\n" ); } else { $dbw->query( $sql, $fname ); } } + $i++; } if ( $method == 'pipe' ) { fflush( $pipe ); pclose( $pipe ); } $t += microtime( true ); -print "Done in $t seconds\n"; +printf( "\nDone %d files in %.1f seconds\n", $numRows, $t ); ?>