* 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
*/
/**
* @param string $command
- * @param array $params
+ * @param array|Title|null $params
*/
- public function __construct( $command, $params = [] ) {
+ public function __construct( $command, $params = null ) {
if ( $params instanceof Title ) {
// Backwards compatibility for old signature ($command, $title, $params)
$title = $params;
- $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
+ $params = func_get_arg( 2 );
} else {
// Subclasses can override getTitle() to return something more meaningful
$title = Title::makeTitle( NS_SPECIAL, 'Blankpage' );
$this->command = $command;
$this->title = $title;
- $this->params = is_array( $params ) ? $params : []; // sanity
+ $this->params = is_array( $params ) ? $params : [];
if ( !isset( $this->params['requestId'] ) ) {
$this->params['requestId'] = WebRequest::getRequestId();
}
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