MediaWiki  1.33.0
JobSpecification.php
Go to the documentation of this file.
1 <?php
42  protected $type;
43 
45  protected $params;
46 
48  protected $title;
49 
51  protected $opts;
52 
59  public function __construct(
60  $type, array $params, array $opts = [], Title $title = null
61  ) {
62  $this->validateParams( $params );
63  $this->validateParams( $opts );
64 
65  $this->type = $type;
66  $this->params = $params;
67  $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Blankpage' );
68  $this->opts = $opts;
69  }
70 
74  protected function validateParams( array $params ) {
75  foreach ( $params as $p => $v ) {
76  if ( is_array( $v ) ) {
77  $this->validateParams( $v );
78  } elseif ( !is_scalar( $v ) && $v !== null ) {
79  throw new UnexpectedValueException( "Job parameter $p is not JSON serializable." );
80  }
81  }
82  }
83 
84  public function getType() {
85  return $this->type;
86  }
87 
88  public function getTitle() {
89  return $this->title;
90  }
91 
92  public function getParams() {
93  return $this->params;
94  }
95 
96  public function getReleaseTimestamp() {
97  return isset( $this->params['jobReleaseTimestamp'] )
98  ? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
99  : null;
100  }
101 
102  public function ignoreDuplicates() {
103  return !empty( $this->opts['removeDuplicates'] );
104  }
105 
106  public function getDeduplicationInfo() {
107  $info = [
108  'type' => $this->getType(),
109  'namespace' => $this->getTitle()->getNamespace(),
110  'title' => $this->getTitle()->getDBkey(),
111  'params' => $this->getParams()
112  ];
113  if ( is_array( $info['params'] ) ) {
114  // Identical jobs with different "root" jobs should count as duplicates
115  unset( $info['params']['rootJobSignature'] );
116  unset( $info['params']['rootJobTimestamp'] );
117  // Likewise for jobs with different delay times
118  unset( $info['params']['jobReleaseTimestamp'] );
119  }
120 
121  return $info;
122  }
123 
124  public function getRootJobParams() {
125  return [
126  'rootJobSignature' => $this->params['rootJobSignature'] ?? null,
127  'rootJobTimestamp' => $this->params['rootJobTimestamp'] ?? null
128  ];
129  }
130 
131  public function hasRootJobParams() {
132  return isset( $this->params['rootJobSignature'] )
133  && isset( $this->params['rootJobTimestamp'] );
134  }
135 
136  public function isRootJob() {
137  return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
138  }
139 
144  public function toSerializableArray() {
145  return [
146  'type' => $this->type,
147  'params' => $this->params,
148  'opts' => $this->opts,
149  'title' => [
150  'ns' => $this->title->getNamespace(),
151  'key' => $this->title->getDBkey()
152  ]
153  ];
154  }
155 
161  public static function newFromArray( array $map ) {
162  $title = Title::makeTitle( $map['title']['ns'], $map['title']['key'] );
163 
164  return new self( $map['type'], $map['params'], $map['opts'], $title );
165  }
166 }
JobSpecification\__construct
__construct( $type, array $params, array $opts=[], Title $title=null)
Definition: JobSpecification.php:59
JobSpecification\toSerializableArray
toSerializableArray()
Definition: JobSpecification.php:144
JobSpecification\getTitle
getTitle()
Definition: JobSpecification.php:88
JobSpecification\newFromArray
static newFromArray(array $map)
Definition: JobSpecification.php:161
JobSpecification\$opts
array $opts
Definition: JobSpecification.php:51
JobSpecification\getType
getType()
Definition: JobSpecification.php:84
JobSpecification\getReleaseTimestamp
getReleaseTimestamp()
Definition: JobSpecification.php:96
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:35
JobSpecification\isRootJob
isRootJob()
Definition: JobSpecification.php:136
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
wfTimestampOrNull
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
Definition: GlobalFunctions.php:1928
JobSpecification\ignoreDuplicates
ignoreDuplicates()
Definition: JobSpecification.php:102
JobSpecification\getParams
getParams()
Definition: JobSpecification.php:92
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
JobSpecification\$params
array $params
Array of job parameters or false if none.
Definition: JobSpecification.php:45
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
captcha-old.opts
opts
Definition: captcha-old.py:227
title
title
Definition: parserTests.txt:245
JobSpecification\validateParams
validateParams(array $params)
Definition: JobSpecification.php:74
JobSpecification\getRootJobParams
getRootJobParams()
Definition: JobSpecification.php:124
JobSpecification\hasRootJobParams
hasRootJobParams()
Definition: JobSpecification.php:131
Title
Represents a title within MediaWiki.
Definition: Title.php:40
JobSpecification\$type
string $type
Definition: JobSpecification.php:42
JobSpecification
Job queue task description base code.
Definition: JobSpecification.php:40
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
JobSpecification\$title
Title $title
Definition: JobSpecification.php:48
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 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:22
JobSpecification\getDeduplicationInfo
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
Definition: JobSpecification.php:106
IJobSpecification
Job queue task description interface.
Definition: IJobSpecification.php:29