diff options
Diffstat (limited to 'Echo/includes/gateway/UserNotificationGateway.php')
-rw-r--r-- | Echo/includes/gateway/UserNotificationGateway.php | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/Echo/includes/gateway/UserNotificationGateway.php b/Echo/includes/gateway/UserNotificationGateway.php index 7ee23704..d8087715 100644 --- a/Echo/includes/gateway/UserNotificationGateway.php +++ b/Echo/includes/gateway/UserNotificationGateway.php @@ -30,14 +30,20 @@ class EchoUserNotificationGateway { * @var string */ protected static $notificationTable = 'echo_notification'; + /** + * @var Config + */ + private $config; /** * @param User $user * @param MWEchoDbFactory $dbFactory + * @param Config $config */ - public function __construct( User $user, MWEchoDbFactory $dbFactory ) { + public function __construct( User $user, MWEchoDbFactory $dbFactory, Config $config ) { $this->user = $user; $this->dbFactory = $dbFactory; + $this->config = $config; } public function getDB( $dbSource ) { @@ -51,7 +57,6 @@ class EchoUserNotificationGateway { * failure, or when there was nothing to update */ public function markRead( array $eventIDs ) { - global $wgUpdateRowsPerQuery; if ( !$eventIDs ) { return false; } @@ -62,7 +67,9 @@ class EchoUserNotificationGateway { } $success = true; - foreach ( array_chunk( $eventIDs, $wgUpdateRowsPerQuery ) as $batch ) { + foreach ( + array_chunk( $eventIDs, $this->config->get( 'UpdateRowsPerQuery' ) ) as $batch + ) { $success = $dbw->update( self::$notificationTable, [ 'notification_read_timestamp' => $dbw->timestamp( wfTimestampNow() ) ], @@ -85,7 +92,6 @@ class EchoUserNotificationGateway { * failure, or when there was nothing to update */ public function markUnRead( array $eventIDs ) { - global $wgUpdateRowsPerQuery; if ( !$eventIDs ) { return false; } @@ -96,7 +102,9 @@ class EchoUserNotificationGateway { } $success = true; - foreach ( array_chunk( $eventIDs, $wgUpdateRowsPerQuery ) as $batch ) { + foreach ( + array_chunk( $eventIDs, $this->config->get( 'UpdateRowsPerQuery' ) ) as $batch + ) { $success = $dbw->update( self::$notificationTable, [ 'notification_read_timestamp' => null ], @@ -122,7 +130,7 @@ class EchoUserNotificationGateway { return false; } - return $dbw->update( + $dbw->update( self::$notificationTable, [ 'notification_read_timestamp' => $dbw->timestamp( wfTimestampNow() ) ], [ @@ -131,16 +139,22 @@ class EchoUserNotificationGateway { ], __METHOD__ ); + + return true; } /** * Get notification count for the types specified - * @param int $dbSource use master or slave storage to pull count + * @param int $dbSource use master or replica storage to pull count * @param array $eventTypesToLoad event types to retrieve * @param int $cap Max count * @return int */ - public function getCappedNotificationCount( $dbSource, array $eventTypesToLoad = [], $cap = MWEchoNotifUser::MAX_BADGE_COUNT ) { + public function getCappedNotificationCount( + $dbSource, + array $eventTypesToLoad = [], + $cap = MWEchoNotifUser::MAX_BADGE_COUNT + ) { // double check if ( !in_array( $dbSource, [ DB_REPLICA, DB_MASTER ] ) ) { $dbSource = DB_REPLICA; @@ -156,7 +170,7 @@ class EchoUserNotificationGateway { self::$notificationTable, self::$eventTable ], - [ '1' ], + '1', [ 'notification_user' => $this->user->getId(), 'notification_read_timestamp' => null, |