mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
Merge "Add exception to email job so error will be tracked"
This commit is contained in:
commit
3669ea0972
|
@ -101,7 +101,7 @@ abstract class MWEchoEmailBundler {
|
|||
// send instant single notification email if there is no base event in the batch queue
|
||||
// and the email is ready to send, otherwiase, add the email to batch and schedule
|
||||
// a delayed job
|
||||
if ( !$this->baseEvent && $this->shouldSendEmailNow() ) {
|
||||
if ( !$this->baseEvent && $this->shouldSendEmailNow() ) {
|
||||
$this->timestamp = wfTimestampNow();
|
||||
$this->updateEmailMetadata();
|
||||
return false;
|
||||
|
@ -211,24 +211,23 @@ abstract class MWEchoEmailBundler {
|
|||
* Main function for processinig bundle email
|
||||
*/
|
||||
public function processBundleEmail() {
|
||||
// User has switched to email digest, should not send any bundle email
|
||||
// and should not schedule any bundle job, the daily cron will handle
|
||||
// events left in the queue
|
||||
if ( intval( $this->mUser->getOption( 'echo-email-frequency' ) ) > 0 ) {
|
||||
return;
|
||||
$emailSetting = intval( $this->mUser->getOption( 'echo-email-frequency' ) );
|
||||
|
||||
// User has switched to email digest or decided not to receive email,
|
||||
// the daily cron will handle events left in the queue
|
||||
if ( $emailSetting != 0 ) {
|
||||
throw new MWException( "User has switched to email digest/no email option!" );
|
||||
}
|
||||
|
||||
$this->retrieveLastEmailTimestamp();
|
||||
|
||||
// if there is nothing in the queue, do not schedule a job or
|
||||
// update timestamp so next email would be just an instant email
|
||||
// If there is nothing in the queue, do not update timestamp so next
|
||||
// email would be just an instant email
|
||||
if ( $this->retrieveBaseEvent() ) {
|
||||
$this->timestamp = wfTimestampNow();
|
||||
$this->updateEmailMetadata();
|
||||
$this->sendEmail();
|
||||
// for testing purpose, comment out the line below so events are kept
|
||||
$this->clearProcessedEvent();
|
||||
$this->pushToJobQueue( $this->emailInterval );
|
||||
} else {
|
||||
throw new MWException( "There is no bundle notification to process!" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,10 +237,8 @@ abstract class MWEchoEmailBundler {
|
|||
protected function sendEmail() {
|
||||
$content = $this->generateEmailContent();
|
||||
|
||||
// Error has occurred
|
||||
// @Todo more error handling
|
||||
if ( !isset( $content['subject'] ) || !isset( $content['body'] ) ) {
|
||||
return;
|
||||
throw new MWException( "Fail to create bundle email content!" );
|
||||
}
|
||||
|
||||
global $wgPasswordSender, $wgPasswordSenderName;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class MWEchoNotificationEmailBundleJob extends Job {
|
||||
function __construct( $title, $params ) {
|
||||
parent::__construct( 'MWEchoNotificationEmailBundleJob', $title, $params );
|
||||
parent::__construct( __CLASS__, $title, $params );
|
||||
// If there is already a job with the same params, this job will be ignored
|
||||
// for example, if there is a page link bundle notification job for article A
|
||||
// created by user B, any subsequent jobs with the same data will be ignored
|
||||
|
@ -10,15 +10,17 @@ class MWEchoNotificationEmailBundleJob extends Job {
|
|||
}
|
||||
|
||||
function run() {
|
||||
$user = User::newFromId( $this->params['user_id'] );
|
||||
if ( $user ) {
|
||||
$bundle = MWEchoEmailBundler::newFromUserHash( $user, $this->params['bundle_hash'] );
|
||||
if ( $bundle ) {
|
||||
$bundle->processBundleEmail();
|
||||
}
|
||||
$bundle = MWEchoEmailBundler::newFromUserHash(
|
||||
User::newFromId( $this->params['user_id'] ),
|
||||
$this->params['bundle_hash']
|
||||
);
|
||||
|
||||
if ( $bundle ) {
|
||||
$bundle->processBundleEmail();
|
||||
} else {
|
||||
//@Todo: delete notifications for this user_id
|
||||
throw new MWException( 'Fail to create bundle object for: user_id: ' . $this->params['user_id'] . ', bundle_hash: ' . $this->params['bundle_hash'] );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue