function saveNewFromNotice($notice, $event, $verb) { $other = RSVP::getKV('uri', $notice->uri); if (!empty($other)) { // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond"). throw new ClientException(_m('RSVP already exists.')); } $profile = $notice->getProfile(); try { $other = RSVP::getByKeys(['profile_id' => $profile->getID(), 'event_uri' => $event->getUri()]); // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond"). throw new AlreadyFulfilledException(_m('RSVP already exists.')); } catch (NoResultException $e) { // No previous RSVP, so go ahead and add. } $rsvp = new RSVP(); preg_match('/\\/([^\\/]+)\\/*/', $notice->uri, $match); $rsvp->id = $match[1] ? $match[1] : UUID::gen(); $rsvp->profile_id = $profile->id; $rsvp->event_id = $event->id; $rsvp->response = self::codeFor($verb); $rsvp->created = $notice->created; $rsvp->uri = $notice->uri; $rsvp->insert(); self::blow('rsvp:for-event:%s', $event->getUri()); return $rsvp; }