/**
  * Creates an EchoNotification object based on event and user
  * @param $info array The following keys are required:
  * - 'event' The EchoEvent being notified about.
  * - 'user' The User being notified.
  * @throws MWException
  * @return EchoNotification
  */
 public static function create(array $info)
 {
     $obj = new EchoNotification();
     static $validFields = array('event', 'user');
     foreach ($validFields as $field) {
         if (isset($info[$field])) {
             $obj->{$field} = $info[$field];
         } else {
             throw new MWException("Field {$field} is required");
         }
     }
     if (!$obj->user instanceof User && !$obj->user instanceof StubObject) {
         throw new MWException('Invalid user parameter, expected: User/StubObject object');
     }
     if (!$obj->event instanceof EchoEvent) {
         throw new MWException('Invalid event parameter, expected: EchoEvent object');
     }
     // Notification timestamp should be the same as event timestamp
     $obj->timestamp = $obj->event->getTimestamp();
     // Safe fallback
     if (!$obj->timestamp) {
         $obj->timestamp = wfTimestampNow();
     }
     $obj->insert();
     return $obj;
 }
Exemple #2
0
 /**
  * Record an EchoNotification for an EchoEvent
  * Currently used for web-based notifications.
  *
  * @param $user User to notify.
  * @param $event EchoEvent to notify about.
  */
 public static function notifyWithNotification($user, $event)
 {
     global $wgEchoConfig, $wgEchoNotifications;
     // Only create the notification if the user wants to recieve that type
     // of notification and they are eligible to recieve it. See bug 47664.
     $userWebNotifications = EchoNotificationController::getUserEnabledEvents($user, 'web');
     if (!in_array($event->getType(), $userWebNotifications)) {
         return;
     }
     EchoNotification::create(array('user' => $user, 'event' => $event));
     MWEchoEventLogging::logSchemaEcho($user, $event, 'web');
 }
Exemple #3
0
 /**
  * Handler for EchoCreateNotificationComplete hook, this will allow some
  * extra stuff to be done upon creating a new notification
  * @param $notif EchoNotification
  * @return bool true in all cases
  */
 public static function onEchoCreateNotificationComplete(EchoNotification $notif)
 {
     if ($notif->getEvent() && $notif->getUser()) {
         // Extra stuff for talk page notification
         if ($notif->getEvent()->getType() === 'edit-user-talk') {
             $notifUser = MWEchoNotifUser::newFromUser($notif->getUser());
             $notifUser->flagCacheWithNewTalkNotification();
         }
     }
     return true;
 }