X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJobSpecification.php;h=327a18f95a5031e962084d0109e829e4994073b3;hb=7845227f8f9155a73a66e037b1b9843c59a28f93;hp=9fa7747ffc5e09b137274e23f6998cc5376196e2;hpb=3e39c2c157b30699b622d5cc4ae066a84ae74348;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/JobSpecification.php b/includes/jobqueue/JobSpecification.php index 9fa7747ffc..327a18f95a 100644 --- a/includes/jobqueue/JobSpecification.php +++ b/includes/jobqueue/JobSpecification.php @@ -68,7 +68,7 @@ interface IJobSpecification { * Job queue task description base code * * Example usage: - * + * @code * $job = new JobSpecification( * 'null', * array( 'lives' => 1, 'usleep' => 100, 'pi' => 3.141569 ), @@ -76,7 +76,7 @@ interface IJobSpecification { * Title::makeTitle( NS_SPECIAL, 'nullity' ) * ); * JobQueueGroup::singleton()->push( $job ) - * + * @endcode * * @ingroup JobQueue * @since 1.23 @@ -91,8 +91,8 @@ class JobSpecification implements IJobSpecification { /** @var Title */ protected $title; - /** @var bool Expensive jobs may set this to true */ - protected $ignoreDuplicates; + /** @var array */ + protected $opts; /** * @param string $type @@ -104,11 +104,12 @@ class JobSpecification implements IJobSpecification { $type, array $params, array $opts = array(), Title $title = null ) { $this->validateParams( $params ); + $this->validateParams( $opts ); $this->type = $type; $this->params = $params; - $this->title = $title ?: Title::newMainPage(); - $this->ignoreDuplicates = !empty( $opts['removeDuplicates'] ); + $this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . get_class( $this ) ); + $this->opts = $opts; } /** @@ -158,7 +159,7 @@ class JobSpecification implements IJobSpecification { * @return bool Whether only one of each identical set of jobs should be run */ public function ignoreDuplicates() { - return $this->ignoreDuplicates; + return !empty( $this->opts['removeDuplicates'] ); } /** @@ -186,4 +187,31 @@ class JobSpecification implements IJobSpecification { return $info; } + + /** + * @return array Field/value map that can immediately be serialized + * @since 1.25 + */ + public function toSerializableArray() { + return array( + 'type' => $this->type, + 'params' => $this->params, + 'opts' => $this->opts, + 'title' => array( + 'ns' => $this->title->getNamespace(), + 'key' => $this->title->getDbKey() + ) + ); + } + + /** + * @param array $map Field/value map + * @return JobSpecification + * @since 1.25 + */ + public static function newFromArray( array $map ) { + $title = Title::makeTitle( $map['title']['ns'], $map['title']['key'] ); + + return new self( $map['type'], $map['params'], $map['opts'], $title ); + } }