MediaWiki  REL1_31
JobSpecification.php
Go to the documentation of this file.
1 <?php
29 interface IJobSpecification {
33  public function getType();
34 
38  public function getParams();
39 
43  public function getReleaseTimestamp();
44 
48  public function ignoreDuplicates();
49 
58  public function getDeduplicationInfo();
59 
65  public function getRootJobParams();
66 
72  public function hasRootJobParams();
73 
78  public function isRootJob();
79 
83  public function getTitle();
84 }
85 
105  protected $type;
106 
108  protected $params;
109 
111  protected $title;
112 
114  protected $opts;
115 
122  public function __construct(
123  $type, array $params, array $opts = [], Title $title = null
124  ) {
125  $this->validateParams( $params );
126  $this->validateParams( $opts );
127 
128  $this->type = $type;
129  $this->params = $params;
130  $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . static::class );
131  $this->opts = $opts;
132  }
133 
137  protected function validateParams( array $params ) {
138  foreach ( $params as $p => $v ) {
139  if ( is_array( $v ) ) {
140  $this->validateParams( $v );
141  } elseif ( !is_scalar( $v ) && $v !== null ) {
142  throw new UnexpectedValueException( "Job parameter $p is not JSON serializable." );
143  }
144  }
145  }
146 
147  public function getType() {
148  return $this->type;
149  }
150 
151  public function getTitle() {
152  return $this->title;
153  }
154 
155  public function getParams() {
156  return $this->params;
157  }
158 
159  public function getReleaseTimestamp() {
160  return isset( $this->params['jobReleaseTimestamp'] )
161  ? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
162  : null;
163  }
164 
165  public function ignoreDuplicates() {
166  return !empty( $this->opts['removeDuplicates'] );
167  }
168 
169  public function getDeduplicationInfo() {
170  $info = [
171  'type' => $this->getType(),
172  'namespace' => $this->getTitle()->getNamespace(),
173  'title' => $this->getTitle()->getDBkey(),
174  'params' => $this->getParams()
175  ];
176  if ( is_array( $info['params'] ) ) {
177  // Identical jobs with different "root" jobs should count as duplicates
178  unset( $info['params']['rootJobSignature'] );
179  unset( $info['params']['rootJobTimestamp'] );
180  // Likewise for jobs with different delay times
181  unset( $info['params']['jobReleaseTimestamp'] );
182  }
183 
184  return $info;
185  }
186 
187  public function getRootJobParams() {
188  return [
189  'rootJobSignature' => isset( $this->params['rootJobSignature'] )
190  ? $this->params['rootJobSignature']
191  : null,
192  'rootJobTimestamp' => isset( $this->params['rootJobTimestamp'] )
193  ? $this->params['rootJobTimestamp']
194  : null
195  ];
196  }
197 
198  public function hasRootJobParams() {
199  return isset( $this->params['rootJobSignature'] )
200  && isset( $this->params['rootJobTimestamp'] );
201  }
202 
203  public function isRootJob() {
204  return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
205  }
206 
211  public function toSerializableArray() {
212  return [
213  'type' => $this->type,
214  'params' => $this->params,
215  'opts' => $this->opts,
216  'title' => [
217  'ns' => $this->title->getNamespace(),
218  'key' => $this->title->getDBkey()
219  ]
220  ];
221  }
222 
228  public static function newFromArray( array $map ) {
229  $title = Title::makeTitle( $map['title']['ns'], $map['title']['key'] );
230 
231  return new self( $map['type'], $map['params'], $map['opts'], $title );
232  }
233 }
JobSpecification\__construct
__construct( $type, array $params, array $opts=[], Title $title=null)
Definition: JobSpecification.php:122
JobSpecification\toSerializableArray
toSerializableArray()
Definition: JobSpecification.php:211
type
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition: postgres.txt:30
JobSpecification\getTitle
getTitle()
Definition: JobSpecification.php:151
IJobSpecification\hasRootJobParams
hasRootJobParams()
array
the array() calling protocol came about after MediaWiki 1.4rc1.
JobSpecification\newFromArray
static newFromArray(array $map)
Definition: JobSpecification.php:228
JobSpecification\$opts
array $opts
Definition: JobSpecification.php:114
IJobSpecification\getTitle
getTitle()
IJobSpecification\getRootJobParams
getRootJobParams()
JobSpecification\getType
getType()
Definition: JobSpecification.php:147
JobSpecification\getReleaseTimestamp
getReleaseTimestamp()
Definition: JobSpecification.php:159
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
JobSpecification\isRootJob
isRootJob()
Definition: JobSpecification.php:203
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:63
IJobSpecification\getType
getType()
wfTimestampOrNull
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
Definition: GlobalFunctions.php:1996
title
title
Definition: parserTests.txt:219
IJobSpecification\getReleaseTimestamp
getReleaseTimestamp()
JobSpecification\ignoreDuplicates
ignoreDuplicates()
Definition: JobSpecification.php:165
JobSpecification\getParams
getParams()
Definition: JobSpecification.php:155
IJobSpecification\getParams
getParams()
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:534
JobSpecification\$params
array $params
Array of job parameters or false if none.
Definition: JobSpecification.php:108
IJobSpecification\getDeduplicationInfo
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
JobSpecification\validateParams
validateParams(array $params)
Definition: JobSpecification.php:137
JobSpecification\getRootJobParams
getRootJobParams()
Definition: JobSpecification.php:187
JobSpecification\hasRootJobParams
hasRootJobParams()
Definition: JobSpecification.php:198
Title
Represents a title within MediaWiki.
Definition: Title.php:39
JobSpecification\$type
string $type
Definition: JobSpecification.php:105
JobSpecification
Job queue task description base code.
Definition: JobSpecification.php:103
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:22
IJobSpecification\ignoreDuplicates
ignoreDuplicates()
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
JobSpecification\$title
Title $title
Definition: JobSpecification.php:111
JobSpecification\getDeduplicationInfo
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
Definition: JobSpecification.php:169
IJobSpecification
Job queue task description interface.
Definition: JobSpecification.php:29
IJobSpecification\isRootJob
isRootJob()