X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJob.php;h=8508861fbc0362ca09f78adf2123fd208c8d9eaa;hb=6b97d969c3a1c4f7c3565c980383ce977062c0e2;hp=bbd0ddb5f8dffd327116779b2afa8e3471174864;hpb=cc991d3cb0cb17c8532d4970c7f50cb1250c7ebe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php index bbd0ddb5f8..8508861fbc 100644 --- a/includes/jobqueue/Job.php +++ b/includes/jobqueue/Job.php @@ -69,12 +69,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}'" ); @@ -301,7 +311,9 @@ abstract class Job implements IJobSpecification { } /** - * @param callable $callback + * @param callable $callback A function with one parameter, the success status, which will be + * false if the job failed or it succeeded but the DB changes could not be committed or + * any deferred updates threw an exception. (This parameter was added in 1.28.) * @since 1.27 */ protected function addTeardownCallback( $callback ) { @@ -310,12 +322,12 @@ abstract class Job implements IJobSpecification { /** * Do any final cleanup after run(), deferred updates, and all DB commits happen - * + * @param bool $status Whether the job, its deferred updates, and DB commit all succeeded * @since 1.27 */ - public function teardown() { + public function teardown( $status ) { foreach ( $this->teardownCallbacks as $callback ) { - call_user_func( $callback ); + call_user_func( $callback, $status ); } } @@ -325,6 +337,7 @@ abstract class Job implements IJobSpecification { * @deprecated since 1.21 */ public function insert() { + wfDeprecated( __METHOD__, '1.21' ); JobQueueGroup::singleton()->push( $this ); return true; }