MediaWiki REL1_39
ActivityUpdateJob.php
Go to the documentation of this file.
1<?php
24
37class ActivityUpdateJob extends Job {
42 public function __construct( $title, array $params ) {
43 // If we know its a PageReference, we could just pass that to the parent
44 // constructor, but its simpler to just extract namespace and dbkey, and
45 // that works for both LinkTarget and PageReference
46 $params['namespace'] = $title->getNamespace();
47 $params['title'] = $title->getDBkey();
48
49 parent::__construct( 'activityUpdateJob', $params );
50
51 static $required = [ 'type', 'userid', 'notifTime', 'curTime' ];
52 $missing = implode( ', ', array_diff( $required, array_keys( $this->params ) ) );
53 if ( $missing != '' ) {
54 throw new InvalidArgumentException( "Missing parameter(s) $missing" );
55 }
56
57 $this->removeDuplicates = true;
58 }
59
60 public function run() {
61 if ( $this->params['type'] === 'updateWatchlistNotification' ) {
63 } else {
64 throw new InvalidArgumentException( "Invalid 'type' '{$this->params['type']}'." );
65 }
66
67 return true;
68 }
69
70 protected function updateWatchlistNotification() {
71 $casTimestamp = $this->params['notifTime'] ?? $this->params['curTime'];
72
73 $dbw = wfGetDB( DB_PRIMARY );
74 // Add a "check and set" style comparison to handle conflicts.
75 // The inequality always avoids updates when the current value
76 // is already NULL per ANSI SQL. This is desired since NULL means
77 // that the user is "caught up" on edits already. When the field
78 // is non-NULL, make sure not to set it back in time or set it to
79 // NULL when newer revisions were in fact added to the page.
80 $casTimeCond = 'wl_notificationtimestamp < ' . $dbw->addQuotes( $dbw->timestamp( $casTimestamp ) );
81
82 // select primary key first instead of directly update to avoid deadlocks per T204561
83 $wlId = $dbw->selectField(
84 'watchlist',
85 'wl_id',
86 [
87 'wl_user' => $this->params['userid'],
88 'wl_namespace' => $this->title->getNamespace(),
89 'wl_title' => $this->title->getDBkey(),
90 $casTimeCond
91 ],
92 __METHOD__
93 );
94
95 if ( !$wlId ) {
96 return;
97 }
98
99 $dbw->update(
100 'watchlist',
101 [ 'wl_notificationtimestamp' => $dbw->timestampOrNull( $this->params['notifTime'] ) ],
102 [
103 'wl_id' => (int)$wlId,
104 // For paranoia, enforce the CAS time condition here too
105 $casTimeCond
106 ],
107 __METHOD__
108 );
109 }
110}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Job for updating user activity like "last viewed" timestamps.
__construct( $title, array $params)
Class to both describe a background job and handle jobs.
Definition Job.php:39
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
const DB_PRIMARY
Definition defines.php:28