MediaWiki  master
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
34 class CopyJobQueue extends Maintenance {
35  public function __construct() {
36  parent::__construct();
37  $this->addDescription( 'Copy jobs from one queue system to another.' );
38  $this->addOption( 'src', 'Key to $wgJobQueueMigrationConfig for source', true, true );
39  $this->addOption( 'dst', 'Key to $wgJobQueueMigrationConfig for destination', true, true );
40  $this->addOption( 'type', 'Types of jobs to copy (use "all" for all)', true, true );
41  $this->setBatchSize( 500 );
42  }
44  public function execute() {
45  global $wgJobQueueMigrationConfig;
47  $srcKey = $this->getOption( 'src' );
48  $dstKey = $this->getOption( 'dst' );
50  if ( !isset( $wgJobQueueMigrationConfig[$srcKey] ) ) {
51  $this->fatalError( "\$wgJobQueueMigrationConfig not set for '$srcKey'." );
52  } elseif ( !isset( $wgJobQueueMigrationConfig[$dstKey] ) ) {
53  $this->fatalError( "\$wgJobQueueMigrationConfig not set for '$dstKey'." );
54  }
56  $types = ( $this->getOption( 'type' ) === 'all' )
57  ? JobQueueGroup::singleton()->getQueueTypes()
58  : [ $this->getOption( 'type' ) ];
60  $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
61  foreach ( $types as $type ) {
62  $baseConfig = [ 'type' => $type, 'domain' => $dbDomain ];
63  $src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] );
64  $dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] );
66  list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllQueuedJobs() );
67  $this->output( "Copied $totalOK/$total queued $type jobs.\n" );
69  list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllDelayedJobs() );
70  $this->output( "Copied $totalOK/$total delayed $type jobs.\n" );
71  }
72  }
74  protected function copyJobs( JobQueue $src, JobQueue $dst, $jobs ) {
75  $total = 0;
76  $totalOK = 0;
77  $batch = [];
78  foreach ( $jobs as $job ) {
79  ++$total;
80  $batch[] = $job;
81  if ( count( $batch ) >= $this->getBatchSize() ) {
82  $dst->push( $batch );
83  $totalOK += count( $batch );
84  $batch = [];
85  $dst->waitForBackups();
86  }
87  }
88  if ( count( $batch ) ) {
89  $dst->push( $batch );
90  $totalOK += count( $batch );
91  $dst->waitForBackups();
92  }
94  return [ $total, $totalOK ];
95  }
96 }
99 require_once RUN_MAINTENANCE_IF_MAIN;
Copy all jobs from one job queue system to another.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
getOption( $name, $default=null)
Get an option, or return the default.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
setBatchSize( $s=0)
Set the batch size.
Definition: maintenance.txt:50
Definition: linkcache.txt:23
addDescription( $text)
Set the description text.
output( $out, $channel=null)
Throw some output to the user.
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:9
push( $jobs, $flags=0)
Push one or more jobs into the queue.
Definition: JobQueue.php:318
static getCurrentWikiDbDomain()
Definition: WikiMap.php:293
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:35
copyJobs(JobQueue $src, JobQueue $dst, $jobs)
static factory(array $params)
Get a job queue object of the specified type.
Definition: JobQueue.php:114
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Class to handle enqueueing and running of background jobs.
Definition: JobQueue.php:31
if(count( $args)< 1) $job
Returns batch size.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
static singleton( $domain=false)
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Wait for any replica DBs or backup servers to catch up.
Definition: JobQueue.php:570