r37185 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37184‎ | r37185 | r37186 >
Date:17:19, 6 July 2008
Author:nicdumz
Status:old
Tags:
Comment:
In fact we need to match both cl_inline and cl_target for one particular move, updating the Job.
This Job should now be working.
Modified paths:
  • /branches/category-redirects/includes/CategoryMove.php (modified) (history)

Diff [purge]

Index: branches/category-redirects/includes/CategoryMove.php
@@ -8,36 +8,52 @@
99 {
1010 public $mTitle;
1111 public $mRowsPerJob, $mRowsPerQuery;
12 - public $mFromID, $mToID;
 12+ public $mFromTarget, $mFromInline, $mToTargetID;
1313
1414 /**
15 - * Moving a category from cat_id $fromID to cat_id $toID
 15+ * Moving a category from ($fromInline, $fromTarget) to cl_target $toTargetID
1616 *
1717 * @param Title $title cat_title (unused, needed for Job::factory)
18 - * @param int $fromID
 18+ * @param int $fromInline
 19+ * @param int $fromTarget
1920 * @param int $toID
2021 */
21 - function __construct( $title, $fromID, $toID ) {
 22+ function __construct( $title, $fromInline, $fromTarget, $toTargetID ) {
2223 global $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery;
2324
2425 $this->mTitle = $title;
25 - $this->mFromID = $fromID;
26 - $this->mToID = $toID;
 26+ $this->mFromTarget = $fromTarget;
 27+ $this->mFromInline = $fromInline;
 28+ $this->mToTargetID = $toTargetID;
2729 $this->mRowsPerJob = $wgUpdateRowsPerJob;
2830 $this->mRowsPerQuery = $wgUpdateRowsPerQuery;
2931 }
3032
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() ) {
3340 $dbr = wfGetDB( DB_SLAVE );
 41+
 42+ $conds['cl_target'] = $this->mFromTarget;
 43+ $conds['cl_inline'] = $this->mFromInline;
 44+
3445 $res = $dbr->select( 'categorylinks',
3546 'cl_from',
36 - array( 'cl_target' => $this->mFromID ),
 47+ $conds,
3748 __METHOD__
3849 );
 50+ return $res;
 51+ }
 52+
 53+ function doUpdate() {
 54+ $res = $this->fetchIDs();
3955
40 - if ( $dbr->numRows( $res ) != 0 ) {
41 - if ( $dbr->numRows( $res ) > $this->mRowsPerJob ) {
 56+ if ( $res->numRows() != 0 ) {
 57+ if ( $res->numRows() > $this->mRowsPerJob ) {
4258 $this->insertJobs( $res );
4359 } else {
4460 $this->updateIDs( $res );
@@ -45,6 +61,12 @@
4662 }
4763 }
4864
 65+ /**
 66+ * Splits the ids into smaller queries and put them
 67+ * into JobQueue
 68+ *
 69+ * @param ResultWrapper $res
 70+ */
4971 function insertJobs( ResultWrapper $res ) {
5072 $numRows = $res->numRows();
5173 $numBatches = ceil( $numRows / $this->mRowsPerJob );
@@ -65,6 +87,9 @@
6688 $params = array(
6789 'start' => $start,
6890 'end' => ( $id !== false ? $id - 1 : false ),
 91+ 'inline' => $this->mFromInline,
 92+ 'target' => $this->mFromTarget,
 93+ 'to' => $this->mToTargetID
6994 );
7095 $jobs[] = new CategoryMoveJob( $this->mTitle, $params );
7196
@@ -104,7 +129,7 @@
105130 }
106131
107132 $dbw->update( 'categorylinks',
108 - array( 'cl_target' => $this->mToID ),
 133+ array( 'cl_target' => $this->mToTargetID ),
109134 array( 'cl_from' => $ids ),
110135 __METHOD__
111136 );
@@ -119,6 +144,7 @@
120145 */
121146 class CategoryMoveJob extends Job {
122147 public $start, $end;
 148+ public $inline, $target, $to;
123149
124150 /**
125151 * Construct a job
@@ -128,15 +154,16 @@
129155 */
130156 function __construct( $title, $params, $id = 0 ) {
131157 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+ }
134162 }
135163
136164 function run() {
137 - $update = new HTMLCacheUpdate( $this->title, $this->table );
 165+ $update = new CategoryMove( $this->title, $this->inline, $this->target, $this->to );
138166
139 - $fromField = $update->getFromField();
140 - $conds = $update->getToCondition();
 167+ $conds = array();
141168 if ( $this->start ) {
142169 $conds[] = "$fromField >= {$this->start}";
143170 }
@@ -144,8 +171,7 @@
145172 $conds[] = "$fromField <= {$this->end}";
146173 }
147174
148 - $dbr = wfGetDB( DB_SLAVE );
149 - $res = $dbr->select( $tables, $fromField, $conds, __METHOD__ );
 175+ $res = $update->fetchIDs( $conds );
150176 $update->updateIDs( $res );
151177
152178 return true;

Status & tagging log