r80615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80614‎ | r80615 | r80616 >
Date:06:24, 20 January 2011
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
Add --force option to updateCollation.php.
Modified paths:
  • /trunk/phase3/maintenance/updateCollation.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updateCollation.php
@@ -42,39 +42,51 @@
4343 up-to-date, it will do nothing.
4444 TEXT;
4545
46 - #$this->addOption( 'force', 'Run on all rows, even if the collation is supposed to be up-to-date.' );
 46+ $this->addOption( 'force', 'Run on all rows, even if the collation is ' .
 47+ 'supposed to be up-to-date.' );
4748 }
4849
4950 public function execute() {
5051 global $wgCategoryCollation;
5152
5253 $dbw = wfGetDB( DB_MASTER );
53 - $count = $dbw->selectField(
54 - 'categorylinks',
55 - 'COUNT(*)',
56 - 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
57 - __METHOD__
58 - );
 54+ $force = $this->getOption( 'force' );
5955
60 - if ( $count == 0 ) {
61 - $this->output( "Collations up-to-date.\n" );
62 - return;
 56+ $options = array( 'LIMIT' => self::BATCH_SIZE );
 57+
 58+ if ( $force ) {
 59+ $collationConds = array();
 60+ $options['ORDER BY'] = 'cl_from, cl_to';
 61+ } else {
 62+ $collationConds = array( 0 =>
 63+ 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ) );
 64+
 65+ $count = $dbw->selectField(
 66+ 'categorylinks',
 67+ 'COUNT(*)',
 68+ $collationConds,
 69+ __METHOD__
 70+ );
 71+
 72+ if ( $count == 0 ) {
 73+ $this->output( "Collations up-to-date.\n" );
 74+ return;
 75+ }
 76+ $this->output( "Fixing collation for $count rows.\n" );
6377 }
64 - $this->output( "Fixing collation for $count rows.\n" );
6578
6679 $count = 0;
 80+ $row = false;
 81+ $batchConds = array();
6782 do {
6883 $res = $dbw->select(
6984 array( 'categorylinks', 'page' ),
7085 array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation',
7186 'cl_sortkey', 'page_namespace', 'page_title'
7287 ),
73 - array(
74 - 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
75 - 'cl_from = page_id'
76 - ),
 88+ array_merge( $collationConds, $batchConds, array( 'cl_from = page_id' ) ),
7789 __METHOD__,
78 - array( 'LIMIT' => self::BATCH_SIZE )
 90+ $options
7991 );
8092
8193 $dbw->begin();
@@ -118,6 +130,14 @@
119131 }
120132 $dbw->commit();
121133
 134+ if ( $force && $row ) {
 135+ $encFrom = $dbw->addQuotes( $row->cl_from );
 136+ $encTo = $dbw->addQuotes( $row->cl_to );
 137+ $batchConds = array(
 138+ "(cl_from = $encFrom AND cl_to > $encTo) " .
 139+ " OR cl_from > $encFrom" );
 140+ }
 141+
122142 $count += $res->numRows();
123143 $this->output( "$count done.\n" );
124144 } while ( $res->numRows() == self::BATCH_SIZE );

Follow-up revisions

RevisionCommit summaryAuthorDate
r806781.17: MFT category collation changes: r80432, r80443, r80590, r80614, r80615,...catrope03:16, 21 January 2011

Comments

#Comment by Catrope (talk | contribs)   01:17, 21 January 2011
+			$collationConds = array( 0 => 
+				'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ) );

array( 0 => foo ) is kinda silly.

#Comment by Tim Starling (talk | contribs)   01:24, 21 January 2011

I added it for a reason and then deleted the reason before commit.

Status & tagging log