mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-30 19:16:01 +00:00
Inject services on JobClasses
Change-Id: Ic0e965dca31b41ab76e59a3d2672069464418de8
This commit is contained in:
parent
627a4bf0ef
commit
efa6c4f0ce
|
@ -63,7 +63,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"JobClasses": {
|
"JobClasses": {
|
||||||
"InitImageDataJob": "PageImages\\Job\\InitImageDataJob"
|
"InitImageDataJob": {
|
||||||
|
"class": "PageImages\\Job\\InitImageDataJob",
|
||||||
|
"services": [
|
||||||
|
"DBLoadBalancerFactory"
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"PageImagesScores": {
|
"PageImagesScores": {
|
||||||
|
|
|
@ -3,31 +3,38 @@
|
||||||
namespace PageImages\Job;
|
namespace PageImages\Job;
|
||||||
|
|
||||||
use Job;
|
use Job;
|
||||||
use MediaWiki\MediaWikiServices;
|
|
||||||
use MediaWiki\Title\Title;
|
use MediaWiki\Title\Title;
|
||||||
use MWExceptionHandler;
|
use MWExceptionHandler;
|
||||||
use RefreshLinks;
|
use RefreshLinks;
|
||||||
|
use Wikimedia\Rdbms\LBFactory;
|
||||||
|
|
||||||
class InitImageDataJob extends Job {
|
class InitImageDataJob extends Job {
|
||||||
|
/** @var LBFactory */
|
||||||
|
private $lbFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Title $title Title object associated with this job
|
* @param Title $title Title object associated with this job
|
||||||
* @param array $params Parameters to the job, containing an array of
|
* @param array $params Parameters to the job, containing an array of
|
||||||
* page ids representing which pages to process
|
* 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 );
|
parent::__construct( 'InitImageDataJob', $title, $params );
|
||||||
|
$this->lbFactory = $lbFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function run() {
|
public function run() {
|
||||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
|
||||||
|
|
||||||
foreach ( $this->params['page_ids'] as $id ) {
|
foreach ( $this->params['page_ids'] as $id ) {
|
||||||
try {
|
try {
|
||||||
RefreshLinks::fixLinksFromArticle( $id );
|
RefreshLinks::fixLinksFromArticle( $id );
|
||||||
$lbFactory->waitForReplication();
|
$this->lbFactory->waitForReplication();
|
||||||
} catch ( \Exception $e ) {
|
} catch ( \Exception $e ) {
|
||||||
// There are some broken pages out there that just don't parse.
|
// There are some broken pages out there that just don't parse.
|
||||||
// Log it and keep on trucking.
|
// Log it and keep on trucking.
|
||||||
|
|
|
@ -81,7 +81,11 @@ class InitImageData extends Maintenance {
|
||||||
foreach ( $res as $row ) {
|
foreach ( $res as $row ) {
|
||||||
$pageIds[] = $row->page_id;
|
$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 ) {
|
if ( $queue === null ) {
|
||||||
$job->run();
|
$job->run();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue