Debian Codegraph @

extensions/Echo/maintenance/processEchoEmailBatch.php

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