From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- maintenance/copyJobQueue.php | 99 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 maintenance/copyJobQueue.php (limited to 'maintenance/copyJobQueue.php') diff --git a/maintenance/copyJobQueue.php b/maintenance/copyJobQueue.php new file mode 100644 index 00000000..e833115b --- /dev/null +++ b/maintenance/copyJobQueue.php @@ -0,0 +1,99 @@ +mDescription = "Copy jobs from one queue system to another."; + $this->addOption( 'src', 'Key to $wgJobQueueMigrationConfig for source', true, true ); + $this->addOption( 'dst', 'Key to $wgJobQueueMigrationConfig for destination', true, true ); + $this->addOption( 'type', 'Types of jobs to copy (use "all" for all)', true, true ); + $this->setBatchSize( 500 ); + } + + public function execute() { + global $wgJobQueueMigrationConfig; + + $srcKey = $this->getOption( 'src' ); + $dstKey = $this->getOption( 'dst' ); + + if ( !isset( $wgJobQueueMigrationConfig[$srcKey] ) ) { + $this->error( "\$wgJobQueueMigrationConfig not set for '$srcKey'.", 1 ); + } elseif ( !isset( $wgJobQueueMigrationConfig[$dstKey] ) ) { + $this->error( "\$wgJobQueueMigrationConfig not set for '$dstKey'.", 1 ); + } + + $types = ( $this->getOption( 'type' ) === 'all' ) + ? JobQueueGroup::singleton()->getQueueTypes() + : array( $this->getOption( 'type' ) ); + + foreach ( $types as $type ) { + $baseConfig = array( 'type' => $type, 'wiki' => wfWikiID() ); + $src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] ); + $dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] ); + + list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllQueuedJobs() ); + $this->output( "Copied $totalOK/$total queued $type jobs.\n" ); + + list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllDelayedJobs() ); + $this->output( "Copied $totalOK/$total delayed $type jobs.\n" ); + } + } + + protected function copyJobs( JobQueue $src, JobQueue $dst, $jobs ) { + $total = 0; + $totalOK = 0; + $batch = array(); + foreach ( $jobs as $job ) { + ++$total; + $batch[] = $job; + if ( count( $batch ) >= $this->mBatchSize ) { + if ( $dst->push( $batch ) ) { + $totalOK += count( $batch ); + } + $batch = array(); + $dst->waitForBackups(); + } + } + if ( count( $batch ) ) { + if ( $dst->push( $batch ) ) { + $totalOK += count( $batch ); + } + $dst->waitForBackups(); + } + return array( $total, $totalOK ); + } +} + +$maintClass = 'CopyJobQueue'; +require_once RUN_MAINTENANCE_IF_MAIN; -- cgit v1.2.2