Merge "Introduce PermissionManager service"
[lhc/web/wiklou.git] / includes / jobqueue / Job.php
index 24fc473..55cb942 100644 (file)
@@ -65,7 +65,7 @@ abstract class Job implements IJobSpecification {
         * Create the appropriate object to handle a specific job
         *
         * @param string $command Job command
-        * @param array $params Job parameters
+        * @param array|Title $params Job parameters
         * @throws InvalidArgumentException
         * @return Job
         */
@@ -106,7 +106,7 @@ abstract class Job implements IJobSpecification {
 
        /**
         * @param string $command
-        * @param array $params
+        * @param array|Title $params
         */
        public function __construct( $command, $params = [] ) {
                if ( $params instanceof Title ) {
@@ -156,6 +156,36 @@ abstract class Job implements IJobSpecification {
                return $this->params;
        }
 
+       /**
+        * @param string|null $field Metadata field or null to get all the metadata
+        * @return mixed|null Value; null if missing
+        * @since 1.33
+        */
+       public function getMetadata( $field = null ) {
+               if ( $field === null ) {
+                       return $this->metadata;
+               }
+
+               return $this->metadata[$field] ?? null;
+       }
+
+       /**
+        * @param string $field Key name to set the value for
+        * @param mixed $value The value to set the field for
+        * @return mixed|null The prior field value; null if missing
+        * @since 1.33
+        */
+       public function setMetadata( $field, $value ) {
+               $old = $this->getMetadata( $field );
+               if ( $value === null ) {
+                       unset( $this->metadata[$field] );
+               } else {
+                       $this->metadata[$field] = $value;
+               }
+
+               return $old;
+       }
+
        /**
         * @return int|null UNIX timestamp to delay running this job until, otherwise null
         * @since 1.22