From 51bd09e3aa3c182e6b35f5941bb8ecdebb119883 Mon Sep 17 00:00:00 2001 From: lwelling Date: Wed, 24 Apr 2013 16:45:05 -0400 Subject: [PATCH] Add event logging call to notifications sent by email Add deliveryMethod to logged data as described in the new schema at http://meta.wikimedia.org/wiki/Schema:Echo Change-Id: I60705900166b675d7d8e07d11114ae06a2d1a7c3 --- Notifier.php | 86 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/Notifier.php b/Notifier.php index c2fd98b91..7e44cc734 100644 --- a/Notifier.php +++ b/Notifier.php @@ -14,42 +14,62 @@ class EchoNotifier { EchoNotification::create( array( 'user' => $user, 'event' => $event ) ); - // Attempt event logging if Echo schema is enabled - if ( $wgEchoConfig['eventlogging']['Echo']['enabled'] ) { - $agent = $event->getAgent(); - // Typically an event should always have an agent, but agent could be - // null if the data is corrupted - if ( $agent ) { - $sender = $agent->isAnon() ? $agent->getName() : $agent->getId(); - } else { - $sender = 0; - } - - if ( isset( $wgEchoNotifications[$event->getType()]['group'] ) ) { - $group = $wgEchoNotifications[$event->getType()]['group']; - } else { - $group = 'neutral'; - } - $data = array ( - 'version' => $wgEchoConfig['version'], - 'eventId' => $event->getId(), - 'notificationType' => $event->getType(), - 'notificationGroup' => $group, - 'sender' => (string)$sender, - 'recipientUserId' => $user->getId(), - 'recipientEditCount' => (int)$user->getEditCount() - ); - // Add the source if it exists. (This is mostly for the Thanks extension.) - $extra = $event->getExtra(); - if ( isset( $extra['source'] ) ) { - $data['eventSource'] = (string)$extra['source']; - } - EchoHooks::logEvent( 'Echo', $data ); - } + self::logEvent( $user, $event, 'web' ); EchoNotificationController::resetNotificationCount( $user, DB_MASTER ); } + /** + * Store Event Logging data for web or email notifications + * + * @param $user User being notified. + * @param $event EchoEvent to log detail about. + * @param $deliveryMethod string containing either 'web' or 'email' + */ + public static function logEvent( $user, $event, $deliveryMethod ) { + global $wgEchoConfig, $wgEchoNotifications; + if ( $wgEchoConfig['eventlogging']['Echo']['enabled'] ) { + // Only attempt event logging if Echo schema is enabled + return; + } + + $agent = $event->getAgent(); + // Typically an event should always have an agent, but agent could be + // null if the data is corrupted + if ( $agent ) { + $sender = $agent->isAnon() ? $agent->getName() : $agent->getId(); + } else { + $sender = -1; + } + + if ( isset( $wgEchoNotifications[$event->getType()]['group'] ) ) { + $group = $wgEchoNotifications[$event->getType()]['group']; + } else { + $group = 'neutral'; + } + $data = array ( + 'version' => $wgEchoConfig['version'], + 'eventId' => $event->getId(), + 'notificationType' => $event->getType(), + 'notificationGroup' => $group, + 'sender' => (string)$sender, + 'recipientUserId' => $user->getId(), + 'recipientEditCount' => (int)$user->getEditCount() + ); + // Add the source if it exists. (This is mostly for the Thanks extension.) + $extra = $event->getExtra(); + if ( isset( $extra['source'] ) ) { + $data['eventSource'] = (string)$extra['source']; + } + if( $deliveryMethod == 'email' ) { + $data['deliveryMethod'] = 'email'; + } else { + // whitelist valid delivery methods so it is always valid + $data['deliveryMethod'] = 'web'; + } + EchoHooks::logEvent( 'Echo', $data ); + } + /** * Send a Notification to a user by email * @@ -97,6 +117,8 @@ class EchoNotifier { $addedToQueue = false; + self::logEvent( $user, $event, 'email' ); + // only send bundle email if email bundling is on if ( $wgEchoBundleEmailInterval && $bundleHash && !empty( $wgEchoNotifications[$event->getType()]['bundle']['email'] ) ) { $bundler = MWEchoEmailBundler::newFromUserHash( $user, $bundleHash );