MediaWiki  master
JobSpecification.php
Go to the documentation of this file.
1 <?php
41  protected $type;
42 
44  protected $params;
45 
47  protected $title;
48 
50  protected $opts;
51 
58  public function __construct(
59  $type, array $params, array $opts = [], Title $title = null
60  ) {
61  $this->validateParams( $params );
62  $this->validateParams( $opts );
63 
64  $this->type = $type;
65  if ( $title instanceof Title ) {
66  // Make sure JobQueue classes can pull the title from parameters alone
67  if ( $title->getDBkey() !== '' ) {
68  $params += [
69  'namespace' => $title->getNamespace(),
70  'title' => $title->getDBkey()
71  ];
72  }
73  } else {
75  }
76  $this->params = $params;
77  $this->title = $title;
78  $this->opts = $opts;
79  }
80 
84  protected function validateParams( array $params ) {
85  foreach ( $params as $p => $v ) {
86  if ( is_array( $v ) ) {
87  $this->validateParams( $v );
88  } elseif ( !is_scalar( $v ) && $v !== null ) {
89  throw new UnexpectedValueException( "Job parameter $p is not JSON serializable." );
90  }
91  }
92  }
93 
94  public function getType() {
95  return $this->type;
96  }
97 
98  public function getTitle() {
99  return $this->title;
100  }
101 
102  public function getParams() {
103  return $this->params;
104  }
105 
106  public function getReleaseTimestamp() {
107  return isset( $this->params['jobReleaseTimestamp'] )
108  ? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
109  : null;
110  }
111 
112  public function ignoreDuplicates() {
113  return !empty( $this->opts['removeDuplicates'] );
114  }
115 
116  public function getDeduplicationInfo() {
117  $info = [
118  'type' => $this->getType(),
119  'namespace' => $this->getTitle()->getNamespace(),
120  'title' => $this->getTitle()->getDBkey(),
121  'params' => $this->getParams()
122  ];
123  if ( is_array( $info['params'] ) ) {
124  // Identical jobs with different "root" jobs should count as duplicates
125  unset( $info['params']['rootJobSignature'] );
126  unset( $info['params']['rootJobTimestamp'] );
127  // Likewise for jobs with different delay times
128  unset( $info['params']['jobReleaseTimestamp'] );
129  }
130 
131  return $info;
132  }
133 
134  public function getRootJobParams() {
135  return [
136  'rootJobSignature' => $this->params['rootJobSignature'] ?? null,
137  'rootJobTimestamp' => $this->params['rootJobTimestamp'] ?? null
138  ];
139  }
140 
141  public function hasRootJobParams() {
142  return isset( $this->params['rootJobSignature'] )
143  && isset( $this->params['rootJobTimestamp'] );
144  }
145 
146  public function isRootJob() {
147  return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
148  }
149 
154  public function toSerializableArray() {
155  return [
156  'type' => $this->type,
157  'params' => $this->params,
158  'opts' => $this->opts,
159  'title' => [
160  'ns' => $this->title->getNamespace(),
161  'key' => $this->title->getDBkey()
162  ]
163  ];
164  }
165 
171  public static function newFromArray( array $map ) {
172  $title = Title::makeTitle( $map['title']['ns'], $map['title']['key'] );
173 
174  return new self( $map['type'], $map['params'], $map['opts'], $title );
175  }
176 }
validateParams(array $params)
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
const NS_SPECIAL
Definition: Defines.php:49
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
title
getDBkey()
Get the main part with underscores.
Definition: Title.php:1019
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:767
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1043
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
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:590
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
__construct( $type, array $params, array $opts=[], Title $title=null)
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
array $params
Array of job parameters or false if none.
Interface for serializable objects that describe a job queue task.
static newFromArray(array $map)
Job queue task description base code.