/** * Adds this new notification object to the backend storage. */ protected function insert() { global $wgEchoBackend, $wgEchoNotifications; $row = array('notification_event' => $this->event->getId(), 'notification_user' => $this->user->getId(), 'notification_anon_ip' => $this->user->isAnon() ? $this->user->getName() : $this->user->getId(), 'notification_timestamp' => $this->timestamp, 'notification_read_timestamp' => $this->readTimestamp, 'notification_bundle_hash' => '', 'notification_bundle_display_hash' => ''); // Get the bundle key for this event if web bundling is enabled $bundleKey = ''; if (!empty($wgEchoNotifications[$this->event->getType()]['bundle']['web'])) { wfRunHooks('EchoGetBundleRules', array($this->event, &$bundleKey)); } if ($bundleKey) { $hash = md5($bundleKey); $row['notification_bundle_hash'] = $hash; $lastStat = $wgEchoBackend->getLastBundleStat($this->user, $hash); // Use a new display hash if: // 1. there was no last bundle notification // 2. last bundle notification with the same hash was read if ($lastStat && !$lastStat->notification_read_timestamp) { $row['notification_bundle_display_hash'] = $lastStat->notification_bundle_display_hash; } else { $row['notification_bundle_display_hash'] = md5($bundleKey . '-display-hash-' . wfTimestampNow()); } } $wgEchoBackend->createNotification($row); wfRunHooks('EchoCreateNotificationComplete', array($this)); }
/** * Function 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 $user, EchoEvent $event, $deliveryMethod) { global $wgEchoConfig, $wgEchoNotifications; if (!$wgEchoConfig['eventlogging']['Echo']['enabled']) { // Only attempt event logging if Echo schema is enabled return; } // Notifications under system category should have -1 as sender id if ($event->getCategory() === 'system') { $sender = -1; } else { $agent = $event->getAgent(); 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'; } // Add revision ID if it exists $rev = $event->getRevision(); if ($rev) { $data['revisionId'] = $rev->getId(); } self::actuallyLogTheEvent('Echo', $data); }