| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Watchlist; |
| 22 |
|
| 23 |
use GenericParameterJob; |
| 24 |
use InvalidArgumentException; |
| 25 |
use Job; |
| 26 |
use MediaWiki\MainConfigNames; |
| 27 |
use MediaWiki\MediaWikiServices; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class ClearWatchlistNotificationsJob extends Job implements GenericParameterJob { |
| 42 |
public function __construct( array $params ) { |
| 43 |
parent::__construct( 'clearWatchlistNotifications', $params ); |
| 44 |
|
| 45 |
static $required = [ 'userId', 'casTime' ]; |
| 46 |
$missing = implode( ', ', array_diff( $required, array_keys( $this->params ) ) ); |
| 47 |
if ( $missing != '' ) { |
| 48 |
throw new InvalidArgumentException( "Missing parameter(s) $missing" ); |
| 49 |
} |
| 50 |
|
| 51 |
$this->removeDuplicates = true; |
| 52 |
} |
| 53 |
|
| 54 |
public function run() { |
| 55 |
$services = MediaWikiServices::getInstance(); |
| 56 |
$dbProvider = $services->getConnectionProvider(); |
| 57 |
$rowsPerQuery = $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery ); |
| 58 |
|
| 59 |
$dbw = $dbProvider->getPrimaryDatabase(); |
| 60 |
$ticket = $dbProvider->getEmptyTransactionTicket( __METHOD__ ); |
| 61 |
if ( !isset( $this->params['timestamp'] ) ) { |
| 62 |
$timestamp = null; |
| 63 |
$timestampCond = $dbw->expr( 'wl_notificationtimestamp', '!=', null ); |
| 64 |
} else { |
| 65 |
$timestamp = $dbw->timestamp( $this->params['timestamp'] ); |
| 66 |
$timestampCond = $dbw->expr( 'wl_notificationtimestamp', '!=', $timestamp ) |
| 67 |
->or( 'wl_notificationtimestamp', '=', null ); |
| 68 |
} |
| 69 |
|
| 70 |
$casTimeCond = $dbw->expr( 'wl_notificationtimestamp', '<', $dbw->timestamp( $this->params['casTime'] ) ) |
| 71 |
->or( 'wl_notificationtimestamp', '=', null ); |
| 72 |
|
| 73 |
$firstBatch = true; |
| 74 |
do { |
| 75 |
$idsToUpdate = $dbw->newSelectQueryBuilder() |
| 76 |
->select( 'wl_id' ) |
| 77 |
->from( 'watchlist' ) |
| 78 |
->where( [ 'wl_user' => $this->params['userId'] ] ) |
| 79 |
->andWhere( $timestampCond ) |
| 80 |
->andWhere( $casTimeCond ) |
| 81 |
->limit( $rowsPerQuery ) |
| 82 |
->caller( __METHOD__ )->fetchFieldValues(); |
| 83 |
|
| 84 |
if ( $idsToUpdate ) { |
| 85 |
$dbw->newUpdateQueryBuilder() |
| 86 |
->update( 'watchlist' ) |
| 87 |
->set( [ 'wl_notificationtimestamp' => $timestamp ] ) |
| 88 |
->where( [ 'wl_id' => $idsToUpdate ] ) |
| 89 |
->andWhere( $casTimeCond ) |
| 90 |
->caller( __METHOD__ )->execute(); |
| 91 |
if ( !$firstBatch ) { |
| 92 |
$dbProvider->commitAndWaitForReplication( __METHOD__, $ticket ); |
| 93 |
} |
| 94 |
$firstBatch = false; |
| 95 |
} |
| 96 |
} while ( $idsToUpdate ); |
| 97 |
return true; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
class_alias( ClearWatchlistNotificationsJob::class, 'ClearWatchlistNotificationsJob' ); |