From ca80c48416df0cfd2ef18ce52fd1e3c665ca03f0 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 25 Aug 2007 15:15:15 +0000 Subject: [PATCH] Optional upgrade script to populate the img_sha1 field --- maintenance/archives/populateSha1.php | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 maintenance/archives/populateSha1.php diff --git a/maintenance/archives/populateSha1.php b/maintenance/archives/populateSha1.php new file mode 100644 index 0000000000..a34d36d312 --- /dev/null +++ b/maintenance/archives/populateSha1.php @@ -0,0 +1,43 @@ +select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), $fname ); +$imageTable = $dbw->tableName( 'image' ); +$oldimageTable = $dbw->tableName( 'oldimage' ); +$batch = array(); + +$cmd = 'mysql -u ' . wfEscapeShellArg( $wgDBuser ) . ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname ); +if ( $method == 'pipe' ) { + $pipe = popen( $cmd, 'w' ); + fwrite( $pipe, "-- hello\n" ); +} + +foreach ( $res as $row ) { + $file = wfLocalFile( $row->img_name ); + $sha1 = File::sha1Base36( $file->getPath() ); + if ( strval( $sha1 ) !== '' ) { + $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) . + " WHERE img_name=" . $dbw->addQuotes( $row->img_name ); + if ( $method == 'pipe' ) { + fwrite( $pipe, $sql ); + } else { + $dbw->query( $sql, $fname ); + } + } +} +if ( $method == 'pipe' ) { + fflush( $pipe ); + pclose( $pipe ); +} +$t += microtime( true ); +print "Done in $t seconds\n"; + +?> -- 2.20.1