Index: trunk/phase3/maintenance/populateSha1.php |
— | — | @@ -1,99 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Optional upgrade script to populate the img_sha1 field |
5 | | - * |
6 | | - * This program is free software; you can redistribute it and/or modify |
7 | | - * it under the terms of the GNU General Public License as published by |
8 | | - * the Free Software Foundation; either version 2 of the License, or |
9 | | - * (at your option) any later version. |
10 | | - * |
11 | | - * This program is distributed in the hope that it will be useful, |
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | - * GNU General Public License for more details. |
15 | | - * |
16 | | - * You should have received a copy of the GNU General Public License along |
17 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
18 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | | - * http://www.gnu.org/copyleft/gpl.html |
20 | | - * |
21 | | - * @ingroup Maintenance |
22 | | - */ |
23 | | - |
24 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
25 | | - |
26 | | -class PopulateSha1 extends Maintenance { |
27 | | - public function __construct() { |
28 | | - parent::__construct(); |
29 | | - $this->mDescription = "Populate the img_sha1 field"; |
30 | | - $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" . |
31 | | - "\t\tdefault uses Database class", false, true ); |
32 | | - $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true ); |
33 | | - } |
34 | | - |
35 | | - public function execute() { |
36 | | - $method = $this->getOption( 'method', 'normal' ); |
37 | | - $file = $this->getOption( 'file' ); |
38 | | - |
39 | | - $t = -microtime( true ); |
40 | | - $dbw = wfGetDB( DB_MASTER ); |
41 | | - if ( $file ) { |
42 | | - $res = $dbw->selectRow( |
43 | | - 'image', |
44 | | - array( 'img_name' ), |
45 | | - array( 'img_name' => $dbw->addQuotes( $file ) ), |
46 | | - __METHOD__ |
47 | | - ); |
48 | | - if ( !$res ) { |
49 | | - $this->error( "No such file: $file", true ); |
50 | | - return; |
51 | | - } |
52 | | - } else { |
53 | | - $res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ ); |
54 | | - } |
55 | | - $imageTable = $dbw->tableName( 'image' ); |
56 | | - |
57 | | - if ( $method == 'pipe' ) { |
58 | | - // @todo FIXME: Kill this and replace with a second unbuffered DB connection. |
59 | | - global $wgDBuser, $wgDBserver, $wgDBpassword, $wgDBname; |
60 | | - $cmd = 'mysql -u' . wfEscapeShellArg( $wgDBuser ) . |
61 | | - ' -h' . wfEscapeShellArg( $wgDBserver ) . |
62 | | - ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname ); |
63 | | - $this->output( "Using pipe method\n" ); |
64 | | - $pipe = popen( $cmd, 'w' ); |
65 | | - } |
66 | | - |
67 | | - $numRows = $res->numRows(); |
68 | | - $i = 0; |
69 | | - foreach ( $res as $row ) { |
70 | | - if ( $i % 100 == 0 ) { |
71 | | - $this->output( sprintf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ) ); |
72 | | - wfWaitForSlaves(); |
73 | | - } |
74 | | - $file = wfLocalFile( $row->img_name ); |
75 | | - if ( !$file ) { |
76 | | - continue; |
77 | | - } |
78 | | - $sha1 = File::sha1Base36( $file->getPath() ); |
79 | | - if ( strval( $sha1 ) !== '' ) { |
80 | | - $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) . |
81 | | - " WHERE img_name=" . $dbw->addQuotes( $row->img_name ); |
82 | | - if ( $method == 'pipe' ) { |
83 | | - fwrite( $pipe, "$sql;\n" ); |
84 | | - } else { |
85 | | - $dbw->query( $sql, __METHOD__ ); |
86 | | - } |
87 | | - } |
88 | | - $i++; |
89 | | - } |
90 | | - if ( $method == 'pipe' ) { |
91 | | - fflush( $pipe ); |
92 | | - pclose( $pipe ); |
93 | | - } |
94 | | - $t += microtime( true ); |
95 | | - $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $numRows, $t ) ); |
96 | | - } |
97 | | -} |
98 | | - |
99 | | -$maintClass = "PopulateSha1"; |
100 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/phase3/maintenance/populateImageSha1.php |
— | — | @@ -0,0 +1,99 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Optional upgrade script to populate the img_sha1 field |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @ingroup Maintenance |
| 22 | + */ |
| 23 | + |
| 24 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 25 | + |
| 26 | +class PopulateImageSha1 extends Maintenance { |
| 27 | + public function __construct() { |
| 28 | + parent::__construct(); |
| 29 | + $this->mDescription = "Populate the img_sha1 field"; |
| 30 | + $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" . |
| 31 | + "\t\tdefault uses Database class", false, true ); |
| 32 | + $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true ); |
| 33 | + } |
| 34 | + |
| 35 | + public function execute() { |
| 36 | + $method = $this->getOption( 'method', 'normal' ); |
| 37 | + $file = $this->getOption( 'file' ); |
| 38 | + |
| 39 | + $t = -microtime( true ); |
| 40 | + $dbw = wfGetDB( DB_MASTER ); |
| 41 | + if ( $file ) { |
| 42 | + $res = $dbw->selectRow( |
| 43 | + 'image', |
| 44 | + array( 'img_name' ), |
| 45 | + array( 'img_name' => $dbw->addQuotes( $file ) ), |
| 46 | + __METHOD__ |
| 47 | + ); |
| 48 | + if ( !$res ) { |
| 49 | + $this->error( "No such file: $file", true ); |
| 50 | + return; |
| 51 | + } |
| 52 | + } else { |
| 53 | + $res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ ); |
| 54 | + } |
| 55 | + $imageTable = $dbw->tableName( 'image' ); |
| 56 | + |
| 57 | + if ( $method == 'pipe' ) { |
| 58 | + // @todo FIXME: Kill this and replace with a second unbuffered DB connection. |
| 59 | + global $wgDBuser, $wgDBserver, $wgDBpassword, $wgDBname; |
| 60 | + $cmd = 'mysql -u' . wfEscapeShellArg( $wgDBuser ) . |
| 61 | + ' -h' . wfEscapeShellArg( $wgDBserver ) . |
| 62 | + ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname ); |
| 63 | + $this->output( "Using pipe method\n" ); |
| 64 | + $pipe = popen( $cmd, 'w' ); |
| 65 | + } |
| 66 | + |
| 67 | + $numRows = $res->numRows(); |
| 68 | + $i = 0; |
| 69 | + foreach ( $res as $row ) { |
| 70 | + if ( $i % 100 == 0 ) { |
| 71 | + $this->output( sprintf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ) ); |
| 72 | + wfWaitForSlaves(); |
| 73 | + } |
| 74 | + $file = wfLocalFile( $row->img_name ); |
| 75 | + if ( !$file ) { |
| 76 | + continue; |
| 77 | + } |
| 78 | + $sha1 = File::sha1Base36( $file->getPath() ); |
| 79 | + if ( strval( $sha1 ) !== '' ) { |
| 80 | + $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) . |
| 81 | + " WHERE img_name=" . $dbw->addQuotes( $row->img_name ); |
| 82 | + if ( $method == 'pipe' ) { |
| 83 | + fwrite( $pipe, "$sql;\n" ); |
| 84 | + } else { |
| 85 | + $dbw->query( $sql, __METHOD__ ); |
| 86 | + } |
| 87 | + } |
| 88 | + $i++; |
| 89 | + } |
| 90 | + if ( $method == 'pipe' ) { |
| 91 | + fflush( $pipe ); |
| 92 | + pclose( $pipe ); |
| 93 | + } |
| 94 | + $t += microtime( true ); |
| 95 | + $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $numRows, $t ) ); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +$maintClass = "PopulateImageSha1"; |
| 100 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/phase3/maintenance/populateImageSha1.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 101 | + native |