Example #1
0
 /**
  * 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;
 }