X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJobSpecification.php;h=d59c09b51054e4d749556069ed1ddf57e67dbde1;hb=64b83bdb3afd0ee4f8fc1893a865409c198e601e;hp=9ace1ba54e71b244e2a4efb92c02ae50a74ad87b;hpb=d864012f338917db791c234675ab7a5b427ade98;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/JobSpecification.php b/includes/jobqueue/JobSpecification.php index 9ace1ba54e..d844795143 100644 --- a/includes/jobqueue/JobSpecification.php +++ b/includes/jobqueue/JobSpecification.php @@ -58,6 +58,26 @@ interface IJobSpecification { */ public function getDeduplicationInfo(); + /** + * @see JobQueue::deduplicateRootJob() + * @return array + * @since 1.26 + */ + public function getRootJobParams(); + + /** + * @see JobQueue::deduplicateRootJob() + * @return bool + * @since 1.22 + */ + public function hasRootJobParams(); + + /** + * @see JobQueue::deduplicateRootJob() + * @return bool Whether this is job is a root job + */ + public function isRootJob(); + /** * @return Title Descriptive title (this can simply be informative) */ @@ -101,14 +121,14 @@ class JobSpecification implements IJobSpecification { * @param Title $title Optional descriptive title */ public function __construct( - $type, array $params, array $opts = array(), Title $title = null + $type, array $params, array $opts = [], Title $title = null ) { $this->validateParams( $params ); $this->validateParams( $opts ); $this->type = $type; $this->params = $params; - $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . get_class( $this ) ); + $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . static::class ); $this->opts = $opts; } @@ -125,58 +145,35 @@ class JobSpecification implements IJobSpecification { } } - /** - * @return string - */ public function getType() { return $this->type; } - /** - * @return Title - */ public function getTitle() { return $this->title; } - /** - * @return array - */ public function getParams() { return $this->params; } - /** - * @return int|null UNIX timestamp to delay running this job until, otherwise null - */ public function getReleaseTimestamp() { return isset( $this->params['jobReleaseTimestamp'] ) ? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] ) : null; } - /** - * @return bool Whether only one of each identical set of jobs should be run - */ public function ignoreDuplicates() { return !empty( $this->opts['removeDuplicates'] ); } - /** - * Subclasses may need to override this to make duplication detection work. - * The resulting map conveys everything that makes the job unique. This is - * only checked if ignoreDuplicates() returns true, meaning that duplicate - * jobs are supposed to be ignored. - * - * @return array Map of key/values - */ public function getDeduplicationInfo() { - $info = array( + $info = [ 'type' => $this->getType(), 'namespace' => $this->getTitle()->getNamespace(), 'title' => $this->getTitle()->getDBkey(), 'params' => $this->getParams() - ); + ]; if ( is_array( $info['params'] ) ) { // Identical jobs with different "root" jobs should count as duplicates unset( $info['params']['rootJobSignature'] ); @@ -188,20 +185,40 @@ class JobSpecification implements IJobSpecification { return $info; } + public function getRootJobParams() { + return [ + 'rootJobSignature' => isset( $this->params['rootJobSignature'] ) + ? $this->params['rootJobSignature'] + : null, + 'rootJobTimestamp' => isset( $this->params['rootJobTimestamp'] ) + ? $this->params['rootJobTimestamp'] + : null + ]; + } + + public function hasRootJobParams() { + return isset( $this->params['rootJobSignature'] ) + && isset( $this->params['rootJobTimestamp'] ); + } + + public function isRootJob() { + return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] ); + } + /** * @return array Field/value map that can immediately be serialized * @since 1.25 */ public function toSerializableArray() { - return array( + return [ 'type' => $this->type, 'params' => $this->params, 'opts' => $this->opts, - 'title' => array( + 'title' => [ 'ns' => $this->title->getNamespace(), - 'key' => $this->title->getDbKey() - ) - ); + 'key' => $this->title->getDBkey() + ] + ]; } /**