Flow is the only thing remaining that uses this deprecated method.
Change-Id: Iaa4e1e34cb3f2a91c163565fb0107c500e3852d7
** WatchedItem::removeWatch was deprecated.
** WatchedItem::isWatched was deprecated.
** WatchedItem::duplicateEntries was deprecated.
+** EmailNotification::updateWatchlistTimestamp was deprecated.
** User::getWatchedItem was removed.
== Compatibility ==
return $success;
}
+ /**
+ * @param User $editor The editor that triggered the update. Their notification
+ * timestamp will not be updated(they have already seen it)
+ * @param LinkTarget $target The target to update timestamps for
+ * @param string $timestamp Set the update timestamp to this value
+ *
+ * @return int[] Array of user IDs the timestamp has been updated for
+ */
+ public function updateNotificationTimestamp( User $editor, LinkTarget $target, $timestamp ) {
+ $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 'watchlist' ] );
+ $res = $dbw->select( [ 'watchlist' ],
+ [ 'wl_user' ],
+ [
+ 'wl_user != ' . intval( $editor->getId() ),
+ 'wl_namespace' => $target->getNamespace(),
+ 'wl_title' => $target->getDBkey(),
+ 'wl_notificationtimestamp IS NULL',
+ ], __METHOD__
+ );
+
+ $watchers = [];
+ foreach ( $res as $row ) {
+ $watchers[] = intval( $row->wl_user );
+ }
+
+ if ( $watchers ) {
+ // Update wl_notificationtimestamp for all watching users except the editor
+ $fname = __METHOD__;
+ $dbw->onTransactionIdle(
+ function () use ( $dbw, $timestamp, $watchers, $target, $fname ) {
+ $dbw->update( 'watchlist',
+ [ /* SET */
+ 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
+ ], [ /* WHERE */
+ 'wl_user' => $watchers,
+ 'wl_namespace' => $target->getNamespace(),
+ 'wl_title' => $target->getDBkey(),
+ ], $fname
+ );
+ }
+ );
+ }
+
+ $this->loadBalancer->reuseConnection( $dbw );
+
+ return $watchers;
+ }
+
/**
* Reset the notification timestamp of this entry
*
protected $editor;
/**
+ * @deprecated since 1.27 use WatchedItemStore::updateNotificationTimestamp directly
+ *
* @param User $editor The editor that triggered the update. Their notification
* timestamp will not be updated(they have already seen it)
* @param LinkTarget $linkTarget The link target of the title to update timestamps for
* @param string $timestamp Set the update timestamp to this value
+ *
* @return int[] Array of user IDs
*/
public static function updateWatchlistTimestamp(
LinkTarget $linkTarget,
$timestamp
) {
- global $wgEnotifWatchlist, $wgShowUpdatedMarker;
-
- if ( !$wgEnotifWatchlist && !$wgShowUpdatedMarker ) {
+ // wfDeprecated( __METHOD__, '1.27' );
+ $config = RequestContext::getMain()->getConfig();
+ if ( !$config->get( 'EnotifWatchlist' ) && !$config->get( 'ShowUpdatedMarker' ) ) {
return [];
}
-
- $dbw = wfGetDB( DB_MASTER );
- $res = $dbw->select( [ 'watchlist' ],
- [ 'wl_user' ],
- [
- 'wl_user != ' . intval( $editor->getID() ),
- 'wl_namespace' => $linkTarget->getNamespace(),
- 'wl_title' => $linkTarget->getDBkey(),
- 'wl_notificationtimestamp IS NULL',
- ], __METHOD__
+ return WatchedItemStore::getDefaultInstance()->updateNotificationTimestamp(
+ $editor,
+ $linkTarget,
+ $timestamp
);
-
- $watchers = [];
- foreach ( $res as $row ) {
- $watchers[] = intval( $row->wl_user );
- }
-
- if ( $watchers ) {
- // Update wl_notificationtimestamp for all watching users except the editor
- $fname = __METHOD__;
- $dbw->onTransactionIdle(
- function () use ( $dbw, $timestamp, $watchers, $linkTarget, $fname ) {
- $dbw->update( 'watchlist',
- [ /* SET */
- 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
- ], [ /* WHERE */
- 'wl_user' => $watchers,
- 'wl_namespace' => $linkTarget->getNamespace(),
- 'wl_title' => $linkTarget->getDBkey(),
- ], $fname
- );
- }
- );
- }
-
- return $watchers;
}
/**
}
// update wl_notificationtimestamp for watchers
- $watchers = self::updateWatchlistTimestamp( $editor, $title, $timestamp );
+ $config = RequestContext::getMain()->getConfig();
+ $watchers = [];
+ if ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) ) {
+ $watchers = WatchedItemStore::getDefaultInstance()->updateNotificationTimestamp(
+ $editor,
+ $title,
+ $timestamp
+ );
+ }
$sendEmail = true;
// $watchers deals with $wgEnotifWatchlist.
);
}
- public function testResetNotificationTimestamp() {
+ public function testUpdateAndResetNotificationTimestamp() {
$user = $this->getUser();
$otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
$title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
$store = WatchedItemStore::getDefaultInstance();
$store->addWatch( $user, $title );
- EmailNotification::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' );
+ $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
+
+ $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
+ $this->assertEquals(
+ '20150202010101',
+ $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
+ );
- $this->assertNotNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
$this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
$this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
}
$this->assertEquals( 1, $getTimestampCallCounter );
}
+ public function testUpdateNotificationTimestamp_watchersExist() {
+ $mockDb = $this->getMockDb();
+ $mockDb->expects( $this->once() )
+ ->method( 'select' )
+ ->with(
+ [ 'watchlist' ],
+ [ 'wl_user' ],
+ [
+ 'wl_user != 1',
+ 'wl_namespace' => 0,
+ 'wl_title' => 'SomeDbKey',
+ 'wl_notificationtimestamp IS NULL'
+ ]
+ )
+ ->will(
+ $this->returnValue( [
+ $this->getFakeRow( [ 'wl_user' => '2' ] ),
+ $this->getFakeRow( [ 'wl_user' => '3' ] )
+ ] )
+ );
+ $mockDb->expects( $this->once() )
+ ->method( 'onTransactionIdle' )
+ ->with( $this->isType( 'callable' ) )
+ ->will( $this->returnCallback( function( $callable ) {
+ $callable();
+ } ) );
+ $mockDb->expects( $this->once() )
+ ->method( 'update' )
+ ->with(
+ 'watchlist',
+ [ 'wl_notificationtimestamp' => null ],
+ [
+ 'wl_user' => [ 2, 3 ],
+ 'wl_namespace' => 0,
+ 'wl_title' => 'SomeDbKey',
+ ]
+ );
+
+ $store = new WatchedItemStore(
+ $this->getMockLoadBalancer( $mockDb ),
+ new HashBagOStuff( [ 'maxKeys' => 100 ] )
+ );
+
+ $this->assertEquals(
+ [ 2, 3 ],
+ $store->updateNotificationTimestamp(
+ $this->getMockNonAnonUserWithId( 1 ),
+ new TitleValue( 0, 'SomeDbKey' ),
+ '20151212010101'
+ )
+ );
+ }
+
+ public function testUpdateNotificationTimestamp_noWatchers() {
+ $mockDb = $this->getMockDb();
+ $mockDb->expects( $this->once() )
+ ->method( 'select' )
+ ->with(
+ [ 'watchlist' ],
+ [ 'wl_user' ],
+ [
+ 'wl_user != 1',
+ 'wl_namespace' => 0,
+ 'wl_title' => 'SomeDbKey',
+ 'wl_notificationtimestamp IS NULL'
+ ]
+ )
+ ->will(
+ $this->returnValue( [] )
+ );
+ $mockDb->expects( $this->never() )
+ ->method( 'onTransactionIdle' );
+ $mockDb->expects( $this->never() )
+ ->method( 'update' );
+
+ $store = new WatchedItemStore(
+ $this->getMockLoadBalancer( $mockDb ),
+ new HashBagOStuff( [ 'maxKeys' => 100 ] )
+ );
+
+ $watchers = $store->updateNotificationTimestamp(
+ $this->getMockNonAnonUserWithId( 1 ),
+ new TitleValue( 0, 'SomeDbKey' ),
+ '20151212010101'
+ );
+ $this->assertInternalType( 'array', $watchers );
+ $this->assertEmpty( $watchers );
+ }
+
}