7use InvalidArgumentException;
11use Wikimedia\ObjectFactory\ObjectFactory;
18 private ObjectFactory $objectFactory;
21 private array $jobObjectSpecs;
27 public function __construct( ObjectFactory $objectFactory, array $jobObjectSpecs ) {
28 $this->objectFactory = $objectFactory;
29 $this->jobObjectSpecs = $jobObjectSpecs;
51 public function newJob(
string $command, $params = [] ):
Job {
52 if ( !isset( $this->jobObjectSpecs[ $command ] ) ) {
53 throw new InvalidArgumentException(
"Invalid job command '{$command}'" );
56 $spec = $this->jobObjectSpecs[ $command ];
57 $needsTitle = $this->needsTitle( $command, $spec );
63 $params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
64 } elseif ( isset( $params[
'namespace'] ) && isset( $params[
'title'] ) ) {
84 $args = [
$title, $params ];
90 $job = $this->objectFactory->createObject(
93 'allowClassName' =>
true,
94 'allowCallable' =>
true,
96 'assertClass' => Job::class
101 $job->command = $command;
114 private function needsTitle(
string $command, $spec ): bool {
115 if ( is_callable( $spec ) ) {
117 } elseif ( is_array( $spec ) ) {
118 if ( isset( $spec[
'needsPage'] ) ) {
119 $needsTitle = $spec[
'needsPage'];
120 } elseif ( isset( $spec[
'class'] ) ) {
121 $needsTitle = !is_subclass_of( $spec[
'class'],
122 GenericParameterJob::class );
123 } elseif ( isset( $spec[
'factory'] ) ) {
126 throw new InvalidArgumentException(
127 "Invalid job specification for '{$command}': " .
128 "must contain the 'class' or 'factory' key."
131 } elseif ( is_string( $spec ) ) {
132 $needsTitle = !is_subclass_of( $spec,
133 GenericParameterJob::class );
135 throw new InvalidArgumentException(
136 "Invalid job specification for '{$command}': " .
137 "must be a callable, an object spec array, or a class name"
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Class to both describe a background job and handle jobs.
Interface for generic jobs only uses the parameters field and are JSON serializable.
if(count( $args)< 1) $job