MediaWiki  1.33.0
ClearWatchlistNotificationsJob.php
Go to the documentation of this file.
1 <?php
23 
38  parent::__construct( 'clearWatchlistNotifications', $title, $params );
39 
40  static $required = [ 'userId', 'casTime' ];
41  $missing = implode( ', ', array_diff( $required, array_keys( $this->params ) ) );
42  if ( $missing != '' ) {
43  throw new InvalidArgumentException( "Missing parameter(s) $missing" );
44  }
45 
46  $this->removeDuplicates = true;
47  }
48 
49  public function run() {
50  $services = MediaWikiServices::getInstance();
51  $lbFactory = $services->getDBLoadBalancerFactory();
52  $rowsPerQuery = $services->getMainConfig()->get( 'UpdateRowsPerQuery' );
53 
54  $dbw = $lbFactory->getMainLB()->getConnection( DB_MASTER );
55  $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
56  $timestamp = $this->params['timestamp'] ?? null;
57  if ( $timestamp === null ) {
58  $timestampCond = 'wl_notificationtimestamp IS NOT NULL';
59  } else {
60  $timestamp = $dbw->timestamp( $timestamp );
61  $timestampCond = 'wl_notificationtimestamp != ' . $dbw->addQuotes( $timestamp ) .
62  ' OR wl_notificationtimestamp IS NULL';
63  }
64  // New notifications since the reset should not be cleared
65  $casTimeCond = 'wl_notificationtimestamp < ' .
66  $dbw->addQuotes( $dbw->timestamp( $this->params['casTime'] ) ) .
67  ' OR wl_notificationtimestamp IS NULL';
68 
69  $firstBatch = true;
70  do {
71  $idsToUpdate = $dbw->selectFieldValues(
72  'watchlist',
73  'wl_id',
74  [
75  'wl_user' => $this->params['userId'],
76  $timestampCond,
77  $casTimeCond,
78  ],
79  __METHOD__,
80  [ 'LIMIT' => $rowsPerQuery ]
81  );
82  if ( $idsToUpdate ) {
83  $dbw->update(
84  'watchlist',
85  [ 'wl_notificationtimestamp' => $timestamp ],
86  [
87  'wl_id' => $idsToUpdate,
88  // For paranoia, enforce the CAS time condition here too
89  $casTimeCond
90  ],
91  __METHOD__
92  );
93  if ( !$firstBatch ) {
94  $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
95  }
96  $firstBatch = false;
97  }
98  } while ( $idsToUpdate );
99  return true;
100  }
101 }
Job\$title
Title $title
Definition: Job.php:41
ClearWatchlistNotificationsJob
Job for clearing all of the "last viewed" timestamps for a user's watchlist, or setting them all to t...
Definition: ClearWatchlistNotificationsJob.php:36
Job\$params
array $params
Array of job parameters.
Definition: Job.php:35
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Job
Class to both describe a background job and handle jobs.
Definition: Job.php:30
ClearWatchlistNotificationsJob\__construct
__construct(Title $title, array $params)
Definition: ClearWatchlistNotificationsJob.php:37
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DB_MASTER
const DB_MASTER
Definition: defines.php:26
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Title
Represents a title within MediaWiki.
Definition: Title.php:40
$services
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2220
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
ClearWatchlistNotificationsJob\run
run()
Run the job.
Definition: ClearWatchlistNotificationsJob.php:49