mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-27 17:50:53 +00:00
Inject services on JobClasses
Change-Id: Ic0e965dca31b41ab76e59a3d2672069464418de8
This commit is contained in:
parent
627a4bf0ef
commit
efa6c4f0ce
|
@ -63,7 +63,12 @@
|
|||
}
|
||||
},
|
||||
"JobClasses": {
|
||||
"InitImageDataJob": "PageImages\\Job\\InitImageDataJob"
|
||||
"InitImageDataJob": {
|
||||
"class": "PageImages\\Job\\InitImageDataJob",
|
||||
"services": [
|
||||
"DBLoadBalancerFactory"
|
||||
]
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"PageImagesScores": {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue