jenkins-bot has submitted this change and it was merged.

Change subject: Add new EventLogging schema: EchoMail along with code refactor
......................................................................


Add new EventLogging schema: EchoMail along with code refactor

Change-Id: I7f9ec99d27b69abb14aa89540e424f1e0bcd8160
---
M Echo.php
M Hooks.php
M Notifier.php
M includes/EmailBatch.php
M includes/EmailBundler.php
A includes/EventLogging.php
6 files changed, 109 insertions(+), 68 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, but someone else must approve
  Kaldari: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Echo.php b/Echo.php
index 9948968..56fec56 100644
--- a/Echo.php
+++ b/Echo.php
@@ -51,6 +51,7 @@
 $wgAutoloadClasses['MWDbEchoEmailBatch'] = $dir . 'includes/DbEmailBatch.php';
 $wgAutoloadClasses['MWEchoEmailBundler'] = $dir . 'includes/EmailBundler.php';
 $wgAutoloadClasses['MWDbEchoEmailBundler'] = $dir . 
'includes/DbEmailBundler.php';
+$wgAutoloadClasses['MWEchoEventLogging'] = $dir . 'includes/EventLogging.php';
 
 // Formatters
 $wgAutoloadClasses['EchoNotificationFormatter'] = $dir . 
'formatters/NotificationFormatter.php';
@@ -473,11 +474,16 @@
 
 // Echo Configuration for EventLogging
 $wgEchoConfig = array(
-       'version' => '1.1',
+       'version' => '1.2',
+       // default all eventlogging off, overwrite them in site configuration
        'eventlogging' => array (
                'Echo' => array (
                        'enabled' => false,
                        'revision' => 5423520
-               )
+               ),
+               'EchoMail' => array (
+                       'enabled' => false,
+                       'revision' => 5467650
+               ),
        )
 );
diff --git a/Hooks.php b/Hooks.php
index 0f65134..efabd32 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -50,19 +50,6 @@
        }
 
        /**
-        * Attempt to log the event
-        * @param $schema string
-        * @param $data array
-        */
-       public static function logEvent( $schema, $data ) {
-               global $wgEchoConfig;
-
-               if ( !empty( $wgEchoConfig['eventlogging'][$schema]['enabled'] 
) ) {
-                       efLogServerSideEvent( $schema, 
$wgEchoConfig['eventlogging'][$schema]['revision'], $data );
-               }
-       }
-
-       /**
         * @param $updater DatabaseUpdater object
         * @return bool true in all cases
         */
diff --git a/Notifier.php b/Notifier.php
index 55c3d9b..c6b45d7 100644
--- a/Notifier.php
+++ b/Notifier.php
@@ -21,60 +21,9 @@
 
                EchoNotification::create( array( 'user' => $user, 'event' => 
$event ) );
 
-               self::logEvent( $user, $event, 'web' );
+               MWEchoEventLogging::logSchemaEcho( $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 );
        }
 
        /**
@@ -112,7 +61,7 @@
                                $bundleHash = md5( $bundleString );
                        }
 
-                       self::logEvent( $user, $event, 'email' );
+                       MWEchoEventLogging::logSchemaEcho( $user, $event, 
'email' );
 
                        // email digest notification ( weekly or daily )
                        if ( $wgEchoEnableEmailBatch && $user->getOption( 
'echo-email-frequency' ) > 0 ) {
@@ -149,6 +98,7 @@
                                $body = $email['body'];
 
                                UserMailer::send( $toAddress, $fromAddress, 
$subject, $body, $replyAddress );
+                               MWEchoEventLogging::logSchemaEchoMail( $user, 
'single' );
                        }
                }
 
diff --git a/includes/EmailBatch.php b/includes/EmailBatch.php
index f238b22..69a7fb2 100644
--- a/includes/EmailBatch.php
+++ b/includes/EmailBatch.php
@@ -226,8 +226,10 @@
                // @Todo - replace them with the CONSTANT in 33810 once it is 
merged 
                if ( $this->mUser->getOption( 'echo-email-frequency' ) == 7 ) {
                        $frequency = 'weekly';
+                       $emailDeliveryMode = 'weekly_digest';
                } else {
                        $frequency = 'daily';
+                       $emailDeliveryMode = 'daily_digest';
                }
 
                // email subject
@@ -251,6 +253,7 @@
 
                // @Todo Push the email to job queue or just send it out 
directly?
                UserMailer::send( $toAddress, $fromAddress, $subject, $body, 
$replyAddress );
+               MWEchoEventLogging::logSchemaEchoMail( $this->mUser, 
$emailDeliveryMode );
        }
 
        /**
diff --git a/includes/EmailBundler.php b/includes/EmailBundler.php
index 89d36dd..103c05c 100644
--- a/includes/EmailBundler.php
+++ b/includes/EmailBundler.php
@@ -245,6 +245,7 @@
 
                // Schedule a email job or just send the email directly?
                UserMailer::send( $toAddress, $fromAddress, 
$content['subject'], $content['body'], $replyAddress );
+               MWEchoEventLogging::logSchemaEchoMail( $this->mUser, 'bundle' );
        }
 
        /**
diff --git a/includes/EventLogging.php b/includes/EventLogging.php
new file mode 100644
index 0000000..0f9b349
--- /dev/null
+++ b/includes/EventLogging.php
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * Static class for handling all kinds of event logging
+ */
+class MWEchoEventLogging {
+
+       /**
+        * This is the only function that interacts with EventLogging
+        * @param $schema string
+        * @param $data array
+        */
+       public static function actuallyLogTheEvent( $schema, $data ) {
+               global $wgEchoConfig;
+
+               if ( !empty( $wgEchoConfig['eventlogging'][$schema]['enabled'] 
) ) {
+                       efLogServerSideEvent( $schema, 
$wgEchoConfig['eventlogging'][$schema]['revision'], $data );
+               }
+       }
+
+       /**
+        * Functions for logging the event for Schema:Echo
+        * @param $user User being notified.
+        * @param $event EchoEvent to log detail about.
+        * @param $deliveryMethod string containing either 'web' or 'email'
+        */
+       public static function logSchemaEcho( $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';
+               }
+
+               self::actuallyLogTheEvent( 'Echo', $data );
+       }
+
+       /**
+        * Functions for logging the event for Schema:EchoEmail
+        * @param $user User
+        * @param $emailDeliveryMode string
+        */
+       public static function logSchemaEchoMail( $user, $emailDeliveryMode = 
'single' ) {
+               global $wgEchoConfig;
+
+               if ( !$wgEchoConfig['eventlogging']['EchoMail']['enabled'] ) {
+                       // Only attempt event logging if EchoMail schema is 
enabled
+                       return;
+               }
+
+               $data = array (
+                       'version' => $wgEchoConfig['version'],
+                       'recipientUserId' => $user->getId(),
+                       'emailDeliveryMode' => $emailDeliveryMode
+               );
+
+               self::actuallyLogTheEvent( 'EchoMail', $data );
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/62758
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7f9ec99d27b69abb14aa89540e424f1e0bcd8160
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <bs...@wikimedia.org>
Gerrit-Reviewer: Bsitu <bs...@wikimedia.org>
Gerrit-Reviewer: Kaldari <rkald...@wikimedia.org>
Gerrit-Reviewer: Lwelling <lwell...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Spage <sp...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to