diff --git a/extension.json b/extension.json index 1abe587..1cf2cf2 100644 --- a/extension.json +++ b/extension.json @@ -63,7 +63,12 @@ } }, "JobClasses": { - "InitImageDataJob": "PageImages\\Job\\InitImageDataJob" + "InitImageDataJob": { + "class": "PageImages\\Job\\InitImageDataJob", + "services": [ + "DBLoadBalancerFactory" + ] + } }, "config": { "PageImagesScores": { diff --git a/includes/Job/InitImageDataJob.php b/includes/Job/InitImageDataJob.php index f31cba1..4b8caac 100644 --- a/includes/Job/InitImageDataJob.php +++ b/includes/Job/InitImageDataJob.php @@ -3,31 +3,38 @@ namespace PageImages\Job; use Job; -use MediaWiki\MediaWikiServices; use MediaWiki\Title\Title; use MWExceptionHandler; use RefreshLinks; +use Wikimedia\Rdbms\LBFactory; class InitImageDataJob extends Job { + /** @var LBFactory */ + private $lbFactory; + /** * @param Title $title Title object associated with this job * @param array $params Parameters to the job, containing an array of * page ids representing which pages to process + * @param LBFactory $lbFactory */ - public function __construct( Title $title, array $params ) { + public function __construct( + Title $title, + array $params, + LBFactory $lbFactory + ) { parent::__construct( 'InitImageDataJob', $title, $params ); + $this->lbFactory = $lbFactory; } /** * @inheritDoc */ public function run() { - $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); - foreach ( $this->params['page_ids'] as $id ) { try { RefreshLinks::fixLinksFromArticle( $id ); - $lbFactory->waitForReplication(); + $this->lbFactory->waitForReplication(); } catch ( \Exception $e ) { // There are some broken pages out there that just don't parse. // Log it and keep on trucking. diff --git a/maintenance/initImageData.php b/maintenance/initImageData.php index 2d4a3ec..c2b754f 100644 --- a/maintenance/initImageData.php +++ b/maintenance/initImageData.php @@ -81,7 +81,11 @@ class InitImageData extends Maintenance { foreach ( $res as $row ) { $pageIds[] = $row->page_id; } - $job = new InitImageDataJob( Title::newMainPage(), [ 'page_ids' => $pageIds ] ); + $job = new InitImageDataJob( + Title::newMainPage(), + [ 'page_ids' => $pageIds ], + $this->getServiceContainer()->getDBLoadBalancerFactory() + ); if ( $queue === null ) { $job->run(); } else {