mediawiki-extensions-Echo/includes/jobs/NotificationJob.php
Stephane Bisson 4690c2fb47 Use static newFromID instead of loadFromID
Bug: T192945
Change-Id: Ifd7c40dfef5147581a59d39a6dbe7312a9b82cc6
2018-05-17 22:29:09 +02:00

51 lines
1.2 KiB
PHP

<?php
class EchoNotificationJob extends Job {
function __construct( $title, $params ) {
parent::__construct( 'EchoNotificationJob', $title, $params );
$this->eventId = $params['eventId'];
}
function run() {
// back compat for jobs still in queue, new jobs
// masterPos is always set. remove after deploy.
if ( isset( $this->params['masterPos'] ) ) {
$masterPos = $this->params['masterPos'];
} else {
$masterPos = $this->getMasterPosition();
}
MWEchoDbFactory::newFromDefault()->waitFor( $masterPos );
// TEMPORARY: some jobs already in the queue
// have $this->event but not $this->eventId
$event = isset( $this->eventId ) ?
EchoEvent::newFromID( $this->eventId ) :
$this->event;
EchoNotificationController::notify( $event, false );
return true;
}
/**
* back compat detects masterPos from prior job params
*
* @return array
*/
function getMasterPosition() {
$masterPos = [
'wikiDb' => false,
'echoDb' => false,
];
if ( !empty( $this->params['mainDbMasterPos'] ) ) {
$masterPos['wikiDb'] = $this->params['mainDbMasterPos'];
}
if ( !empty( $this->params['echoDbMasterPos'] ) ) {
$masterPos['echoDb'] = $this->params['echoDbMasterPos'];
}
return $masterPos;
}
}