X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWatchedItemStore.php;h=69a9df2d579b5e1771265edf52f09f350d7c8a53;hb=bc12345f4bb7893030c31e1133abc4b20153f59b;hp=70fdbf13af97580f5579dbe64fef55e4f3ea41df;hpb=bf9c2b0cb30cbe994f3a1859cf46224dd52039e1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index 70fdbf13af..69a9df2d57 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -7,6 +7,7 @@ use MediaWiki\MediaWikiServices; use Wikimedia\Assert\Assert; use Wikimedia\ScopedCallback; use Wikimedia\Rdbms\LoadBalancer; +use Wikimedia\Rdbms\DBUnexpectedError; /** * Storage layer class for WatchedItems. @@ -29,6 +30,11 @@ class WatchedItemStore implements StatsdAwareInterface { */ private $loadBalancer; + /** + * @var ReadOnlyMode + */ + private $readOnlyMode; + /** * @var HashBagOStuff */ @@ -60,13 +66,16 @@ class WatchedItemStore implements StatsdAwareInterface { /** * @param LoadBalancer $loadBalancer * @param HashBagOStuff $cache + * @param ReadOnlyMode $readOnlyMode */ public function __construct( LoadBalancer $loadBalancer, - HashBagOStuff $cache + HashBagOStuff $cache, + ReadOnlyMode $readOnlyMode ) { $this->loadBalancer = $loadBalancer; $this->cache = $cache; + $this->readOnlyMode = $readOnlyMode; $this->stats = new NullStatsdDataFactory(); $this->deferredUpdatesAddCallableUpdateCallback = [ 'DeferredUpdates', 'addCallableUpdate' ]; $this->revisionGetTimestampFromIdCallback = [ 'Revision', 'getTimestampFromId' ]; @@ -95,7 +104,7 @@ class WatchedItemStore implements StatsdAwareInterface { } $previousValue = $this->deferredUpdatesAddCallableUpdateCallback; $this->deferredUpdatesAddCallableUpdateCallback = $callback; - return new ScopedCallback( function() use ( $previousValue ) { + return new ScopedCallback( function () use ( $previousValue ) { $this->deferredUpdatesAddCallableUpdateCallback = $previousValue; } ); } @@ -118,7 +127,7 @@ class WatchedItemStore implements StatsdAwareInterface { } $previousValue = $this->revisionGetTimestampFromIdCallback; $this->revisionGetTimestampFromIdCallback = $callback; - return new ScopedCallback( function() use ( $previousValue ) { + return new ScopedCallback( function () use ( $previousValue ) { $this->revisionGetTimestampFromIdCallback = $previousValue; } ); } @@ -458,7 +467,7 @@ class WatchedItemStore implements StatsdAwareInterface { $item = new WatchedItem( $user, $target, - $row->wl_notificationtimestamp + wfTimestampOrNull( TS_MW, $row->wl_notificationtimestamp ) ); $this->cache( $item ); @@ -572,7 +581,8 @@ class WatchedItemStore implements StatsdAwareInterface { ); foreach ( $res as $row ) { - $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp; + $timestamps[$row->wl_namespace][$row->wl_title] = + wfTimestampOrNull( TS_MW, $row->wl_notificationtimestamp ); } return $timestamps; @@ -595,7 +605,7 @@ class WatchedItemStore implements StatsdAwareInterface { * @return bool success */ public function addWatchBatchForUser( User $user, array $targets ) { - if ( $this->loadBalancer->getReadOnlyReason() !== false ) { + if ( $this->readOnlyMode->isReadOnly() ) { return false; } // Only loggedin user can have a watchlist @@ -653,7 +663,7 @@ class WatchedItemStore implements StatsdAwareInterface { */ public function removeWatch( User $user, LinkTarget $target ) { // Only logged in user can have a watchlist - if ( $this->loadBalancer->getReadOnlyReason() !== false || $user->isAnon() ) { + if ( $this->readOnlyMode->isReadOnly() || $user->isAnon() ) { return false; } @@ -784,7 +794,7 @@ class WatchedItemStore implements StatsdAwareInterface { */ public function resetNotificationTimestamp( User $user, Title $title, $force = '', $oldid = 0 ) { // Only loggedin user can have a watchlist - if ( $this->loadBalancer->getReadOnlyReason() !== false || $user->isAnon() ) { + if ( $this->readOnlyMode->isReadOnly() || $user->isAnon() ) { return false; } @@ -811,7 +821,7 @@ class WatchedItemStore implements StatsdAwareInterface { // Calls DeferredUpdates::addCallableUpdate in normal operation call_user_func( $this->deferredUpdatesAddCallableUpdateCallback, - function() use ( $job ) { + function () use ( $job ) { $job->run(); } );