jobqueue: simplify the signature of Job::factory() and Job::__construct()
Remove the $title argument from these methods to simplify subclasses that do not have a meaningful title to use. The Job::getTitle() method can be overriden by subclasses to return something meaningful. The old call signature is still supported for backwards compatibility. This will automatically determine what getTitle() returns as before. Use "Blankpage" as the "not applicable" title for jobs instead of one that looks like some error occured. Change-Id: I3d5bd012d9cef1e7daaccfb0d5d319552eb89fb6
This commit is contained in:
parent
e17e9ea519
commit
9b4938c40d
2 changed files with 25 additions and 12 deletions
|
|
@ -41,7 +41,7 @@ abstract class Job implements IJobSpecification {
|
|||
protected $title;
|
||||
|
||||
/** @var bool Expensive jobs may set this to true */
|
||||
protected $removeDuplicates;
|
||||
protected $removeDuplicates = false;
|
||||
|
||||
/** @var string Text for error that occurred last */
|
||||
protected $error;
|
||||
|
|
@ -65,14 +65,22 @@ abstract class Job implements IJobSpecification {
|
|||
* Create the appropriate object to handle a specific job
|
||||
*
|
||||
* @param string $command Job command
|
||||
* @param Title $title Associated title
|
||||
* @param array $params Job parameters
|
||||
* @throws InvalidArgumentException
|
||||
* @return Job
|
||||
*/
|
||||
public static function factory( $command, Title $title, $params = [] ) {
|
||||
public static function factory( $command, $params = [] ) {
|
||||
global $wgJobClasses;
|
||||
|
||||
if ( $params instanceof Title ) {
|
||||
// Backwards compatibility for old signature ($command, $title, $params)
|
||||
$title = $params;
|
||||
$params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
|
||||
} else {
|
||||
// Subclasses can override getTitle() to return something more meaningful
|
||||
$title = Title::makeTitle( NS_SPECIAL, 'Blankpage' );
|
||||
}
|
||||
|
||||
if ( isset( $wgJobClasses[$command] ) ) {
|
||||
$handler = $wgJobClasses[$command];
|
||||
|
||||
|
|
@ -86,9 +94,10 @@ abstract class Job implements IJobSpecification {
|
|||
|
||||
if ( $job instanceof Job ) {
|
||||
$job->command = $command;
|
||||
|
||||
return $job;
|
||||
} else {
|
||||
throw new InvalidArgumentException( "Cannot instantiate job '$command': bad spec!" );
|
||||
throw new InvalidArgumentException( "Could instantiate job '$command': bad spec!" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,17 +106,21 @@ abstract class Job implements IJobSpecification {
|
|||
|
||||
/**
|
||||
* @param string $command
|
||||
* @param Title $title
|
||||
* @param array|bool $params Can not be === true
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $command, $title, $params = false ) {
|
||||
public function __construct( $command, $params = [] ) {
|
||||
if ( $params instanceof Title ) {
|
||||
// Backwards compatibility for old signature ($command, $title, $params)
|
||||
$title = $params;
|
||||
$params = func_num_args() >= 3 ? 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
|
||||
|
||||
// expensive jobs may set this to true
|
||||
$this->removeDuplicates = false;
|
||||
|
||||
if ( !isset( $this->params['requestId'] ) ) {
|
||||
$this->params['requestId'] = WebRequest::getRequestId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class JobSpecification implements IJobSpecification {
|
|||
|
||||
$this->type = $type;
|
||||
$this->params = $params;
|
||||
$this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . static::class );
|
||||
$this->title = $title ?: Title::makeTitle( NS_SPECIAL, 'Blankpage' );
|
||||
$this->opts = $opts;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue