mediawiki-extensions-Echo/processEchoEmailBatch.php
bsitu 6b8571403a Initial check-in for email batch
patch set 3:
	* add gender support to various messages
	* tweak variables a little bit, e.g. move class variables to function local variables
patch set 4:
	* update various email to e-mail in i18n file
	* add support to process only valid echo events
	* add global email footer
	* add the new table schema to core schema file
patch set 5:
	* remove trailing white space
	* add missing semicolon to return statement in Notifier::notifyWithEmail()
patch set 8:
	* some change based on newest feature requirement

Change-Id: I3298617dab4c04c4d6d486469120fc2d0c986b66
2012-12-12 12:00:13 -08:00

79 lines
1.6 KiB
PHP

<?php
$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = dirname( __FILE__ ) . '/../..';
}
require_once( "$IP/maintenance/Maintenance.php" );
/**
* A maintenance script that processes email digest
*/
class processEchoEmailBatch extends Maintenance {
/**
* Max number of records to process at a time
* @var int
*/
protected $batchSize = 300;
/**
* @var DatabaseBase
*/
protected $dbr;
public function __construct() {
parent::__construct();
$this->mDescription = "Process email digest";
}
protected function init() {
$this->dbr = wfGetDB( DB_SLAVE );
}
public function execute() {
$this->init();
$this->output( "Started processing... \n" );
$startUserId = 0;
$count = $this->batchSize;
while ( $count === $this->batchSize ) {
$count = 0;
$res = $this->dbr->select(
array( 'echo_email_batch' ),
array( 'eeb_user_id' ),
array( 'eeb_user_id > ' . $startUserId ),
__METHOD__,
array( 'ORDER BY' => 'eeb_user_id', 'LIMIT' => $this->batchSize )
);
$updated = false;
foreach ( $res as $row ) {
$userId = intval( $row->eeb_user_id );
if ( $userId && $userId > $startUserId ) {
$emailBatch = MWEchoEmailBatch::newFromUserId( $userId );
if ( $emailBatch ) {
$this->output( "processing user_Id " . $userId . " \n" );
$emailBatch->process();
}
$startUserId = $userId;
$updated = true;
}
$count++;
}
wfWaitForSlaves();
// double check to make sure that the id is updated
if ( !$updated ) {
break;
}
}
$this->output( "Completed \n" );
}
}
$maintClass = "processEchoEmailBatch";
require_once( DO_MAINTENANCE );