Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ProcessEchoEmailBatch | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | use MediaWiki\Extension\Notifications\DbFactory; |
4 | use MediaWiki\Extension\Notifications\EmailBatch; |
5 | |
6 | $IP = getenv( 'MW_INSTALL_PATH' ); |
7 | if ( $IP === false ) { |
8 | $IP = __DIR__ . '/../../..'; |
9 | } |
10 | require_once "$IP/maintenance/Maintenance.php"; |
11 | |
12 | /** |
13 | * A maintenance script that processes email digest |
14 | */ |
15 | class ProcessEchoEmailBatch extends Maintenance { |
16 | |
17 | public function __construct() { |
18 | parent::__construct(); |
19 | $this->addDescription( "Process email digest" ); |
20 | |
21 | $this->addOption( |
22 | "ignoreConfiguredSchedule", |
23 | "Send all pending notifications immediately even if configured to be weekly or daily.", |
24 | false, false, "i" ); |
25 | |
26 | $this->setBatchSize( 300 ); |
27 | $this->requireExtension( 'Echo' ); |
28 | } |
29 | |
30 | public function execute() { |
31 | $lbFactory = DbFactory::newFromDefault(); |
32 | $ignoreConfiguredSchedule = $this->getOption( "ignoreConfiguredSchedule", 0 ); |
33 | |
34 | $this->output( "Started processing... \n" ); |
35 | |
36 | $startUserId = 0; |
37 | $batchSize = $this->getBatchSize(); |
38 | $count = $batchSize; |
39 | |
40 | while ( $count === $batchSize ) { |
41 | $count = 0; |
42 | |
43 | $res = EmailBatch::getUsersToNotify( $startUserId, $batchSize ); |
44 | |
45 | $updated = false; |
46 | foreach ( $res as $row ) { |
47 | $userId = intval( $row->eeb_user_id ); |
48 | if ( $userId && $userId > $startUserId ) { |
49 | $emailBatch = EmailBatch::newFromUserId( $userId, !$ignoreConfiguredSchedule ); |
50 | if ( $emailBatch ) { |
51 | $this->output( "processing user_Id " . $userId . " \n" ); |
52 | $emailBatch->process(); |
53 | } |
54 | $startUserId = $userId; |
55 | $updated = true; |
56 | } |
57 | $count++; |
58 | } |
59 | $this->waitForReplication(); |
60 | |
61 | // double check to make sure that the id is updated |
62 | if ( !$updated ) { |
63 | break; |
64 | } |
65 | } |
66 | |
67 | $this->output( "Completed \n" ); |
68 | } |
69 | } |
70 | |
71 | $maintClass = ProcessEchoEmailBatch::class; |
72 | require_once RUN_MAINTENANCE_IF_MAIN; |