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