5 * @author Aryeh Gregor (Simetrical)
8 #$optionsWithArgs = array( 'begin', 'max-slave-lag' );
10 require_once( dirname( __FILE__
) . '/Maintenance.php' );
12 class UpdateCollation
extends Maintenance
{
13 const BATCH_SIZE
= 1000;
15 public function __construct() {
16 parent
::__construct();
18 global $wgCollationVersion;
19 $this->mDescription
= <<<TEXT
20 This script will find all rows in the categorylinks table whose collation is
21 out-of-date (cl_collation < $wgCollationVersion) and repopulate cl_sortkey
22 using cl_raw_sortkey. If everything's collation is up-to-date, it will do
26 #$this->addOption( 'force', 'Run on all rows, even if the collation is supposed to be up-to-date.' );
29 public function execute() {
30 global $wgCollationVersion, $wgContLang;
32 $dbw = wfGetDB( DB_MASTER
);
33 $count = $dbw->estimateRowCount(
35 array( 'cl_from', 'cl_to', 'cl_raw_sortkey' ),
36 'cl_collation < ' . $dbw->addQuotes( $wgCollationVersion ),
40 $this->output( "Fixing around $count rows (estimate might be wrong).\n" );
46 array( 'cl_from', 'cl_to', 'cl_raw_sortkey' ),
47 'cl_collation < ' . $dbw->addQuotes( $wgCollationVersion ),
49 array( 'LIMIT' => self
::BATCH_SIZE
)
53 foreach ( $res as $row ) {
54 # TODO: Handle the case where cl_raw_sortkey is null.
58 'cl_sortkey' => $wgContLang->convertToSortkey( $row->cl_raw_sortkey
),
59 'cl_collation' => $wgCollationVersion
61 array( 'cl_from' => $row->cl_from
, 'cl_to' => $row->cl_to
),
67 $count +
= self
::BATCH_SIZE
;
68 $this->output( "$count done.\n" );
69 } while ( $res->numRows() >= self
::BATCH_SIZE
);
73 $maintClass = "UpdateCollation";
74 require_once( DO_MAINTENANCE
);