Index: branches/category-redirects/includes/CategoryMove.php |
— | — | @@ -8,36 +8,52 @@ |
9 | 9 | { |
10 | 10 | public $mTitle; |
11 | 11 | public $mRowsPerJob, $mRowsPerQuery; |
12 | | - public $mFromID, $mToID; |
| 12 | + public $mFromTarget, $mFromInline, $mToTargetID; |
13 | 13 | |
14 | 14 | /** |
15 | | - * Moving a category from cat_id $fromID to cat_id $toID |
| 15 | + * Moving a category from ($fromInline, $fromTarget) to cl_target $toTargetID |
16 | 16 | * |
17 | 17 | * @param Title $title cat_title (unused, needed for Job::factory) |
18 | | - * @param int $fromID |
| 18 | + * @param int $fromInline |
| 19 | + * @param int $fromTarget |
19 | 20 | * @param int $toID |
20 | 21 | */ |
21 | | - function __construct( $title, $fromID, $toID ) { |
| 22 | + function __construct( $title, $fromInline, $fromTarget, $toTargetID ) { |
22 | 23 | global $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery; |
23 | 24 | |
24 | 25 | $this->mTitle = $title; |
25 | | - $this->mFromID = $fromID; |
26 | | - $this->mToID = $toID; |
| 26 | + $this->mFromTarget = $fromTarget; |
| 27 | + $this->mFromInline = $fromInline; |
| 28 | + $this->mToTargetID = $toTargetID; |
27 | 29 | $this->mRowsPerJob = $wgUpdateRowsPerJob; |
28 | 30 | $this->mRowsPerQuery = $wgUpdateRowsPerQuery; |
29 | 31 | } |
30 | 32 | |
31 | | - function doUpdate() { |
32 | | - # Fetch the IDs |
| 33 | + /** |
| 34 | + * Returns the cl_from ids that need to be changed |
| 35 | + * |
| 36 | + * @param Array $conds additional 'where' conditions |
| 37 | + * @return ResultWrapper |
| 38 | + */ |
| 39 | + function fetchIDs( $conds = array() ) { |
33 | 40 | $dbr = wfGetDB( DB_SLAVE ); |
| 41 | + |
| 42 | + $conds['cl_target'] = $this->mFromTarget; |
| 43 | + $conds['cl_inline'] = $this->mFromInline; |
| 44 | + |
34 | 45 | $res = $dbr->select( 'categorylinks', |
35 | 46 | 'cl_from', |
36 | | - array( 'cl_target' => $this->mFromID ), |
| 47 | + $conds, |
37 | 48 | __METHOD__ |
38 | 49 | ); |
| 50 | + return $res; |
| 51 | + } |
| 52 | + |
| 53 | + function doUpdate() { |
| 54 | + $res = $this->fetchIDs(); |
39 | 55 | |
40 | | - if ( $dbr->numRows( $res ) != 0 ) { |
41 | | - if ( $dbr->numRows( $res ) > $this->mRowsPerJob ) { |
| 56 | + if ( $res->numRows() != 0 ) { |
| 57 | + if ( $res->numRows() > $this->mRowsPerJob ) { |
42 | 58 | $this->insertJobs( $res ); |
43 | 59 | } else { |
44 | 60 | $this->updateIDs( $res ); |
— | — | @@ -45,6 +61,12 @@ |
46 | 62 | } |
47 | 63 | } |
48 | 64 | |
| 65 | + /** |
| 66 | + * Splits the ids into smaller queries and put them |
| 67 | + * into JobQueue |
| 68 | + * |
| 69 | + * @param ResultWrapper $res |
| 70 | + */ |
49 | 71 | function insertJobs( ResultWrapper $res ) { |
50 | 72 | $numRows = $res->numRows(); |
51 | 73 | $numBatches = ceil( $numRows / $this->mRowsPerJob ); |
— | — | @@ -65,6 +87,9 @@ |
66 | 88 | $params = array( |
67 | 89 | 'start' => $start, |
68 | 90 | 'end' => ( $id !== false ? $id - 1 : false ), |
| 91 | + 'inline' => $this->mFromInline, |
| 92 | + 'target' => $this->mFromTarget, |
| 93 | + 'to' => $this->mToTargetID |
69 | 94 | ); |
70 | 95 | $jobs[] = new CategoryMoveJob( $this->mTitle, $params ); |
71 | 96 | |
— | — | @@ -104,7 +129,7 @@ |
105 | 130 | } |
106 | 131 | |
107 | 132 | $dbw->update( 'categorylinks', |
108 | | - array( 'cl_target' => $this->mToID ), |
| 133 | + array( 'cl_target' => $this->mToTargetID ), |
109 | 134 | array( 'cl_from' => $ids ), |
110 | 135 | __METHOD__ |
111 | 136 | ); |
— | — | @@ -119,6 +144,7 @@ |
120 | 145 | */ |
121 | 146 | class CategoryMoveJob extends Job { |
122 | 147 | public $start, $end; |
| 148 | + public $inline, $target, $to; |
123 | 149 | |
124 | 150 | /** |
125 | 151 | * Construct a job |
— | — | @@ -128,15 +154,16 @@ |
129 | 155 | */ |
130 | 156 | function __construct( $title, $params, $id = 0 ) { |
131 | 157 | parent::__construct( 'categoryMoveJob', $title, $params, $id ); |
132 | | - $this->start = $params['start']; |
133 | | - $this->end = $params['end']; |
| 158 | + |
| 159 | + foreach ($params as $name => $value ) { |
| 160 | + $this->{$name} = $value; |
| 161 | + } |
134 | 162 | } |
135 | 163 | |
136 | 164 | function run() { |
137 | | - $update = new HTMLCacheUpdate( $this->title, $this->table ); |
| 165 | + $update = new CategoryMove( $this->title, $this->inline, $this->target, $this->to ); |
138 | 166 | |
139 | | - $fromField = $update->getFromField(); |
140 | | - $conds = $update->getToCondition(); |
| 167 | + $conds = array(); |
141 | 168 | if ( $this->start ) { |
142 | 169 | $conds[] = "$fromField >= {$this->start}"; |
143 | 170 | } |
— | — | @@ -144,8 +171,7 @@ |
145 | 172 | $conds[] = "$fromField <= {$this->end}"; |
146 | 173 | } |
147 | 174 | |
148 | | - $dbr = wfGetDB( DB_SLAVE ); |
149 | | - $res = $dbr->select( $tables, $fromField, $conds, __METHOD__ ); |
| 175 | + $res = $update->fetchIDs( $conds ); |
150 | 176 | $update->updateIDs( $res ); |
151 | 177 | |
152 | 178 | return true; |