From 05ca28bba0e65e17428d274043a8b765d08583eb Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 16 Dec 2016 14:31:24 -0500 Subject: [PATCH] WatchedItemStore::setNotificationTimestampsForUser(): Allow clearing timestamp ApiSetNotificationTimestamp expects to be able to clear the timestamp by passing null. Allow that to work as expected. Bug: T153482 Change-Id: Ibf4ba56f0abd3b72283f7a33e4665d5999a70b82 --- includes/WatchedItemStore.php | 8 +++-- .../includes/WatchedItemStoreUnitTest.php | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index cc4779ef38..3cdc59cda0 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -668,7 +668,7 @@ class WatchedItemStore implements StatsdAwareInterface { /** * @param User $user The user to set the timestamp for - * @param string $timestamp Set the update timestamp to this value + * @param string|null $timestamp Set the update timestamp to this value * @param LinkTarget[] $targets List of targets to update. Default to all targets * * @return bool success @@ -687,9 +687,13 @@ class WatchedItemStore implements StatsdAwareInterface { $conds[] = $batch->constructSet( 'wl', $dbw ); } + if ( $timestamp !== null ) { + $timestamp = $dbw->timestamp( $timestamp ); + } + $success = $dbw->update( 'watchlist', - [ 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp ) ], + [ 'wl_notificationtimestamp' => $timestamp ], $conds, __METHOD__ ); diff --git a/tests/phpunit/includes/WatchedItemStoreUnitTest.php b/tests/phpunit/includes/WatchedItemStoreUnitTest.php index ba4705970c..0bd0bccbf4 100644 --- a/tests/phpunit/includes/WatchedItemStoreUnitTest.php +++ b/tests/phpunit/includes/WatchedItemStoreUnitTest.php @@ -2404,6 +2404,35 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { ); } + public function testSetNotificationTimestampsForUser_nullTimestamp() { + $user = $this->getMockNonAnonUserWithId( 1 ); + $timestamp = null; + + $mockDb = $this->getMockDb(); + $mockDb->expects( $this->once() ) + ->method( 'update' ) + ->with( + 'watchlist', + [ 'wl_notificationtimestamp' => null ], + [ 'wl_user' => 1 ] + ) + ->will( $this->returnValue( true ) ); + $mockDb->expects( $this->exactly( 0 ) ) + ->method( 'timestamp' ) + ->will( $this->returnCallback( function( $value ) { + return 'TS' . $value . 'TS'; + } ) ); + + $store = $this->newWatchedItemStore( + $this->getMockLoadBalancer( $mockDb ), + $this->getMockCache() + ); + + $this->assertTrue( + $store->setNotificationTimestampsForUser( $user, $timestamp ) + ); + } + public function testSetNotificationTimestampsForUser_specificTargets() { $user = $this->getMockNonAnonUserWithId( 1 ); $timestamp = '20100101010101'; -- 2.20.1