Merge "Maintenance script sends notifications immediately"

This commit is contained in:
jenkins-bot 2015-05-28 07:58:23 +00:00 committed by Gerrit Code Review
commit 5bcdfc6607
2 changed files with 14 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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();