3 # Optional upgrade script to populate the img_sha1 field
5 $optionsWithArgs = array( 'method' );
6 require_once( dirname(__FILE__
).'/../commandLine.inc' );
7 $method = isset( $args['method'] ) ?
$args['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 ) . ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname );
18 if ( $method == 'pipe' ) {
19 $pipe = popen( $cmd, 'w' );
20 fwrite( $pipe, "-- hello\n" );
23 foreach ( $res as $row ) {
24 $file = wfLocalFile( $row->img_name
);
25 $sha1 = File
::sha1Base36( $file->getPath() );
26 if ( strval( $sha1 ) !== '' ) {
27 $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) .
28 " WHERE img_name=" . $dbw->addQuotes( $row->img_name
);
29 if ( $method == 'pipe' ) {
30 fwrite( $pipe, $sql );
32 $dbw->query( $sql, $fname );
36 if ( $method == 'pipe' ) {
40 $t +
= microtime( true );
41 print "Done in $t seconds\n";