00001 <?php
00009 $optionsWithArgs = array( 'method' );
00010 require_once( dirname(__FILE__).'/../commandLine.inc' );
00011 $method = isset( $options['method'] ) ? $options['method'] : 'normal';
00012
00013 $t = -microtime( true );
00014 $fname = 'populateSha1.php';
00015 $dbw = wfGetDB( DB_MASTER );
00016 $res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), $fname );
00017 $imageTable = $dbw->tableName( 'image' );
00018 $oldimageTable = $dbw->tableName( 'oldimage' );
00019 $batch = array();
00020
00021 $cmd = 'mysql -u' . wfEscapeShellArg( $wgDBuser ) .
00022 ' -h' . wfEscapeShellArg( $wgDBserver ) .
00023 ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname );
00024 if ( $method == 'pipe' ) {
00025 echo "Using pipe method\n";
00026 $pipe = popen( $cmd, 'w' );
00027 }
00028
00029 $numRows = $res->numRows();
00030 $i = 0;
00031 foreach ( $res as $row ) {
00032 if ( $i % 100 == 0 ) {
00033 printf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 );
00034 wfWaitForSlaves( 5 );
00035 }
00036 $file = wfLocalFile( $row->img_name );
00037 if ( !$file ) {
00038 continue;
00039 }
00040 $sha1 = File::sha1Base36( $file->getPath() );
00041 if ( strval( $sha1 ) !== '' ) {
00042 $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) .
00043 " WHERE img_name=" . $dbw->addQuotes( $row->img_name );
00044 if ( $method == 'pipe' ) {
00045 fwrite( $pipe, "$sql;\n" );
00046 } else {
00047 $dbw->query( $sql, $fname );
00048 }
00049 }
00050 $i++;
00051 }
00052 if ( $method == 'pipe' ) {
00053 fflush( $pipe );
00054 pclose( $pipe );
00055 }
00056 $t += microtime( true );
00057 printf( "\nDone %d files in %.1f seconds\n", $numRows, $t );
00058
00059 ?>