MediaWiki REL1_28
JobSpecification.php
Go to the documentation of this file.
1<?php
34 public function getType();
35
39 public function getParams();
40
44 public function getReleaseTimestamp();
45
49 public function ignoreDuplicates();
50
59 public function getDeduplicationInfo();
60
66 public function getRootJobParams();
67
73 public function hasRootJobParams();
74
79 public function isRootJob();
80
84 public function getTitle();
85}
86
106 protected $type;
107
109 protected $params;
110
112 protected $title;
113
115 protected $opts;
116
123 public function __construct(
124 $type, array $params, array $opts = [], Title $title = null
125 ) {
126 $this->validateParams( $params );
127 $this->validateParams( $opts );
128
129 $this->type = $type;
130 $this->params = $params;
131 $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . get_class( $this ) );
132 $this->opts = $opts;
133 }
134
138 protected function validateParams( array $params ) {
139 foreach ( $params as $p => $v ) {
140 if ( is_array( $v ) ) {
141 $this->validateParams( $v );
142 } elseif ( !is_scalar( $v ) && $v !== null ) {
143 throw new UnexpectedValueException( "Job parameter $p is not JSON serializable." );
144 }
145 }
146 }
147
148 public function getType() {
149 return $this->type;
150 }
151
152 public function getTitle() {
153 return $this->title;
154 }
155
156 public function getParams() {
157 return $this->params;
158 }
159
160 public function getReleaseTimestamp() {
161 return isset( $this->params['jobReleaseTimestamp'] )
162 ? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
163 : null;
164 }
165
166 public function ignoreDuplicates() {
167 return !empty( $this->opts['removeDuplicates'] );
168 }
169
170 public function getDeduplicationInfo() {
171 $info = [
172 'type' => $this->getType(),
173 'namespace' => $this->getTitle()->getNamespace(),
174 'title' => $this->getTitle()->getDBkey(),
175 'params' => $this->getParams()
176 ];
177 if ( is_array( $info['params'] ) ) {
178 // Identical jobs with different "root" jobs should count as duplicates
179 unset( $info['params']['rootJobSignature'] );
180 unset( $info['params']['rootJobTimestamp'] );
181 // Likewise for jobs with different delay times
182 unset( $info['params']['jobReleaseTimestamp'] );
183 }
184
185 return $info;
186 }
187
188 public function getRootJobParams() {
189 return [
190 'rootJobSignature' => isset( $this->params['rootJobSignature'] )
191 ? $this->params['rootJobSignature']
192 : null,
193 'rootJobTimestamp' => isset( $this->params['rootJobTimestamp'] )
194 ? $this->params['rootJobTimestamp']
195 : null
196 ];
197 }
198
199 public function hasRootJobParams() {
200 return isset( $this->params['rootJobSignature'] )
201 && isset( $this->params['rootJobTimestamp'] );
202 }
203
204 public function isRootJob() {
205 return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
206 }
207
212 public function toSerializableArray() {
213 return [
214 'type' => $this->type,
215 'params' => $this->params,
216 'opts' => $this->opts,
217 'title' => [
218 'ns' => $this->title->getNamespace(),
219 'key' => $this->title->getDBkey()
220 ]
221 ];
222 }
223
229 public static function newFromArray( array $map ) {
230 $title = Title::makeTitle( $map['title']['ns'], $map['title']['key'] );
231
232 return new self( $map['type'], $map['params'], $map['opts'], $title );
233 }
234}
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
Job queue task description base code.
array $params
Array of job parameters or false if none.
__construct( $type, array $params, array $opts=[], Title $title=null)
validateParams(array $params)
static newFromArray(array $map)
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
Represents a title within MediaWiki.
Definition Title.php:36
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
const NS_SPECIAL
Definition Defines.php:45
the array() calling protocol came about after MediaWiki 1.4rc1.
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
Job queue task description interface.
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
title
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 as and are nearing end of 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:36
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition defines.php:6