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

Change subject: Add first version of EventLogging schema to Echo
......................................................................


Add first version of EventLogging schema to Echo

Change-Id: I4b6033ffc2ec8d1597f2b447f100c58a8c3a7f3e
---
M Echo.php
M Hooks.php
M Notifier.php
M model/Notification.php
4 files changed, 98 insertions(+), 1 deletion(-)

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



diff --git a/Echo.php b/Echo.php
index 50ece45..7e576ea 100644
--- a/Echo.php
+++ b/Echo.php
@@ -87,6 +87,7 @@
 $wgHooks['BeforePageDisplay'][] = 'EchoHooks::beforePageDisplay';
 $wgHooks['MakeGlobalVariablesScript'][] = 
'EchoHooks::makeGlobalVariablesScript';
 $wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
+$wgHooks['ResourceLoaderRegisterModules'][] = 
'EchoHooks::onResourceLoaderRegisterModules';
 
 // Extension initialization
 $wgExtensionFunctions[] = 'EchoHooks::initEchoExtension';
@@ -244,23 +245,28 @@
 $wgEchoEventDetails = array(
        'welcome' => array(
                'nodismiss' => array( 'web', 'email' ),
+               'group' => 'positive',
        ),
        'edit-user-talk' => array(
                'category' => 'edit-user-talk',
                'priority' => 1,
                'nodismiss' => array( 'web' ),
+               'group' => 'interactive',
        ),
        'reverted' => array(
                'category' => 'edit-revert',
                'priority' => 9,
+               'group' => 'negative',
        ),
        'article-linked' => array(
                'category' => 'cross-reference',
                'priority' => 5,
+               'group' => 'positive',
        ),
        'mention' => array(
                'category' => 'mention',
                'priority' => 4,
+               'group' => 'interactive',
        ),
 );
 
@@ -366,3 +372,14 @@
 // unset default email for reverted, article-linked (change them to opt-in)
 $wgDefaultUserOptions['echo-email-notificationsreverted'] = false;
 $wgDefaultUserOptions['echo-email-notificationsarticle-linked'] = false;
+
+// Echo Configuration
+$wgEchoConfig = array(
+       'version' => '1.0',
+       'eventlogging' => array (
+               'Echo' => array (
+                       'enabled' => true,
+                       'revision' => 5285750
+               )
+       )
+);
diff --git a/Hooks.php b/Hooks.php
index 8fccccd..1cc4e38 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -16,6 +16,43 @@
        }
 
        /**
+        * Handler for ResourceLoaderRegisterModules hook
+        */
+       public static function onResourceLoaderRegisterModules( ResourceLoader 
&$resourceLoader ) {
+               global $wgResourceModules, $wgEchoConfig;
+
+               $eventLogEnabled = function_exists( 'efLogServerSideEvent' );
+
+               foreach ( $wgEchoConfig['eventlogging'] as $schema => $property 
) {
+                       if ( $eventLogEnabled && $property['enabled'] ) {
+                               $wgResourceModules[ 'schema.' . $schema ] = 
array(
+                                       'class'  => 
'ResourceLoaderSchemaModule',
+                                       'schema' => $schema,
+                                       'revision' => $property['revision'],
+                               );
+                               
$wgResourceModules['ext.echo.base']['dependencies'][] = 'schema.' . $schema;
+                       } else {
+                               
$wgEchoConfig['eventlogging'][$schema]['enabled'] = false;
+                       }
+               }
+
+               return true;
+       }
+
+       /**
+        * 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 57836c8..a3615fe 100644
--- a/Notifier.php
+++ b/Notifier.php
@@ -10,7 +10,34 @@
         * @param $event EchoEvent to notify about.
         */
        public static function notifyWithNotification( $user, $event ) {
-               EchoNotification::create( array( 'user' => $user, 'event' => 
$event ) );
+               global $wgEchoConfig, $wgEchoEventDetails;
+
+               $notif = EchoNotification::create( array( 'user' => $user, 
'event' => $event ) );
+
+               // Attempt event logging if Echo schema is enabled
+               if ( $wgEchoConfig['eventlogging']['Echo']['enabled'] ) {
+                       $event  = $notif->getEvent();
+                       $sender = $event->getAgent();
+                       $user   = $notif->getUser();
+
+                       if ( isset( 
$wgEchoEventDetails[$event->getType()]['group'] ) ) {
+                               $group = 
$wgEchoEventDetails[$event->getType()]['group'];
+                       } else {
+                               $group = 'neutral';
+                       }
+
+                       $data = array (
+                               'version' => $wgEchoConfig['version'],
+                               'eventId' => $event->getId(),
+                               'notificationType' => $event->getType(),
+                               'notificationGroup' => $group,
+                               'sender' => (string)( $sender->isAnon() ? 
$sender->getName() : $sender->getId() ),
+                               'recipientUserId' => $user->getId(),
+                               'recipientEditCount' => 
(int)$user->getEditCount()
+                       );
+                       EchoHooks::logEvent( 'Echo', $data );
+               }
+
                EchoNotificationController::resetNotificationCount( $user, 
DB_MASTER );
        }
 
diff --git a/model/Notification.php b/model/Notification.php
index d1bdea5..e8b4900 100644
--- a/model/Notification.php
+++ b/model/Notification.php
@@ -66,4 +66,20 @@
 
                $wgEchoBackend->createNotification( $row );
        }
+
+       /**
+        * Getter method
+        * @return EchoEvent The event for this notification
+        */
+       public function getEvent() {
+               return $this->event;
+       }
+
+       /**
+        * Getter method
+        * @return User The recipient of this notification
+        */
+       public function getUser() {
+               return $this->user;
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4b6033ffc2ec8d1597f2b447f100c58a8c3a7f3e
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to