MediaWiki  1.23.2
Job.php
Go to the documentation of this file.
1 <?php
31 abstract class Job implements IJobSpecification {
33  public $command;
34 
36  public $params;
37 
39  public $metadata = array();
40 
42  protected $title;
43 
45  protected $removeDuplicates;
46 
48  protected $error;
49 
50  /*-------------------------------------------------------------------------
51  * Abstract functions
52  *------------------------------------------------------------------------*/
53 
58  abstract public function run();
59 
60  /*-------------------------------------------------------------------------
61  * Static functions
62  *------------------------------------------------------------------------*/
63 
73  public static function factory( $command, Title $title, $params = false ) {
74  global $wgJobClasses;
75  if ( isset( $wgJobClasses[$command] ) ) {
76  $class = $wgJobClasses[$command];
77 
78  return new $class( $title, $params );
79  }
80  throw new MWException( "Invalid job command `{$command}`" );
81  }
82 
94  public static function batchInsert( $jobs ) {
95  return JobQueueGroup::singleton()->push( $jobs );
96  }
97 
109  public static function safeBatchInsert( $jobs ) {
110  return JobQueueGroup::singleton()->push( $jobs, JobQueue::QOS_ATOMIC );
111  }
112 
122  public static function pop_type( $type ) {
123  return JobQueueGroup::singleton()->get( $type )->pop();
124  }
125 
133  public static function pop() {
134  return JobQueueGroup::singleton()->pop();
135  }
136 
137  /*-------------------------------------------------------------------------
138  * Non-static functions
139  *------------------------------------------------------------------------*/
140 
146  public function __construct( $command, $title, $params = false ) {
147  $this->command = $command;
148  $this->title = $title;
149  $this->params = $params;
150 
151  // expensive jobs may set this to true
152  $this->removeDuplicates = false;
153  }
154 
158  public function getType() {
160  }
161 
165  public function getTitle() {
166  return $this->title;
167  }
168 
172  public function getParams() {
173  return $this->params;
174  }
175 
180  public function getReleaseTimestamp() {
181  return isset( $this->params['jobReleaseTimestamp'] )
182  ? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
183  : null;
184  }
185 
189  public function ignoreDuplicates() {
191  }
192 
197  public function allowRetries() {
198  return true;
199  }
200 
206  public function workItemCount() {
207  return 1;
208  }
209 
219  public function getDeduplicationInfo() {
220  $info = array(
221  'type' => $this->getType(),
222  'namespace' => $this->getTitle()->getNamespace(),
223  'title' => $this->getTitle()->getDBkey(),
224  'params' => $this->getParams()
225  );
226  if ( is_array( $info['params'] ) ) {
227  // Identical jobs with different "root" jobs should count as duplicates
228  unset( $info['params']['rootJobSignature'] );
229  unset( $info['params']['rootJobTimestamp'] );
230  // Likewise for jobs with different delay times
231  unset( $info['params']['jobReleaseTimestamp'] );
232  }
233 
234  return $info;
235  }
236 
245  public static function newRootJobParams( $key ) {
246  return array(
247  'rootJobSignature' => sha1( $key ),
248  'rootJobTimestamp' => wfTimestampNow()
249  );
250  }
251 
257  public function getRootJobParams() {
258  return array(
259  'rootJobSignature' => isset( $this->params['rootJobSignature'] )
260  ? $this->params['rootJobSignature']
261  : null,
262  'rootJobTimestamp' => isset( $this->params['rootJobTimestamp'] )
263  ? $this->params['rootJobTimestamp']
264  : null
265  );
266  }
267 
273  public function hasRootJobParams() {
274  return isset( $this->params['rootJobSignature'] )
275  && isset( $this->params['rootJobTimestamp'] );
276  }
277 
283  public function insert() {
284  return JobQueueGroup::singleton()->push( $this );
285  }
286 
290  public function toString() {
291  $paramString = '';
292  if ( $this->params ) {
293  foreach ( $this->params as $key => $value ) {
294  if ( $paramString != '' ) {
295  $paramString .= ' ';
296  }
297  if ( is_array( $value ) ) {
298  $value = "array(" . count( $value ) . ")";
299  } elseif ( is_object( $value ) && !method_exists( $value, '__toString' ) ) {
300  $value = "object(" . get_class( $value ) . ")";
301  }
302  $value = (string)$value;
303  if ( mb_strlen( $value ) > 1024 ) {
304  $value = "string(" . mb_strlen( $value ) . ")";
305  }
306 
307  $paramString .= "$key=$value";
308  }
309  }
310 
311  if ( is_object( $this->title ) ) {
312  $s = "{$this->command} " . $this->title->getPrefixedDBkey();
313  if ( $paramString !== '' ) {
314  $s .= ' ' . $paramString;
315  }
316 
317  return $s;
318  } else {
319  return "{$this->command} $paramString";
320  }
321  }
322 
323  protected function setLastError( $error ) {
324  $this->error = $error;
325  }
326 
327  public function getLastError() {
328  return $this->error;
329  }
330 }
Job\getRootJobParams
getRootJobParams()
Definition: Job.php:251
Job\getReleaseTimestamp
getReleaseTimestamp()
Definition: Job.php:174
Job\getType
getType()
Definition: Job.php:152
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Job\getParams
getParams()
Definition: Job.php:166
Job\toString
toString()
Definition: Job.php:284
Job\workItemCount
workItemCount()
Definition: Job.php:200
Job\$title
Title $title
Definition: Job.php:38
$s
$s
Definition: mergeMessageFileList.php:156
Job\setLastError
setLastError( $error)
Definition: Job.php:317
Job\ignoreDuplicates
ignoreDuplicates()
Definition: Job.php:183
Job\getTitle
getTitle()
Definition: Job.php:159
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
Job\pop_type
static pop_type( $type)
Pop a job of a certain type.
Definition: Job.php:116
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:31
Job\run
run()
Run the job.
Job\$error
string $error
Text for error that occurred last *.
Definition: Job.php:42
MWException
MediaWiki exception.
Definition: MWException.php:26
Job\$command
string $command
Definition: Job.php:32
wfTimestampOrNull
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
Definition: GlobalFunctions.php:2501
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Job\$metadata
array $metadata
Additional queue metadata *.
Definition: Job.php:36
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2514
Job\newRootJobParams
static newRootJobParams( $key)
Definition: Job.php:239
Job\allowRetries
allowRetries()
Definition: Job.php:191
$value
$value
Definition: styleTest.css.php:45
Job\$params
array bool $params
Array of job parameters or false if none *.
Definition: Job.php:34
Job\batchInsert
static batchInsert( $jobs)
Batch-insert a group of jobs into the queue.
Definition: Job.php:88
Job\factory
static factory( $command, Title $title, $params=false)
Create the appropriate object to handle a specific job.
Definition: Job.php:67
Job\$removeDuplicates
bool $removeDuplicates
Expensive jobs may set this to true *.
Definition: Job.php:40
Job\getLastError
getLastError()
Definition: Job.php:321
Job\getDeduplicationInfo
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
Definition: Job.php:213
Job\safeBatchInsert
static safeBatchInsert( $jobs)
Insert a group of jobs into the queue.
Definition: Job.php:103
Title
Represents a title within MediaWiki.
Definition: Title.php:35
TS_UNIX
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: GlobalFunctions.php:2426
JobQueueGroup\singleton
static singleton( $wiki=false)
Definition: JobQueueGroup.php:61
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
JobQueue\QOS_ATOMIC
const QOS_ATOMIC
Definition: JobQueue.php:46
Job\hasRootJobParams
hasRootJobParams()
Definition: Job.php:267
Job\__construct
__construct( $command, $title, $params=false)
Definition: Job.php:140
Job\insert
insert()
Insert a single job into the queue.
Definition: Job.php:277
IJobSpecification
Job queue task description interface.
Definition: JobSpecification.php:30
Job\pop
static pop()
Pop a job off the front of the queue.
Definition: Job.php:127
$type
$type
Definition: testCompression.php:46