/** * Reset the notification timestamp of this entry * * @param bool $force Whether to force the write query to be executed even if the * page is not watched or the notification timestamp is already NULL. * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed. * @mode int $mode WatchedItem::DEFERRED/IMMEDIATE */ public function resetNotificationTimestamp($force = '', $oldid = 0, $mode = self::IMMEDIATE) { // Only loggedin user can have a watchlist if (wfReadOnly() || $this->mUser->isAnon() || !$this->isAllowed('editmywatchlist')) { return; } if ($force != 'force') { $this->load(); if (!$this->watched || $this->timestamp === null) { return; } } $title = $this->getTitle(); if (!$oldid) { // No oldid given, assuming latest revision; clear the timestamp. $notificationTimestamp = null; } elseif (!$title->getNextRevisionID($oldid)) { // Oldid given and is the latest revision for this title; clear the timestamp. $notificationTimestamp = null; } else { // See if the version marked as read is more recent than the one we're viewing. // Call load() if it wasn't called before due to $force. $this->load(); if ($this->timestamp === null) { // This can only happen if $force is enabled. $notificationTimestamp = null; } else { // Oldid given and isn't the latest; update the timestamp. // This will result in no further notification emails being sent! $notificationTimestamp = Revision::getTimestampFromId($title, $oldid); // We need to go one second to the future because of various strict comparisons // throughout the codebase $ts = new MWTimestamp($notificationTimestamp); $ts->timestamp->add(new DateInterval('PT1S')); $notificationTimestamp = $ts->getTimestamp(TS_MW); if ($notificationTimestamp < $this->timestamp) { if ($force != 'force') { return; } else { // This is a little silly… $notificationTimestamp = $this->timestamp; } } } } // If the page is watched by the user (or may be watched), update the timestamp if ($mode === self::DEFERRED) { $job = new ActivityUpdateJob($title, array('type' => 'updateWatchlistNotification', 'userid' => $this->getUserId(), 'notifTime' => $notificationTimestamp, 'curTime' => time())); // Try to run this post-send DeferredUpdates::addCallableUpdate(function () use($job) { $job->run(); }); } else { $dbw = wfGetDB(DB_MASTER); $dbw->update('watchlist', array('wl_notificationtimestamp' => $dbw->timestampOrNull($notificationTimestamp)), $this->dbCond(), __METHOD__); } $this->timestamp = null; }
/** * Reset the notification timestamp of this entry * * @param User $user * @param Title $title * @param string $force Whether to force the write query to be executed even if the * page is not watched or the notification timestamp is already NULL. * 'force' in order to force * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed. * * @return bool success */ public function resetNotificationTimestamp(User $user, Title $title, $force = '', $oldid = 0) { // Only loggedin user can have a watchlist if ($this->loadBalancer->getReadOnlyReason() !== false || $user->isAnon()) { return false; } $item = null; if ($force != 'force') { $item = $this->loadWatchedItem($user, $title); if (!$item || $item->getNotificationTimestamp() === null) { return false; } } // If the page is watched by the user (or may be watched), update the timestamp $job = new ActivityUpdateJob($title, ['type' => 'updateWatchlistNotification', 'userid' => $user->getId(), 'notifTime' => $this->getNotificationTimestamp($user, $title, $item, $force, $oldid), 'curTime' => time()]); // Try to run this post-send // Calls DeferredUpdates::addCallableUpdate in normal operation call_user_func($this->deferredUpdatesAddCallableUpdateCallback, function () use($job) { $job->run(); }); $this->uncache($user, $title); return true; }