Ejemplo n.º 1
0
 /**
  * Creates an EchoEvent object
  * @param $info array Named arguments:
  * type (required): The event type;
  * variant: A variant of the type;
  * agent: The user who caused the event;
  * title: The page on which the event was triggered;
  * extra: Event-specific extra information (e.g. post content)
  *
  * @throws MWException
  * @return EchoEvent|bool false if aborted via hook
  */
 public static function create($info = array())
 {
     global $wgEchoNotifications;
     // Do not create event and notifications if write access is locked
     if (wfReadOnly()) {
         throw new ReadOnlyError();
     }
     $obj = new EchoEvent();
     static $validFields = array('type', 'variant', 'agent', 'title', 'extra');
     if (empty($info['type'])) {
         throw new MWException("'type' parameter is mandatory");
     }
     if (!isset($wgEchoNotifications[$info['type']])) {
         return false;
     }
     $obj->id = false;
     $obj->timestamp = wfTimestampNow();
     foreach ($validFields as $field) {
         if (isset($info[$field])) {
             $obj->{$field} = $info[$field];
         }
     }
     // If the extra size is more than 50000 bytes, that means there is
     // probably a problem with the design of this notification type.
     // There might be data loss if the size exceeds the DB column size of
     // event_extra.
     if (strlen($obj->serializeExtra()) > 50000) {
         wfDebugLog(__CLASS__, __FUNCTION__ . ': event extra data is too huge for ' . $info['type']);
         return false;
     }
     if ($obj->title) {
         if (!$obj->title instanceof Title) {
             throw new MWException('Invalid title parameter');
         }
         $obj->setTitle($obj->title);
     }
     if ($obj->agent && !($obj->agent instanceof User || $obj->agent instanceof StubObject)) {
         throw new MWException("Invalid user parameter");
     }
     if (!wfRunHooks('BeforeEchoEventInsert', array($obj))) {
         return false;
     }
     $obj->insert();
     wfRunHooks('EchoEventInsertComplete', array($obj));
     global $wgEchoUseJobQueue;
     EchoNotificationController::notify($obj, $wgEchoUseJobQueue);
     return $obj;
 }