Merge "Add new EventLogging schema: EchoMail along with code refactor"

This commit is contained in:
jenkins-bot 2013-05-14 00:48:21 +00:00 committed by Gerrit Code Review
commit ceba6083ad
6 changed files with 109 additions and 68 deletions

View file

@ -51,6 +51,7 @@ $wgAutoloadClasses['MWEchoEmailBatch'] = $dir . 'includes/EmailBatch.php';
$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 @@ $wgDefaultUserOptions['echo-subscriptions-web-article-linked'] = false;
// 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
),
)
);

View file

@ -49,19 +49,6 @@ class EchoHooks {
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

View file

@ -21,62 +21,11 @@ class EchoNotifier {
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 );
}
/**
* Send a Notification to a user by email
*
@ -112,7 +61,7 @@ class EchoNotifier {
$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 @@ class EchoNotifier {
$body = $email['body'];
UserMailer::send( $toAddress, $fromAddress, $subject, $body, $replyAddress );
MWEchoEventLogging::logSchemaEchoMail( $user, 'single' );
}
}

View file

@ -226,8 +226,10 @@ abstract class MWEchoEmailBatch {
// @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 @@ abstract class MWEchoEmailBatch {
// @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 );
}
/**

View file

@ -245,6 +245,7 @@ abstract class MWEchoEmailBundler {
// Schedule a email job or just send the email directly?
UserMailer::send( $toAddress, $fromAddress, $content['subject'], $content['body'], $replyAddress );
MWEchoEventLogging::logSchemaEchoMail( $this->mUser, 'bundle' );
}
/**

94
includes/EventLogging.php Normal file
View 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 );
}
}