2012-11-27 01:53:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
2015-10-29 11:22:22 +00:00
|
|
|
$IP = __DIR__ . '/../../..';
|
2012-11-27 01:53:35 +00:00
|
|
|
}
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
2012-11-27 01:53:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A maintenance script that processes email digest
|
|
|
|
*/
|
2013-03-08 01:50:54 +00:00
|
|
|
class ProcessEchoEmailBatch extends Maintenance {
|
2012-11-27 01:53:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Max number of records to process at a time
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $batchSize = 300;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->mDescription = "Process email digest";
|
2015-05-27 09:48:39 +00:00
|
|
|
|
|
|
|
$this->addOption(
|
|
|
|
"ignoreConfiguredSchedule",
|
|
|
|
"Send all pending notifications immediately even if configured to be weekly or daily.",
|
|
|
|
false, false, "i" );
|
2016-12-01 21:34:43 +00:00
|
|
|
|
|
|
|
$this->requireExtension( 'Echo' );
|
2012-11-27 01:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2013-04-11 14:00:00 +00:00
|
|
|
global $wgEchoCluster;
|
|
|
|
|
2015-05-31 12:21:08 +00:00
|
|
|
if ( !class_exists( 'EchoHooks' ) ) {
|
|
|
|
$this->error( "Echo isn't enabled on this wiki\n", 1 );
|
|
|
|
}
|
|
|
|
|
2015-05-27 09:48:39 +00:00
|
|
|
$ignoreConfiguredSchedule = $this->getOption( "ignoreConfiguredSchedule", 0 );
|
|
|
|
|
2012-11-27 01:53:35 +00:00
|
|
|
$this->output( "Started processing... \n" );
|
|
|
|
|
|
|
|
$startUserId = 0;
|
|
|
|
$count = $this->batchSize;
|
|
|
|
|
|
|
|
while ( $count === $this->batchSize ) {
|
|
|
|
$count = 0;
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
$res = MWEchoEmailBatch::getUsersToNotify( $startUserId, $this->batchSize );
|
2012-11-27 01:53:35 +00:00
|
|
|
|
|
|
|
$updated = false;
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$userId = intval( $row->eeb_user_id );
|
|
|
|
if ( $userId && $userId > $startUserId ) {
|
2015-05-27 09:48:39 +00:00
|
|
|
$emailBatch = MWEchoEmailBatch::newFromUserId( $userId, !$ignoreConfiguredSchedule );
|
2012-11-27 01:53:35 +00:00
|
|
|
if ( $emailBatch ) {
|
|
|
|
$this->output( "processing user_Id " . $userId . " \n" );
|
|
|
|
$emailBatch->process();
|
|
|
|
}
|
|
|
|
$startUserId = $userId;
|
|
|
|
$updated = true;
|
|
|
|
}
|
|
|
|
$count++;
|
|
|
|
}
|
2013-04-11 14:00:00 +00:00
|
|
|
wfWaitForSlaves( false, false, $wgEchoCluster );
|
2013-05-02 21:11:49 +00:00
|
|
|
// This is required since we are updating user properties in main wikidb
|
|
|
|
wfWaitForSlaves();
|
2012-11-27 01:53:35 +00:00
|
|
|
|
|
|
|
// double check to make sure that the id is updated
|
|
|
|
if ( !$updated ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->output( "Completed \n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-08 01:50:54 +00:00
|
|
|
$maintClass = "ProcessEchoEmailBatch";
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once DO_MAINTENANCE;
|