[MediaWiki-commits] [Gerrit] Allow the primary link to set all bundled notifications as read - change (mediawiki...Echo)

2016-06-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Allow the primary link to set all bundled notifications as read
..


Allow the primary link to set all bundled notifications as read

Bug: T136368
Change-Id: If07369cb168d1a085f297293e713d65e49997264
(cherry picked from commit b06b2294c9e7897ec709fb1c21a9be24b8b65a93)
---
M Hooks.php
M includes/formatters/EventPresentationModel.php
M includes/mapper/NotificationMapper.php
3 files changed, 54 insertions(+), 21 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Hooks.php b/Hooks.php
index 156c54b..e75f3f9 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -799,20 +799,37 @@
}
}
}
-   // Attempt to mark as read the event ID in the ?markasread= 
parameter, if present
-   $markAsReadId = $sk->getOutput()->getRequest()->getInt( 
'markasread' );
-   if ( $markAsReadId !== 0 && !in_array( $markAsReadId, $eventIds 
) ) {
-   $notifMapper = new EchoNotificationMapper();
-   $notif = $notifMapper->fetchByUserEvent( $user, 
$markAsReadId );
-   if ( $notif && !$notif->getReadTimestamp() ) {
-   if ( $notif->getEvent()->getSection() === 
EchoAttributeManager::MESSAGE ) {
-   $subtractMessages++;
-   } else {
-   $subtractAlerts++;
+
+   // Attempt to mark as read the event IDs in the ?markasread= 
parameter, if present
+   $markAsReadIds = explode( '|', 
$sk->getOutput()->getRequest()->getText( 'markasread' ) );
+   if ( $markAsReadIds ) {
+   // gather the IDs that we didn't already find with 
target_pages
+   $eventsToMarkAsRead = array();
+   foreach ( $markAsReadIds as $markAsReadId ) {
+   $markAsReadId = intval( $markAsReadId );
+   if ( $markAsReadId !== 0 && !in_array( 
$markAsReadId, $eventIds ) ) {
+   $eventsToMarkAsRead[] = $markAsReadId;
}
-   $eventIds[] = $markAsReadId;
+   }
+
+   if ( $eventsToMarkAsRead ) {
+   // fetch the notifications to adjust the 
counters
+   $notifMapper = new EchoNotificationMapper();
+   $notifs = $notifMapper->fetchByUserEvents( 
$user, $eventsToMarkAsRead );
+
+   foreach ( $notifs as $notif ) {
+   if ( !$notif->getReadTimestamp() ) {
+   if ( 
$notif->getEvent()->getSection() === EchoAttributeManager::MESSAGE ) {
+   $subtractMessages++;
+   } else {
+   $subtractAlerts++;
+   }
+   $eventIds[] = intval( 
$notif->getEvent()->getId() );
+   }
+   }
}
}
+
if ( $eventIds ) {
DeferredUpdates::addCallableUpdate( function () use ( 
$user, $eventIds ) {
$notifUser = MWEchoNotifUser::newFromUser( 
$user );
diff --git a/includes/formatters/EventPresentationModel.php 
b/includes/formatters/EventPresentationModel.php
index 691e013..7a95c9d 100644
--- a/includes/formatters/EventPresentationModel.php
+++ b/includes/formatters/EventPresentationModel.php
@@ -406,12 +406,20 @@
/**
 * Like getPrimaryLink(), but with the URL altered to add 
?markasread=XYZ. When this link is followed,
 * the notification is marked as read.
+*
+* When the notification is a bundle, the notification IDs are added to 
the parameter value
+* separated by a "|".
+*
 * @return array|bool
 */
public function getPrimaryLinkWithMarkAsRead() {
$primaryLink = $this->getPrimaryLink();
if ( $primaryLink ) {
-   $primaryLink['url'] = wfAppendQuery( 
$primaryLink['url'], array( 'markasread' => $this->event->getId() ) );
+   $eventIds = array( $this->event->getId() );
+   if ( $this->getBundledIds() ) {
+   $eventIds = array_merge( $eventIds, 
$this->getBundledIds() );
+   }
+   $primaryLink['url'] = wfAppendQuery( 
$primaryLink['url'], 

[MediaWiki-commits] [Gerrit] Allow the primary link to set all bundled notifications as read - change (mediawiki...Echo)

2016-06-14 Thread Catrope (Code Review)
Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/294339

Change subject: Allow the primary link to set all bundled notifications as read
..

Allow the primary link to set all bundled notifications as read

Bug: T136368
Change-Id: If07369cb168d1a085f297293e713d65e49997264
(cherry picked from commit b06b2294c9e7897ec709fb1c21a9be24b8b65a93)
---
M Hooks.php
M includes/formatters/EventPresentationModel.php
M includes/mapper/NotificationMapper.php
3 files changed, 54 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/39/294339/1

diff --git a/Hooks.php b/Hooks.php
index 156c54b..e75f3f9 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -799,20 +799,37 @@
}
}
}
-   // Attempt to mark as read the event ID in the ?markasread= 
parameter, if present
-   $markAsReadId = $sk->getOutput()->getRequest()->getInt( 
'markasread' );
-   if ( $markAsReadId !== 0 && !in_array( $markAsReadId, $eventIds 
) ) {
-   $notifMapper = new EchoNotificationMapper();
-   $notif = $notifMapper->fetchByUserEvent( $user, 
$markAsReadId );
-   if ( $notif && !$notif->getReadTimestamp() ) {
-   if ( $notif->getEvent()->getSection() === 
EchoAttributeManager::MESSAGE ) {
-   $subtractMessages++;
-   } else {
-   $subtractAlerts++;
+
+   // Attempt to mark as read the event IDs in the ?markasread= 
parameter, if present
+   $markAsReadIds = explode( '|', 
$sk->getOutput()->getRequest()->getText( 'markasread' ) );
+   if ( $markAsReadIds ) {
+   // gather the IDs that we didn't already find with 
target_pages
+   $eventsToMarkAsRead = array();
+   foreach ( $markAsReadIds as $markAsReadId ) {
+   $markAsReadId = intval( $markAsReadId );
+   if ( $markAsReadId !== 0 && !in_array( 
$markAsReadId, $eventIds ) ) {
+   $eventsToMarkAsRead[] = $markAsReadId;
}
-   $eventIds[] = $markAsReadId;
+   }
+
+   if ( $eventsToMarkAsRead ) {
+   // fetch the notifications to adjust the 
counters
+   $notifMapper = new EchoNotificationMapper();
+   $notifs = $notifMapper->fetchByUserEvents( 
$user, $eventsToMarkAsRead );
+
+   foreach ( $notifs as $notif ) {
+   if ( !$notif->getReadTimestamp() ) {
+   if ( 
$notif->getEvent()->getSection() === EchoAttributeManager::MESSAGE ) {
+   $subtractMessages++;
+   } else {
+   $subtractAlerts++;
+   }
+   $eventIds[] = intval( 
$notif->getEvent()->getId() );
+   }
+   }
}
}
+
if ( $eventIds ) {
DeferredUpdates::addCallableUpdate( function () use ( 
$user, $eventIds ) {
$notifUser = MWEchoNotifUser::newFromUser( 
$user );
diff --git a/includes/formatters/EventPresentationModel.php 
b/includes/formatters/EventPresentationModel.php
index 691e013..7a95c9d 100644
--- a/includes/formatters/EventPresentationModel.php
+++ b/includes/formatters/EventPresentationModel.php
@@ -406,12 +406,20 @@
/**
 * Like getPrimaryLink(), but with the URL altered to add 
?markasread=XYZ. When this link is followed,
 * the notification is marked as read.
+*
+* When the notification is a bundle, the notification IDs are added to 
the parameter value
+* separated by a "|".
+*
 * @return array|bool
 */
public function getPrimaryLinkWithMarkAsRead() {
$primaryLink = $this->getPrimaryLink();
if ( $primaryLink ) {
-   $primaryLink['url'] = wfAppendQuery( 
$primaryLink['url'], array( 'markasread' => $this->event->getId() ) );
+   $eventIds = array( $this->event->getId() );
+   if ( $this->getBundledIds() ) {
+   $eventIds = array_merge( $eventIds, 
$this->getBundledIds() );
+   }
+   

[MediaWiki-commits] [Gerrit] Allow the primary link to set all bundled notifications as read - change (mediawiki...Echo)

2016-06-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Allow the primary link to set all bundled notifications as read
..


Allow the primary link to set all bundled notifications as read

Bug: T136368
Change-Id: If07369cb168d1a085f297293e713d65e49997264
---
M Hooks.php
M includes/formatters/EventPresentationModel.php
M includes/mapper/NotificationMapper.php
3 files changed, 54 insertions(+), 21 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Hooks.php b/Hooks.php
index 156c54b..e75f3f9 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -799,20 +799,37 @@
}
}
}
-   // Attempt to mark as read the event ID in the ?markasread= 
parameter, if present
-   $markAsReadId = $sk->getOutput()->getRequest()->getInt( 
'markasread' );
-   if ( $markAsReadId !== 0 && !in_array( $markAsReadId, $eventIds 
) ) {
-   $notifMapper = new EchoNotificationMapper();
-   $notif = $notifMapper->fetchByUserEvent( $user, 
$markAsReadId );
-   if ( $notif && !$notif->getReadTimestamp() ) {
-   if ( $notif->getEvent()->getSection() === 
EchoAttributeManager::MESSAGE ) {
-   $subtractMessages++;
-   } else {
-   $subtractAlerts++;
+
+   // Attempt to mark as read the event IDs in the ?markasread= 
parameter, if present
+   $markAsReadIds = explode( '|', 
$sk->getOutput()->getRequest()->getText( 'markasread' ) );
+   if ( $markAsReadIds ) {
+   // gather the IDs that we didn't already find with 
target_pages
+   $eventsToMarkAsRead = array();
+   foreach ( $markAsReadIds as $markAsReadId ) {
+   $markAsReadId = intval( $markAsReadId );
+   if ( $markAsReadId !== 0 && !in_array( 
$markAsReadId, $eventIds ) ) {
+   $eventsToMarkAsRead[] = $markAsReadId;
}
-   $eventIds[] = $markAsReadId;
+   }
+
+   if ( $eventsToMarkAsRead ) {
+   // fetch the notifications to adjust the 
counters
+   $notifMapper = new EchoNotificationMapper();
+   $notifs = $notifMapper->fetchByUserEvents( 
$user, $eventsToMarkAsRead );
+
+   foreach ( $notifs as $notif ) {
+   if ( !$notif->getReadTimestamp() ) {
+   if ( 
$notif->getEvent()->getSection() === EchoAttributeManager::MESSAGE ) {
+   $subtractMessages++;
+   } else {
+   $subtractAlerts++;
+   }
+   $eventIds[] = intval( 
$notif->getEvent()->getId() );
+   }
+   }
}
}
+
if ( $eventIds ) {
DeferredUpdates::addCallableUpdate( function () use ( 
$user, $eventIds ) {
$notifUser = MWEchoNotifUser::newFromUser( 
$user );
diff --git a/includes/formatters/EventPresentationModel.php 
b/includes/formatters/EventPresentationModel.php
index 691e013..7a95c9d 100644
--- a/includes/formatters/EventPresentationModel.php
+++ b/includes/formatters/EventPresentationModel.php
@@ -406,12 +406,20 @@
/**
 * Like getPrimaryLink(), but with the URL altered to add 
?markasread=XYZ. When this link is followed,
 * the notification is marked as read.
+*
+* When the notification is a bundle, the notification IDs are added to 
the parameter value
+* separated by a "|".
+*
 * @return array|bool
 */
public function getPrimaryLinkWithMarkAsRead() {
$primaryLink = $this->getPrimaryLink();
if ( $primaryLink ) {
-   $primaryLink['url'] = wfAppendQuery( 
$primaryLink['url'], array( 'markasread' => $this->event->getId() ) );
+   $eventIds = array( $this->event->getId() );
+   if ( $this->getBundledIds() ) {
+   $eventIds = array_merge( $eventIds, 
$this->getBundledIds() );
+   }
+   $primaryLink['url'] = wfAppendQuery( 
$primaryLink['url'], array( 'markasread' => implode( '|', $eventIds ) ) );
}
 

[MediaWiki-commits] [Gerrit] Allow the primary link to set all bundled notifications as read - change (mediawiki...Echo)

2016-06-13 Thread Sbisson (Code Review)
Sbisson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/294120

Change subject: Allow the primary link to set all bundled notifications as read
..

Allow the primary link to set all bundled notifications as read

Bug: T136368
Change-Id: If07369cb168d1a085f297293e713d65e49997264
---
M Hooks.php
M includes/formatters/EventPresentationModel.php
M includes/mapper/NotificationMapper.php
3 files changed, 53 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/20/294120/1

diff --git a/Hooks.php b/Hooks.php
index 156c54b..e75f3f9 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -799,20 +799,37 @@
}
}
}
-   // Attempt to mark as read the event ID in the ?markasread= 
parameter, if present
-   $markAsReadId = $sk->getOutput()->getRequest()->getInt( 
'markasread' );
-   if ( $markAsReadId !== 0 && !in_array( $markAsReadId, $eventIds 
) ) {
-   $notifMapper = new EchoNotificationMapper();
-   $notif = $notifMapper->fetchByUserEvent( $user, 
$markAsReadId );
-   if ( $notif && !$notif->getReadTimestamp() ) {
-   if ( $notif->getEvent()->getSection() === 
EchoAttributeManager::MESSAGE ) {
-   $subtractMessages++;
-   } else {
-   $subtractAlerts++;
+
+   // Attempt to mark as read the event IDs in the ?markasread= 
parameter, if present
+   $markAsReadIds = explode( '|', 
$sk->getOutput()->getRequest()->getText( 'markasread' ) );
+   if ( $markAsReadIds ) {
+   // gather the IDs that we didn't already find with 
target_pages
+   $eventsToMarkAsRead = array();
+   foreach ( $markAsReadIds as $markAsReadId ) {
+   $markAsReadId = intval( $markAsReadId );
+   if ( $markAsReadId !== 0 && !in_array( 
$markAsReadId, $eventIds ) ) {
+   $eventsToMarkAsRead[] = $markAsReadId;
}
-   $eventIds[] = $markAsReadId;
+   }
+
+   if ( $eventsToMarkAsRead ) {
+   // fetch the notifications to adjust the 
counters
+   $notifMapper = new EchoNotificationMapper();
+   $notifs = $notifMapper->fetchByUserEvents( 
$user, $eventsToMarkAsRead );
+
+   foreach ( $notifs as $notif ) {
+   if ( !$notif->getReadTimestamp() ) {
+   if ( 
$notif->getEvent()->getSection() === EchoAttributeManager::MESSAGE ) {
+   $subtractMessages++;
+   } else {
+   $subtractAlerts++;
+   }
+   $eventIds[] = intval( 
$notif->getEvent()->getId() );
+   }
+   }
}
}
+
if ( $eventIds ) {
DeferredUpdates::addCallableUpdate( function () use ( 
$user, $eventIds ) {
$notifUser = MWEchoNotifUser::newFromUser( 
$user );
diff --git a/includes/formatters/EventPresentationModel.php 
b/includes/formatters/EventPresentationModel.php
index 691e013..7a95c9d 100644
--- a/includes/formatters/EventPresentationModel.php
+++ b/includes/formatters/EventPresentationModel.php
@@ -406,12 +406,20 @@
/**
 * Like getPrimaryLink(), but with the URL altered to add 
?markasread=XYZ. When this link is followed,
 * the notification is marked as read.
+*
+* When the notification is a bundle, the notification IDs are added to 
the parameter value
+* separated by a "|".
+*
 * @return array|bool
 */
public function getPrimaryLinkWithMarkAsRead() {
$primaryLink = $this->getPrimaryLink();
if ( $primaryLink ) {
-   $primaryLink['url'] = wfAppendQuery( 
$primaryLink['url'], array( 'markasread' => $this->event->getId() ) );
+   $eventIds = array( $this->event->getId() );
+   if ( $this->getBundledIds() ) {
+   $eventIds = array_merge( $eventIds, 
$this->getBundledIds() );
+   }
+   $primaryLink['url'] = wfAppendQuery( 
$primaryLink['url'], array( 'markasread'