r25134 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25133‎ | r25134 | r25135 >
Date:15:15, 25 August 2007
Author:tstarling
Status:old
Tags:
Comment:
Optional upgrade script to populate the img_sha1 field
Modified paths:
  • /trunk/phase3/maintenance/archives/populateSha1.php (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/archives/populateSha1.php
@@ -0,0 +1,43 @@
 2+<?php
 3+
 4+# Optional upgrade script to populate the img_sha1 field
 5+
 6+$optionsWithArgs = array( 'method' );
 7+require_once( dirname(__FILE__).'/../commandLine.inc' );
 8+$method = isset( $args['method'] ) ? $args['method'] : 'normal';
 9+
 10+$t = -microtime( true );
 11+$fname = 'populateSha1.php';
 12+$dbw = wfGetDB( DB_MASTER );
 13+$res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), $fname );
 14+$imageTable = $dbw->tableName( 'image' );
 15+$oldimageTable = $dbw->tableName( 'oldimage' );
 16+$batch = array();
 17+
 18+$cmd = 'mysql -u ' . wfEscapeShellArg( $wgDBuser ) . ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname );
 19+if ( $method == 'pipe' ) {
 20+ $pipe = popen( $cmd, 'w' );
 21+ fwrite( $pipe, "-- hello\n" );
 22+}
 23+
 24+foreach ( $res as $row ) {
 25+ $file = wfLocalFile( $row->img_name );
 26+ $sha1 = File::sha1Base36( $file->getPath() );
 27+ if ( strval( $sha1 ) !== '' ) {
 28+ $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) .
 29+ " WHERE img_name=" . $dbw->addQuotes( $row->img_name );
 30+ if ( $method == 'pipe' ) {
 31+ fwrite( $pipe, $sql );
 32+ } else {
 33+ $dbw->query( $sql, $fname );
 34+ }
 35+ }
 36+}
 37+if ( $method == 'pipe' ) {
 38+ fflush( $pipe );
 39+ pclose( $pipe );
 40+}
 41+$t += microtime( true );
 42+print "Done in $t seconds\n";
 43+
 44+?>
Property changes on: trunk/phase3/maintenance/archives/populateSha1.php
___________________________________________________________________
Added: svn:eol-style
145 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r25223Merged revisions 25126-25214 via svnmerge from...david07:39, 28 August 2007

Status & tagging log