MediaWiki  1.23.13
copyJobQueue.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
34 class CopyJobQueue extends Maintenance {
35  public function __construct() {
36  parent::__construct();
37  $this->mDescription = "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  }
43 
44  public function execute() {
45  global $wgJobQueueMigrationConfig;
46 
47  $srcKey = $this->getOption( 'src' );
48  $dstKey = $this->getOption( 'dst' );
49 
50  if ( !isset( $wgJobQueueMigrationConfig[$srcKey] ) ) {
51  $this->error( "\$wgJobQueueMigrationConfig not set for '$srcKey'.", 1 );
52  } elseif ( !isset( $wgJobQueueMigrationConfig[$dstKey] ) ) {
53  $this->error( "\$wgJobQueueMigrationConfig not set for '$dstKey'.", 1 );
54  }
55 
56  $types = ( $this->getOption( 'type' ) === 'all' )
57  ? JobQueueGroup::singleton()->getQueueTypes()
58  : array( $this->getOption( 'type' ) );
59 
60  foreach ( $types as $type ) {
61  $baseConfig = array( 'type' => $type, 'wiki' => wfWikiID() );
62  $src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] );
63  $dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] );
64 
65  list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllQueuedJobs() );
66  $this->output( "Copied $totalOK/$total queued $type jobs.\n" );
67 
68  list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllDelayedJobs() );
69  $this->output( "Copied $totalOK/$total delayed $type jobs.\n" );
70  }
71  }
72 
73  protected function copyJobs( JobQueue $src, JobQueue $dst, $jobs ) {
74  $total = 0;
75  $totalOK = 0;
76  $batch = array();
77  foreach ( $jobs as $job ) {
78  ++$total;
79  $batch[] = $job;
80  if ( count( $batch ) >= $this->mBatchSize ) {
81  if ( $dst->push( $batch ) ) {
82  $totalOK += count( $batch );
83  }
84  $batch = array();
85  $dst->waitForBackups();
86  }
87  }
88  if ( count( $batch ) ) {
89  if ( $dst->push( $batch ) ) {
90  $totalOK += count( $batch );
91  }
92  $dst->waitForBackups();
93  }
94  return array( $total, $totalOK );
95  }
96 }
97 
98 $maintClass = 'CopyJobQueue';
99 require_once RUN_MAINTENANCE_IF_MAIN;
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
JobQueue\push
push( $jobs, $flags=0)
Push one or more jobs into the queue.
Definition: JobQueue.php:303
$total
$total
Definition: Utf8Test.php:92
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
CopyJobQueue\copyJobs
copyJobs(JobQueue $src, JobQueue $dst, $jobs)
Definition: copyJobQueue.php:73
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
CopyJobQueue
Copy all jobs from one job queue system to another.
Definition: copyJobQueue.php:34
CopyJobQueue\__construct
__construct()
Default constructor.
Definition: copyJobQueue.php:35
list
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
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:3660
JobQueue\waitForBackups
waitForBackups()
Wait for any slaves or backup servers to catch up.
Definition: JobQueue.php:564
JobQueue\factory
static factory(array $params)
Get a job queue object of the specified type.
Definition: JobQueue.php:105
$maintClass
$maintClass
Definition: copyJobQueue.php:98
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:42
JobQueueGroup\singleton
static singleton( $wiki=false)
Definition: JobQueueGroup.php:61
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:9
JobQueue
Class to handle enqueueing and running of background jobs.
Definition: JobQueue.php:31
$batch
$batch
Definition: linkcache.txt:23
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
CopyJobQueue\execute
execute()
Do the actual work.
Definition: copyJobQueue.php:44
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:254
$type
$type
Definition: testCompression.php:46