Index: trunk/phase3/maintenance/updateCollation.php |
— | — | @@ -42,39 +42,51 @@ |
43 | 43 | up-to-date, it will do nothing. |
44 | 44 | TEXT; |
45 | 45 | |
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.' ); |
47 | 48 | } |
48 | 49 | |
49 | 50 | public function execute() { |
50 | 51 | global $wgCategoryCollation; |
51 | 52 | |
52 | 53 | $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' ); |
59 | 55 | |
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" ); |
63 | 77 | } |
64 | | - $this->output( "Fixing collation for $count rows.\n" ); |
65 | 78 | |
66 | 79 | $count = 0; |
| 80 | + $row = false; |
| 81 | + $batchConds = array(); |
67 | 82 | do { |
68 | 83 | $res = $dbw->select( |
69 | 84 | array( 'categorylinks', 'page' ), |
70 | 85 | array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation', |
71 | 86 | 'cl_sortkey', 'page_namespace', 'page_title' |
72 | 87 | ), |
73 | | - array( |
74 | | - 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ), |
75 | | - 'cl_from = page_id' |
76 | | - ), |
| 88 | + array_merge( $collationConds, $batchConds, array( 'cl_from = page_id' ) ), |
77 | 89 | __METHOD__, |
78 | | - array( 'LIMIT' => self::BATCH_SIZE ) |
| 90 | + $options |
79 | 91 | ); |
80 | 92 | |
81 | 93 | $dbw->begin(); |
— | — | @@ -118,6 +130,14 @@ |
119 | 131 | } |
120 | 132 | $dbw->commit(); |
121 | 133 | |
| 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 | + |
122 | 142 | $count += $res->numRows(); |
123 | 143 | $this->output( "$count done.\n" ); |
124 | 144 | } while ( $res->numRows() == self::BATCH_SIZE ); |