mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Add new EventLogging schema: EchoMail along with code refactor
Change-Id: I7f9ec99d27b69abb14aa89540e424f1e0bcd8160
This commit is contained in:
parent
4134306e28
commit
ce78c973f3
10
Echo.php
10
Echo.php
|
@ -51,6 +51,7 @@ $wgAutoloadClasses['MWEchoEmailBatch'] = $dir . 'includes/EmailBatch.php';
|
||||||
$wgAutoloadClasses['MWDbEchoEmailBatch'] = $dir . 'includes/DbEmailBatch.php';
|
$wgAutoloadClasses['MWDbEchoEmailBatch'] = $dir . 'includes/DbEmailBatch.php';
|
||||||
$wgAutoloadClasses['MWEchoEmailBundler'] = $dir . 'includes/EmailBundler.php';
|
$wgAutoloadClasses['MWEchoEmailBundler'] = $dir . 'includes/EmailBundler.php';
|
||||||
$wgAutoloadClasses['MWDbEchoEmailBundler'] = $dir . 'includes/DbEmailBundler.php';
|
$wgAutoloadClasses['MWDbEchoEmailBundler'] = $dir . 'includes/DbEmailBundler.php';
|
||||||
|
$wgAutoloadClasses['MWEchoEventLogging'] = $dir . 'includes/EventLogging.php';
|
||||||
|
|
||||||
// Formatters
|
// Formatters
|
||||||
$wgAutoloadClasses['EchoNotificationFormatter'] = $dir . 'formatters/NotificationFormatter.php';
|
$wgAutoloadClasses['EchoNotificationFormatter'] = $dir . 'formatters/NotificationFormatter.php';
|
||||||
|
@ -473,11 +474,16 @@ $wgDefaultUserOptions['echo-subscriptions-web-article-linked'] = false;
|
||||||
|
|
||||||
// Echo Configuration for EventLogging
|
// Echo Configuration for EventLogging
|
||||||
$wgEchoConfig = array(
|
$wgEchoConfig = array(
|
||||||
'version' => '1.1',
|
'version' => '1.2',
|
||||||
|
// default all eventlogging off, overwrite them in site configuration
|
||||||
'eventlogging' => array (
|
'eventlogging' => array (
|
||||||
'Echo' => array (
|
'Echo' => array (
|
||||||
'enabled' => false,
|
'enabled' => false,
|
||||||
'revision' => 5423520
|
'revision' => 5423520
|
||||||
)
|
),
|
||||||
|
'EchoMail' => array (
|
||||||
|
'enabled' => false,
|
||||||
|
'revision' => 5467650
|
||||||
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
13
Hooks.php
13
Hooks.php
|
@ -49,19 +49,6 @@ class EchoHooks {
|
||||||
return true;
|
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
|
* @param $updater DatabaseUpdater object
|
||||||
* @return bool true in all cases
|
* @return bool true in all cases
|
||||||
|
|
56
Notifier.php
56
Notifier.php
|
@ -21,62 +21,11 @@ class EchoNotifier {
|
||||||
|
|
||||||
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
||||||
|
|
||||||
self::logEvent( $user, $event, 'web' );
|
MWEchoEventLogging::logSchemaEcho( $user, $event, 'web' );
|
||||||
|
|
||||||
EchoNotificationController::resetNotificationCount( $user, DB_MASTER );
|
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
|
* Send a Notification to a user by email
|
||||||
*
|
*
|
||||||
|
@ -112,7 +61,7 @@ class EchoNotifier {
|
||||||
$bundleHash = md5( $bundleString );
|
$bundleHash = md5( $bundleString );
|
||||||
}
|
}
|
||||||
|
|
||||||
self::logEvent( $user, $event, 'email' );
|
MWEchoEventLogging::logSchemaEcho( $user, $event, 'email' );
|
||||||
|
|
||||||
// email digest notification ( weekly or daily )
|
// email digest notification ( weekly or daily )
|
||||||
if ( $wgEchoEnableEmailBatch && $user->getOption( 'echo-email-frequency' ) > 0 ) {
|
if ( $wgEchoEnableEmailBatch && $user->getOption( 'echo-email-frequency' ) > 0 ) {
|
||||||
|
@ -149,6 +98,7 @@ class EchoNotifier {
|
||||||
$body = $email['body'];
|
$body = $email['body'];
|
||||||
|
|
||||||
UserMailer::send( $toAddress, $fromAddress, $subject, $body, $replyAddress );
|
UserMailer::send( $toAddress, $fromAddress, $subject, $body, $replyAddress );
|
||||||
|
MWEchoEventLogging::logSchemaEchoMail( $user, 'single' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,8 +226,10 @@ abstract class MWEchoEmailBatch {
|
||||||
// @Todo - replace them with the CONSTANT in 33810 once it is merged
|
// @Todo - replace them with the CONSTANT in 33810 once it is merged
|
||||||
if ( $this->mUser->getOption( 'echo-email-frequency' ) == 7 ) {
|
if ( $this->mUser->getOption( 'echo-email-frequency' ) == 7 ) {
|
||||||
$frequency = 'weekly';
|
$frequency = 'weekly';
|
||||||
|
$emailDeliveryMode = 'weekly_digest';
|
||||||
} else {
|
} else {
|
||||||
$frequency = 'daily';
|
$frequency = 'daily';
|
||||||
|
$emailDeliveryMode = 'daily_digest';
|
||||||
}
|
}
|
||||||
|
|
||||||
// email subject
|
// email subject
|
||||||
|
@ -251,6 +253,7 @@ abstract class MWEchoEmailBatch {
|
||||||
|
|
||||||
// @Todo Push the email to job queue or just send it out directly?
|
// @Todo Push the email to job queue or just send it out directly?
|
||||||
UserMailer::send( $toAddress, $fromAddress, $subject, $body, $replyAddress );
|
UserMailer::send( $toAddress, $fromAddress, $subject, $body, $replyAddress );
|
||||||
|
MWEchoEventLogging::logSchemaEchoMail( $this->mUser, $emailDeliveryMode );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -245,6 +245,7 @@ abstract class MWEchoEmailBundler {
|
||||||
|
|
||||||
// Schedule a email job or just send the email directly?
|
// Schedule a email job or just send the email directly?
|
||||||
UserMailer::send( $toAddress, $fromAddress, $content['subject'], $content['body'], $replyAddress );
|
UserMailer::send( $toAddress, $fromAddress, $content['subject'], $content['body'], $replyAddress );
|
||||||
|
MWEchoEventLogging::logSchemaEchoMail( $this->mUser, 'bundle' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
94
includes/EventLogging.php
Normal file
94
includes/EventLogging.php
Normal file
|
@ -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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue