X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJob.php;h=f9c416f3af700637df6e98fc8ba95555e8e7f214;hb=8518006b9bf0857e35c07729d6263b63ac540989;hp=f814ceeb1b8b7440d1ae6437a10a96fb0da37eab;hpb=fba48c6dae69b7163580d936095b7dd16c9b3644;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php index f814ceeb1b..f9c416f3af 100644 --- a/includes/jobqueue/Job.php +++ b/includes/jobqueue/Job.php @@ -50,6 +50,12 @@ abstract class Job implements IJobSpecification { /** @var callable[] */ protected $teardownCallbacks = []; + /** @var int Bitfield of JOB_* class constants */ + protected $executionFlags = 0; + + /** @var int Job must not be wrapped in the usual explicit LBFactory transaction round */ + const JOB_NO_EXPLICIT_TRX_ROUND = 1; + /** * Run the job * @return bool Success @@ -69,12 +75,22 @@ abstract class Job implements IJobSpecification { global $wgJobClasses; if ( isset( $wgJobClasses[$command] ) ) { - $class = $wgJobClasses[$command]; - - $job = new $class( $title, $params ); - $job->command = $command; + $handler = $wgJobClasses[$command]; + + if ( is_callable( $handler ) ) { + $job = call_user_func( $handler, $title, $params ); + } elseif ( class_exists( $handler ) ) { + $job = new $handler( $title, $params ); + } else { + $job = null; + } - return $job; + if ( $job instanceof Job ) { + $job->command = $command; + return $job; + } else { + throw new InvalidArgumentException( "Cannot instantiate job '$command': bad spec!" ); + } } throw new InvalidArgumentException( "Invalid job command '{$command}'" ); @@ -98,6 +114,15 @@ abstract class Job implements IJobSpecification { } } + /** + * @param int $flag JOB_* class constant + * @return bool + * @since 1.31 + */ + public function hasExecutionFlag( $flag ) { + return ( $this->executionFlags && $flag ) === $flag; + } + /** * Batch-insert a group of jobs into the queue. * This will be wrapped in a transaction with a forced commit. @@ -327,6 +352,7 @@ abstract class Job implements IJobSpecification { * @deprecated since 1.21 */ public function insert() { + wfDeprecated( __METHOD__, '1.21' ); JobQueueGroup::singleton()->push( $this ); return true; }