2012-11-27 01:53:35 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DbFactory;
|
2022-11-13 06:43:40 +00:00
|
|
|
use MediaWiki\Extension\Notifications\EmailBatch;
|
2024-10-19 22:55:03 +00:00
|
|
|
use MediaWiki\Maintenance\Maintenance;
|
2022-11-12 07:19:00 +00:00
|
|
|
|
2012-11-27 01:53:35 +00:00
|
|
|
$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
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
2019-03-27 05:07:48 +00:00
|
|
|
$this->addDescription( "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
|
|
|
|
2020-12-17 18:27:43 +00:00
|
|
|
$this->setBatchSize( 300 );
|
2016-12-01 21:34:43 +00:00
|
|
|
$this->requireExtension( 'Echo' );
|
2012-11-27 01:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2022-11-12 07:19:00 +00:00
|
|
|
$lbFactory = DbFactory::newFromDefault();
|
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;
|
2020-12-17 18:27:43 +00:00
|
|
|
$batchSize = $this->getBatchSize();
|
|
|
|
$count = $batchSize;
|
2012-11-27 01:53:35 +00:00
|
|
|
|
2020-12-17 18:27:43 +00:00
|
|
|
while ( $count === $batchSize ) {
|
2012-11-27 01:53:35 +00:00
|
|
|
$count = 0;
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2022-11-13 06:43:40 +00:00
|
|
|
$res = EmailBatch::getUsersToNotify( $startUserId, $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 ) {
|
2022-11-13 06:43:40 +00:00
|
|
|
$emailBatch = EmailBatch::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++;
|
|
|
|
}
|
2023-01-05 21:14:51 +00:00
|
|
|
$this->waitForReplication();
|
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" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 14:14:15 +00:00
|
|
|
$maintClass = ProcessEchoEmailBatch::class;
|
2018-03-17 20:55:20 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|