params ) ) ); if ( $missing != '' ) { throw new InvalidArgumentException( "Missing parameter(s) $missing" ); } $this->removeDuplicates = true; } public function run() { $services = MediaWikiServices::getInstance(); $lbFactory = $services->getDBLoadBalancerFactory(); $rowsPerQuery = $services->getMainConfig()->get( 'UpdateRowsPerQuery' ); $dbw = $lbFactory->getMainLB()->getConnection( DB_MASTER ); $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); $timestamp = $this->params['timestamp'] ?? null; if ( $timestamp === null ) { $timestampCond = 'wl_notificationtimestamp IS NOT NULL'; } else { $timestamp = $dbw->timestamp( $timestamp ); $timestampCond = 'wl_notificationtimestamp != ' . $dbw->addQuotes( $timestamp ) . ' OR wl_notificationtimestamp IS NULL'; } // New notifications since the reset should not be cleared $casTimeCond = 'wl_notificationtimestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->params['casTime'] ) ) . ' OR wl_notificationtimestamp IS NULL'; $firstBatch = true; do { $idsToUpdate = $dbw->selectFieldValues( 'watchlist', 'wl_id', [ 'wl_user' => $this->params['userId'], $timestampCond, $casTimeCond, ], __METHOD__, [ 'LIMIT' => $rowsPerQuery ] ); if ( $idsToUpdate ) { $dbw->update( 'watchlist', [ 'wl_notificationtimestamp' => $timestamp ], [ 'wl_id' => $idsToUpdate, // For paranoia, enforce the CAS time condition here too $casTimeCond ], __METHOD__ ); if ( !$firstBatch ) { $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); } $firstBatch = false; } } while ( $idsToUpdate ); return true; } }