Merge "Blacklist MeeGo's browser"
[lhc/web/wiklou.git] / includes / jobqueue / JobSpecification.php
index 9fa7747..9ace1ba 100644 (file)
@@ -68,7 +68,7 @@ interface IJobSpecification {
  * Job queue task description base code
  *
  * Example usage:
- * <code>
+ * @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 )
- * </code>
+ * @endcode
  *
  * @ingroup JobQueue
  * @since 1.23
@@ -91,24 +91,25 @@ 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
         * @param array $params Map of key/values
-        * @param array $opts Map of key/values
+        * @param array $opts Map of key/values; includes 'removeDuplicates'
         * @param Title $title Optional descriptive title
         */
        public function __construct(
                $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 );
+       }
 }