jenkins-bot has submitted this change and it was merged. Change subject: 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 ......................................................................
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 --- M Notifier.php 1 file changed, 54 insertions(+), 32 deletions(-) Approvals: Kaldari: Looks good to me, approved DarTar: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/Notifier.php b/Notifier.php index c2fd98b..7e44cc7 100644 --- a/Notifier.php +++ b/Notifier.php @@ -14,40 +14,60 @@ 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 ); } /** @@ -97,6 +117,8 @@ $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 ); -- To view, visit https://gerrit.wikimedia.org/r/60737 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I60705900166b675d7d8e07d11114ae06a2d1a7c3 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Lwelling <[email protected]> Gerrit-Reviewer: Bsitu <[email protected]> Gerrit-Reviewer: DarTar <[email protected]> Gerrit-Reviewer: Kaldari <[email protected]> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
