Add --force option to updateCollation.php.
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 20 Jan 2011 06:24:11 +0000 (06:24 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 20 Jan 2011 06:24:11 +0000 (06:24 +0000)
maintenance/updateCollation.php

index 5fdb0cf..2985add 100644 (file)
@@ -42,39 +42,51 @@ using the page title and cl_sortkey_prefix.  If everything's collation is
 up-to-date, it will do nothing.
 TEXT;
 
-               #$this->addOption( 'force', 'Run on all rows, even if the collation is supposed to be up-to-date.' );
+               $this->addOption( 'force', 'Run on all rows, even if the collation is ' . 
+                       'supposed to be up-to-date.' );
        }
 
        public function execute() {
                global $wgCategoryCollation;
 
                $dbw = wfGetDB( DB_MASTER );
-               $count = $dbw->selectField(
-                       'categorylinks',
-                       'COUNT(*)',
-                       'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
-                       __METHOD__
-               );
-
-               if ( $count == 0 ) {
-                       $this->output( "Collations up-to-date.\n" );
-                       return;
+               $force = $this->getOption( 'force' );
+
+               $options = array( 'LIMIT' => self::BATCH_SIZE );
+
+               if ( $force ) {
+                       $collationConds = array();
+                       $options['ORDER BY'] = 'cl_from, cl_to';
+               } else {
+                       $collationConds = array( 0 => 
+                               'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ) );
+
+                       $count = $dbw->selectField(
+                               'categorylinks',
+                               'COUNT(*)',
+                               $collationConds,
+                               __METHOD__
+                       );
+
+                       if ( $count == 0 ) {
+                               $this->output( "Collations up-to-date.\n" );
+                               return;
+                       }
+                       $this->output( "Fixing collation for $count rows.\n" );
                }
-               $this->output( "Fixing collation for $count rows.\n" );
 
                $count = 0;
+               $row = false;
+               $batchConds = array();
                do {
                        $res = $dbw->select(
                                array( 'categorylinks', 'page' ),
                                array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation',
                                        'cl_sortkey', 'page_namespace', 'page_title'
                                ),
-                               array(
-                                       'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
-                                       'cl_from = page_id'
-                               ),
+                               array_merge( $collationConds, $batchConds, array( 'cl_from = page_id' ) ),
                                __METHOD__,
-                               array( 'LIMIT' => self::BATCH_SIZE )
+                               $options
                        );
 
                        $dbw->begin();
@@ -118,6 +130,14 @@ TEXT;
                        }
                        $dbw->commit();
 
+                       if ( $force && $row ) {
+                               $encFrom = $dbw->addQuotes( $row->cl_from );
+                               $encTo = $dbw->addQuotes( $row->cl_to );
+                               $batchConds = array( 
+                                       "(cl_from = $encFrom AND cl_to > $encTo) " .
+                                       " OR cl_from > $encFrom" );
+                       }
+
                        $count += $res->numRows();
                        $this->output( "$count done.\n" );
                } while ( $res->numRows() == self::BATCH_SIZE );