MediaWiki  REL1_31
EnqueueJob.php
Go to the documentation of this file.
1 <?php
35 final class EnqueueJob extends Job {
43  parent::__construct( 'enqueue', $title, $params );
44  }
45 
50  public static function newFromLocalJobs( $jobs ) {
51  $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
52 
53  return self::newFromJobsByWiki( [ wfWikiID() => $jobs ] );
54  }
55 
60  public static function newFromJobsByWiki( array $jobsByWiki ) {
61  $deduplicate = true;
62 
63  $jobMapsByWiki = [];
64  foreach ( $jobsByWiki as $wiki => $jobs ) {
65  $jobMapsByWiki[$wiki] = [];
66  foreach ( $jobs as $job ) {
67  if ( $job instanceof JobSpecification ) {
68  $jobMapsByWiki[$wiki][] = $job->toSerializableArray();
69  } else {
70  throw new InvalidArgumentException( "Jobs must be of type JobSpecification." );
71  }
72  $deduplicate = $deduplicate && $job->ignoreDuplicates();
73  }
74  }
75 
76  $eJob = new self(
77  Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ ),
78  [ 'jobsByWiki' => $jobMapsByWiki ]
79  );
80  // If *all* jobs to be pushed are to be de-duplicated (a common case), then
81  // de-duplicate this whole job itself to avoid build up in high traffic cases
82  $eJob->removeDuplicates = $deduplicate;
83 
84  return $eJob;
85  }
86 
87  public function run() {
88  foreach ( $this->params['jobsByWiki'] as $wiki => $jobMaps ) {
89  $jobSpecs = [];
90  foreach ( $jobMaps as $jobMap ) {
91  $jobSpecs[] = JobSpecification::newFromArray( $jobMap );
92  }
93  JobQueueGroup::singleton( $wiki )->push( $jobSpecs );
94  }
95 
96  return true;
97  }
98 }
array
the array() calling protocol came about after MediaWiki 1.4rc1.
JobSpecification\newFromArray
static newFromArray(array $map)
Definition: JobSpecification.php:228
EnqueueJob\run
run()
Run the job.
Definition: EnqueueJob.php:87
Job\$title
Title $title
Definition: Job.php:42
EnqueueJob
Router job that takes jobs and enqueues them to their proper queues.
Definition: EnqueueJob.php:35
EnqueueJob\__construct
__construct(Title $title, array $params)
Callers should use the factory methods instead.
Definition: EnqueueJob.php:42
Job\$params
array $params
Array of job parameters.
Definition: Job.php:36
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:31
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:63
EnqueueJob\newFromJobsByWiki
static newFromJobsByWiki(array $jobsByWiki)
Definition: EnqueueJob.php:60
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:534
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:2763
Title
Represents a title within MediaWiki.
Definition: Title.php:39
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:72
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:47
JobSpecification
Job queue task description base code.
Definition: JobSpecification.php:103
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
EnqueueJob\newFromLocalJobs
static newFromLocalJobs( $jobs)
Definition: EnqueueJob.php:50