Merge "Stop using the unholy trinity in DatabaseError"
[lhc/web/wiklou.git] / includes / job / JobQueueDB.php
index b795695..e7a269a 100644 (file)
@@ -324,7 +324,6 @@ class JobQueueDB extends JobQueue {
                                $job = Job::factory( $row->job_cmd, $title,
                                        self::extractBlob( $row->job_params ), $row->job_id );
                                $job->metadata['id'] = $row->job_id;
-                               $job->id = $row->job_id; // XXX: work around broken subclasses
                                break; // done
                        } while ( true );
                } catch ( DBError $e ) {
@@ -359,7 +358,7 @@ class JobQueueDB extends JobQueue {
                                // Instead, this uses job_random to pick a row (possibly checking both directions).
                                $ineq = $gte ? '>=' : '<=';
                                $dir = $gte ? 'ASC' : 'DESC';
-                               $row = $dbw->selectRow( 'job', '*', // find a random job
+                               $row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
                                        array(
                                                'job_cmd' => $this->type,
                                                'job_token' => '', // unclaimed
@@ -376,7 +375,7 @@ class JobQueueDB extends JobQueue {
                                // Bug 42614: "ORDER BY job_random" with a job_random inequality causes high CPU
                                // in MySQL if there are many rows for some reason. This uses a small OFFSET
                                // instead of job_random for reducing excess claim retries.
-                               $row = $dbw->selectRow( 'job', '*', // find a random job
+                               $row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
                                        array(
                                                'job_cmd' => $this->type,
                                                'job_token' => '', // unclaimed
@@ -460,7 +459,7 @@ class JobQueueDB extends JobQueue {
                        }
                        // Fetch any row that we just reserved...
                        if ( $dbw->affectedRows() ) {
-                               $row = $dbw->selectRow( 'job', '*',
+                               $row = $dbw->selectRow( 'job', self::selectFields(),
                                        array( 'job_cmd' => $this->type, 'job_token' => $uuid ), __METHOD__
                                );
                                if ( !$row ) { // raced out by duplicate job removal
@@ -590,17 +589,15 @@ class JobQueueDB extends JobQueue {
                $dbr = $this->getSlaveDB();
                try {
                        return new MappedIterator(
-                               $dbr->select( 'job', '*',
+                               $dbr->select( 'job', self::selectFields(),
                                        array( 'job_cmd' => $this->getType(), 'job_token' => '' ) ),
                                function ( $row ) use ( $dbr ) {
                                        $job = Job::factory(
                                                $row->job_cmd,
                                                Title::makeTitle( $row->job_namespace, $row->job_title ),
-                                               strlen( $row->job_params ) ? unserialize( $row->job_params ) : false,
-                                               $row->job_id
+                                               strlen( $row->job_params ) ? unserialize( $row->job_params ) : false
                                        );
                                        $job->metadata['id'] = $row->job_id;
-                                       $job->id = $row->job_id; // XXX: work around broken subclasses
                                        return $job;
                                }
                        );
@@ -827,4 +824,25 @@ class JobQueueDB extends JobQueue {
        protected function throwDBException( DBError $e ) {
                throw new JobQueueError( get_class( $e ) . ": " . $e->getMessage() );
        }
+
+       /**
+        * Return the list of job fields that should be selected.
+        * @since 1.23
+        * @return array
+        */
+       public static function selectFields() {
+               return array(
+                       'job_id',
+                       'job_cmd',
+                       'job_namespace',
+                       'job_title',
+                       'job_timestamp',
+                       'job_params',
+                       'job_random',
+                       'job_attempts',
+                       'job_token',
+                       'job_token_timestamp',
+                       'job_sha1',
+               );
+       }
 }