EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/159115
Change subject: Mark notifications as read if they fail rendering
......................................................................
Mark notifications as read if they fail rendering
Change-Id: I585b4cc185bf859ddb06829df75309ff3d56d8b8
---
M Echo.php
M controller/NotificationController.php
A includes/DeferredMarkAsReadUpdate.php
3 files changed, 68 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/15/159115/1
diff --git a/Echo.php b/Echo.php
index f5e87d0..aae4656 100644
--- a/Echo.php
+++ b/Echo.php
@@ -109,6 +109,9 @@
$wgAutoloadClasses['MWEchoNotificationEmailBundleJob'] = $dir .
'jobs/NotificationEmailBundleJob.php';
$wgJobClasses['MWEchoNotificationEmailBundleJob'] =
'MWEchoNotificationEmailBundleJob';
+// Deferred execution
+$wgAutoloadClasses['EchoDeferredMarkAsReadUpdate'] = $dir .
'/includes/EchoDeferredMarkAsReadUpdate.php';
+
// API
$wgAutoloadClasses['ApiEchoNotifications'] = $dir .
'api/ApiEchoNotifications.php';
$wgAPIMetaModules['notifications'] = 'ApiEchoNotifications';
diff --git a/controller/NotificationController.php
b/controller/NotificationController.php
index 68b7393..2a69dfa 100644
--- a/controller/NotificationController.php
+++ b/controller/NotificationController.php
@@ -19,6 +19,13 @@
static protected $userWhitelist;
/**
+ * Queue's that failed formatting and marks them as read at end of
request.
+ *
+ * @var DeferredMarkAsReadUpdate|null
+ */
+ protected $markAsRead;
+
+ /**
* Format the notification count with Language::formatNum(). In
addition, for large count,
* return abbreviated version, e.g. 99+
*
@@ -330,12 +337,26 @@
restore_error_handler();
}
- if ( $res ) {
- return $res;
- } else {
- return Xml::tags( 'span', array( 'class' => 'error' ),
- wfMessage( 'echo-error-no-formatter',
$event->getType() )->escaped() );
+ if ( $res === '' ) {
+ self::failFormatting( $event, $user );
}
+
+ return $res;
+ }
+
+ /**
+ * Event has failed to format for the given user. Mark it as read so
+ * we do not continue to notify them about this broken event.
+ *
+ * @param EchoEvent $event
+ * @param User $user
+ */
+ protected static function failFormatting( EchoEvent $event, $user ) {
+ if ( self::$markAsRead === null ) {
+ self::$markAsRead = new EchoDeferredMarkAsReadUpdate();
+ DeferredUpdates::addUpdate( self::$markAsRead );
+ }
+ self::$markAsRead->add( $event, $user );
}
/**
diff --git a/includes/DeferredMarkAsReadUpdate.php
b/includes/DeferredMarkAsReadUpdate.php
new file mode 100644
index 0000000..46fa862
--- /dev/null
+++ b/includes/DeferredMarkAsReadUpdate.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Mark event notifications as read at the end of a request. Used to queue up
+ * individual events to mark due to formatting failures or other uses.
+ */
+class EchoDeferredMarkAsReadUpdate implements DeferrableUpdate {
+ /**
+ * @var array
+ */
+ protected $events = array();
+
+ /**
+ * @param EchoEvent $event
+ * @param User $user
+ */
+ public function add( EchoEvent $event, $user ) {
+ $uid = $user->getId();
+ if ( isset( $this->events[$uid] ) ) {
+ $this->events[$uid]['eventIds'][] = $event->getId();
+ } else {
+ $this->events[$uid] = array(
+ 'user' => $user,
+ 'eventIds' => array( $event->getId() ),
+ );
+ }
+ }
+
+ /**
+ * Mark's all queue'd notifications as read.
+ * Satisfies DeferrableUpdate interface
+ */
+ public function doUpdate() {
+ foreach ( $this->events as $data ) {
+ MWEchoNotifUser::newFromUser( $data['user']
)->markRead( $data['eventIds'] );
+ }
+ $this->events = array();
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/159115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I585b4cc185bf859ddb06829df75309ff3d56d8b8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits