3 # Optional upgrade script to populate the img_sha1 field
5 $optionsWithArgs = array( 'method' );
6 require_once( dirname(__FILE__
).'/../commandLine.inc' );
7 $method = isset( $options['method'] ) ?
$options['method'] : 'normal';
9 $t = -microtime( true );
10 $fname = 'populateSha1.php';
11 $dbw = wfGetDB( DB_MASTER
);
12 $res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), $fname );
13 $imageTable = $dbw->tableName( 'image' );
14 $oldimageTable = $dbw->tableName( 'oldimage' );
17 $cmd = 'mysql -u' . wfEscapeShellArg( $wgDBuser ) .
18 ' -h' . wfEscapeShellArg( $wgDBserver ) .
19 ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname );
20 if ( $method == 'pipe' ) {
21 echo "Using pipe method\n";
22 $pipe = popen( $cmd, 'w' );
25 $numRows = $res->numRows();
27 foreach ( $res as $row ) {
28 if ( $i %
100 == 0 ) {
29 printf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 );
32 $file = wfLocalFile( $row->img_name
);
36 $sha1 = File
::sha1Base36( $file->getPath() );
37 if ( strval( $sha1 ) !== '' ) {
38 $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) .
39 " WHERE img_name=" . $dbw->addQuotes( $row->img_name
);
40 if ( $method == 'pipe' ) {
41 fwrite( $pipe, "$sql;\n" );
43 $dbw->query( $sql, $fname );
48 if ( $method == 'pipe' ) {
52 $t +
= microtime( true );
53 printf( "\nDone %d files in %.1f seconds\n", $numRows, $t );