MediaWiki
REL1_22
|
00001 <?php 00024 require_once __DIR__ . '/Maintenance.php'; 00025 00034 class CopyJobQueue extends Maintenance { 00035 public function __construct() { 00036 parent::__construct(); 00037 $this->mDescription = "Copy jobs from one queue system to another."; 00038 $this->addOption( 'src', 'Key to $wgJobQueueMigrationConfig for source', true, true ); 00039 $this->addOption( 'dst', 'Key to $wgJobQueueMigrationConfig for destination', true, true ); 00040 $this->addOption( 'type', 'Types of jobs to copy (use "all" for all)', true, true ); 00041 $this->setBatchSize( 500 ); 00042 } 00043 00044 public function execute() { 00045 global $wgJobQueueMigrationConfig; 00046 00047 $srcKey = $this->getOption( 'src' ); 00048 $dstKey = $this->getOption( 'dst' ); 00049 00050 if ( !isset( $wgJobQueueMigrationConfig[$srcKey] ) ) { 00051 $this->error( "\$wgJobQueueMigrationConfig not set for '$srcKey'.", 1 ); 00052 } elseif ( !isset( $wgJobQueueMigrationConfig[$dstKey] ) ) { 00053 $this->error( "\$wgJobQueueMigrationConfig not set for '$dstKey'.", 1 ); 00054 } 00055 00056 $types = ( $this->getOption( 'type' ) === 'all' ) 00057 ? JobQueueGroup::singleton()->getQueueTypes() 00058 : array( $this->getOption( 'type' ) ); 00059 00060 foreach ( $types as $type ) { 00061 $baseConfig = array( 'type' => $type, 'wiki' => wfWikiID() ); 00062 $src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] ); 00063 $dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] ); 00064 00065 list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllQueuedJobs() ); 00066 $this->output( "Copied $totalOK/$total queued $type jobs.\n" ); 00067 00068 list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllDelayedJobs() ); 00069 $this->output( "Copied $totalOK/$total delayed $type jobs.\n" ); 00070 } 00071 } 00072 00073 protected function copyJobs( JobQueue $src, JobQueue $dst, $jobs ) { 00074 $total = 0; 00075 $totalOK = 0; 00076 $batch = array(); 00077 foreach ( $jobs as $job ) { 00078 ++$total; 00079 $batch[] = $job; 00080 if ( count( $batch ) >= $this->mBatchSize ) { 00081 if ( $dst->push( $batch ) ) { 00082 $totalOK += count( $batch ); 00083 } 00084 $batch = array(); 00085 $dst->waitForBackups(); 00086 } 00087 } 00088 if ( count( $batch ) ) { 00089 if ( $dst->push( $batch ) ) { 00090 $totalOK += count( $batch ); 00091 } 00092 $dst->waitForBackups(); 00093 } 00094 return array( $total, $totalOK ); 00095 } 00096 } 00097 00098 $maintClass = 'CopyJobQueue'; 00099 require_once RUN_MAINTENANCE_IF_MAIN;