From 3bfa823922e478dafc570ee64d9ad944a82feca1 Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Wed, 27 May 2015 11:48:39 +0200 Subject: [PATCH] Maintenance script sends notifications immediately Update the "processEchoEmailBatch" to allow sending all notifications immediately even if configured to be daily or weekly. Change-Id: I6ebeea86708247700d1950e0f6471c7b3d1fecd2 --- includes/EmailBatch.php | 8 ++++++-- maintenance/processEchoEmailBatch.php | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/includes/EmailBatch.php b/includes/EmailBatch.php index 8e8479820..fee9055ab 100644 --- a/includes/EmailBatch.php +++ b/includes/EmailBatch.php @@ -35,9 +35,13 @@ abstract class MWEchoEmailBatch { * 1 - once everyday * 7 - once every 7 days * @param $userId int + * @param $enforceFrequency boolean Whether or not email sending frequency should be enforced. + * When true, today's notifications won't be returned if their are + * configured to go out tonight or at the end of the week. + * When false, all pending notifications will be returned. * @return MWEchoEmailBatch/false */ - public static function newFromUserId( $userId ) { + public static function newFromUserId( $userId, $enforceFrequency = true ) { $batchClassName = self::getEmailBatchClass(); $user = User::newFromId( intval( $userId ) ); @@ -71,7 +75,7 @@ abstract class MWEchoEmailBatch { if ( $userLastBatch ) { // use 20 as hours per day to get estimate $nextBatch = wfTimestamp( TS_UNIX, $userLastBatch ) + $userEmailSetting * 20 * 60 * 60; - if ( wfTimestamp( TS_MW, $nextBatch ) > wfTimestampNow() ) { + if ( $enforceFrequency && wfTimestamp( TS_MW, $nextBatch ) > wfTimestampNow() ) { return false; } } diff --git a/maintenance/processEchoEmailBatch.php b/maintenance/processEchoEmailBatch.php index 222af2d6e..9a628c582 100644 --- a/maintenance/processEchoEmailBatch.php +++ b/maintenance/processEchoEmailBatch.php @@ -20,11 +20,18 @@ class ProcessEchoEmailBatch extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Process email digest"; + + $this->addOption( + "ignoreConfiguredSchedule", + "Send all pending notifications immediately even if configured to be weekly or daily.", + false, false, "i" ); } public function execute() { global $wgEchoCluster; + $ignoreConfiguredSchedule = $this->getOption( "ignoreConfiguredSchedule", 0 ); + $this->output( "Started processing... \n" ); $startUserId = 0; @@ -39,7 +46,7 @@ class ProcessEchoEmailBatch extends Maintenance { foreach ( $res as $row ) { $userId = intval( $row->eeb_user_id ); if ( $userId && $userId > $startUserId ) { - $emailBatch = MWEchoEmailBatch::newFromUserId( $userId ); + $emailBatch = MWEchoEmailBatch::newFromUserId( $userId, !$ignoreConfiguredSchedule ); if ( $emailBatch ) { $this->output( "processing user_Id " . $userId . " \n" ); $emailBatch->process();