mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-18 10:52:27 +00:00
c408c0ffa8
Switch the callers to the standard Maintenance::waitForReplication() method. Avoid using LoadBalancer::waitFor(), which will made internal soon. Bug: T326274 Change-Id: Idf0562eb33d90ff70eb3a7d5d7f54da944423d27
70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
if ( $IP === false ) {
|
|
$IP = __DIR__ . '/../../..';
|
|
}
|
|
require_once "$IP/maintenance/Maintenance.php";
|
|
|
|
/**
|
|
* A maintenance script that processes email digest
|
|
*/
|
|
class ProcessEchoEmailBatch extends Maintenance {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->addDescription( "Process email digest" );
|
|
|
|
$this->addOption(
|
|
"ignoreConfiguredSchedule",
|
|
"Send all pending notifications immediately even if configured to be weekly or daily.",
|
|
false, false, "i" );
|
|
|
|
$this->setBatchSize( 300 );
|
|
$this->requireExtension( 'Echo' );
|
|
}
|
|
|
|
public function execute() {
|
|
$lbFactory = MWEchoDbFactory::newFromDefault();
|
|
$ignoreConfiguredSchedule = $this->getOption( "ignoreConfiguredSchedule", 0 );
|
|
|
|
$this->output( "Started processing... \n" );
|
|
|
|
$startUserId = 0;
|
|
$batchSize = $this->getBatchSize();
|
|
$count = $batchSize;
|
|
|
|
while ( $count === $batchSize ) {
|
|
$count = 0;
|
|
|
|
$res = MWEchoEmailBatch::getUsersToNotify( $startUserId, $batchSize );
|
|
|
|
$updated = false;
|
|
foreach ( $res as $row ) {
|
|
$userId = intval( $row->eeb_user_id );
|
|
if ( $userId && $userId > $startUserId ) {
|
|
$emailBatch = MWEchoEmailBatch::newFromUserId( $userId, !$ignoreConfiguredSchedule );
|
|
if ( $emailBatch ) {
|
|
$this->output( "processing user_Id " . $userId . " \n" );
|
|
$emailBatch->process();
|
|
}
|
|
$startUserId = $userId;
|
|
$updated = true;
|
|
}
|
|
$count++;
|
|
}
|
|
$this->waitForReplication();
|
|
|
|
// double check to make sure that the id is updated
|
|
if ( !$updated ) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
$this->output( "Completed \n" );
|
|
}
|
|
}
|
|
|
|
$maintClass = ProcessEchoEmailBatch::class;
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|