Index: trunk/phase3/maintenance/Maintenance.php |
— | — | @@ -1305,7 +1305,7 @@ |
1306 | 1306 | |
1307 | 1307 | /** |
1308 | 1308 | * Do the actual work. All child classes will need to implement this. |
1309 | | - * Return true to log the update as done or false on failure. |
| 1309 | + * Return true to log the update as done or false (usually on failure). |
1310 | 1310 | * @return Bool |
1311 | 1311 | */ |
1312 | 1312 | abstract protected function doDBUpdates(); |
Index: trunk/phase3/maintenance/populateImageSha1.php |
— | — | @@ -22,16 +22,29 @@ |
23 | 23 | |
24 | 24 | require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
25 | 25 | |
26 | | -class PopulateImageSha1 extends Maintenance { |
| 26 | +class PopulateImageSha1 extends LoggedUpdateMaintenance { |
27 | 27 | public function __construct() { |
28 | 28 | parent::__construct(); |
29 | 29 | $this->mDescription = "Populate the img_sha1 field"; |
30 | 30 | $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" . |
31 | 31 | "\t\tdefault uses Database class", false, true ); |
32 | 32 | $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true ); |
| 33 | + $this->setBatchSize( 200 ); |
33 | 34 | } |
34 | 35 | |
35 | | - public function execute() { |
| 36 | + protected function getUpdateKey() { |
| 37 | + return 'populate img_sha1'; |
| 38 | + } |
| 39 | + |
| 40 | + protected function updateSkippedMessage() { |
| 41 | + return 'img_sha1 column of image table already populated.'; |
| 42 | + } |
| 43 | + |
| 44 | + protected function updatelogFailedMessage() { |
| 45 | + return 'Could not insert img_sha1 population row.'; |
| 46 | + } |
| 47 | + |
| 48 | + public function doDBUpdates() { |
36 | 49 | $method = $this->getOption( 'method', 'normal' ); |
37 | 50 | $file = $this->getOption( 'file' ); |
38 | 51 | |
— | — | @@ -46,11 +59,15 @@ |
47 | 60 | ); |
48 | 61 | if ( !$res ) { |
49 | 62 | $this->error( "No such file: $file", true ); |
50 | | - return; |
| 63 | + return false; |
51 | 64 | } |
| 65 | + $this->output( "Populating img_sha1 field for specified files\n" ); |
52 | 66 | } else { |
53 | | - $res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ ); |
| 67 | + $res = $dbw->select( 'image', |
| 68 | + array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ ); |
| 69 | + $this->output( "Populating img_sha1 field\n" ); |
54 | 70 | } |
| 71 | + |
55 | 72 | $imageTable = $dbw->tableName( 'image' ); |
56 | 73 | |
57 | 74 | if ( $method == 'pipe' ) { |
— | — | @@ -66,7 +83,7 @@ |
67 | 84 | $numRows = $res->numRows(); |
68 | 85 | $i = 0; |
69 | 86 | foreach ( $res as $row ) { |
70 | | - if ( $i % 100 == 0 ) { |
| 87 | + if ( $i % $this->mBatchSize == 0 ) { |
71 | 88 | $this->output( sprintf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ) ); |
72 | 89 | wfWaitForSlaves(); |
73 | 90 | } |
— | — | @@ -92,6 +109,12 @@ |
93 | 110 | } |
94 | 111 | $t += microtime( true ); |
95 | 112 | $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $numRows, $t ) ); |
| 113 | + |
| 114 | + if ( $file ) { |
| 115 | + return false; // we only updated *some* files, don't log |
| 116 | + } else { |
| 117 | + return true; |
| 118 | + } |
96 | 119 | } |
97 | 120 | } |
98 | 121 | |
Index: trunk/phase3/includes/installer/DatabaseUpdater.php |
— | — | @@ -42,7 +42,8 @@ |
43 | 43 | protected $postDatabaseUpdateMaintenance = array( |
44 | 44 | 'DeleteDefaultMessages', |
45 | 45 | 'PopulateRevisionLength', |
46 | | - 'PopulateRevisionSha1' |
| 46 | + 'PopulateRevisionSha1', |
| 47 | + 'PopulateImageSha1' |
47 | 48 | ); |
48 | 49 | |
49 | 50 | /** |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -835,6 +835,7 @@ |
836 | 836 | 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php', |
837 | 837 | 'Maintenance' => 'maintenance/Maintenance.php', |
838 | 838 | 'PopulateCategory' => 'maintenance/populateCategory.php', |
| 839 | + 'PopulateImageSha1' => 'maintenance/populateImageSha1.php', |
839 | 840 | 'PopulateLogSearch' => 'maintenance/populateLogSearch.php', |
840 | 841 | 'PopulateLogUsertext' => 'maintenance/populateLogUsertext.php', |
841 | 842 | 'PopulateParentId' => 'maintenance/populateParentId.php', |