3 * Fills the rev_sha1 and ar_sha1 columns of revision & archive tables.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @ingroup Maintenance
23 require_once( dirname( __FILE__
) . '/Maintenance.php' );
25 class PopulateRevisionSha1
extends Maintenance
{
26 public function __construct() {
27 parent
::__construct();
28 $this->mDescription
= "Populates the rev_sha1 and ar_sha1 fields";
29 $this->setBatchSize( 150 );
32 public function execute() {
33 $db = wfGetDB( DB_MASTER
);
35 $this->output( "Populating rev_sha1 column\n" );
36 $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
38 $this->output( "Populating ar_sha1 column\n" );
39 $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
43 array( 'ul_key' => 'populate rev_sha1' ),
48 $this->output( "rev_sha1 and ar_sha1 population complete.\n" );
51 $this->output( "Could not insert rev_sha1 population row.\n" );
56 protected function doSha1Updates( $db, $table, $idCol, $prefix ) {
57 $start = $db->selectField( $table, "MIN($idCol)", "$idCol IS NOT NULL", __METHOD__
);
59 $this->output( "Nothing to do.\n" );
62 $end = $db->selectField( $table, "MAX($idCol)", "$idCol IS NOT NULL", __METHOD__
);
65 $end +
= $this->mBatchSize
- 1;
67 $blockEnd = $start +
$this->mBatchSize
- 1;
68 while ( $blockEnd <= $end ) {
69 $this->output( "...doing $idCol from $blockStart to $blockEnd\n" );
70 $cond = "$idCol BETWEEN $blockStart AND $blockEnd
71 AND $idCol IS NOT NULL AND {$prefix}_sha1 IS NOT NULL";
72 $res = $db->select( $table, '*', $cond, __METHOD__
);
75 foreach ( $res as $row ) {
76 if ( $table === 'archive' ) {
77 $rev = Revision
::newFromArchiveRow( $row );
79 $rev = new Revision( $row );
82 array( "{$prefix}_sha1" => Revision
::base36Sha1( $rev->getRawText() ) ),
83 array( $idCol => $row->$idCol ),
88 $blockStart +
= $this->mBatchSize
;
89 $blockEnd +
= $this->mBatchSize
;
95 $maintClass = "PopulateRevisionSha1";
96 require_once( RUN_MAINTENANCE_IF_MAIN
);