Mark the bug number for export thing
[mediawiki.git] / maintenance / archives / populateSha1.php
bloba34d36d3127b1651013a7124bdc05b6a55bcf395
1 <?php
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' );
15 $batch = array();
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 );
31 } else {
32 $dbw->query( $sql, $fname );
36 if ( $method == 'pipe' ) {
37 fflush( $pipe );
38 pclose( $pipe );
40 $t += microtime( true );
41 print "Done in $t seconds\n";