processMessage() публичный Метод

Examples: 1. A user is an attendee to an event. The organizer sends an updated meeting using a new iTip message with METHOD:REQUEST. This function will process the message and update the attendee's event accordingly. 2. The organizer cancelled the event using METHOD:CANCEL. We will update the users event to state STATUS:CANCELLED. 3. An attendee sent a reply to an invite using METHOD:REPLY. We can update the organizers event to update the ATTENDEE with its correct PARTSTAT. The $existingObject is updated in-place. If there is no existing object (because it's a new invite for example) a new object will be created. If an existing object does not exist, and the method was CANCEL or REPLY, the message effectively gets ignored, and no 'existingObject' will be created. The updated $existingObject is also returned from this function. If the iTip message was not supported, we will always return false.
public processMessage ( Sabre\VObject\ITip\Message $itipMessage, Sabre\VObject\Component\VCalendar $existingObject = null ) : Sabre\VObject\Component\VCalendar | null
$itipMessage Sabre\VObject\ITip\Message
$existingObject Sabre\VObject\Component\VCalendar
Результат Sabre\VObject\Component\VCalendar | null
Пример #1
0
 function process($input, $existingObject = null, $expected = false)
 {
     $version = \Sabre\VObject\Version::VERSION;
     $vcal = Reader::read($input);
     foreach ($vcal->getComponents() as $mainComponent) {
         break;
     }
     $message = new Message();
     $message->message = $vcal;
     $message->method = isset($vcal->METHOD) ? $vcal->METHOD->getValue() : null;
     $message->component = $mainComponent->name;
     $message->uid = $mainComponent->UID->getValue();
     $message->sequence = isset($vcal->VEVENT[0]) ? (string) $vcal->VEVENT[0]->SEQUENCE : null;
     if ($message->method === 'REPLY') {
         $message->sender = $mainComponent->ATTENDEE->getValue();
         $message->senderName = isset($mainComponent->ATTENDEE['CN']) ? $mainComponent->ATTENDEE['CN']->getValue() : null;
         $message->recipient = $mainComponent->ORGANIZER->getValue();
         $message->recipientName = isset($mainComponent->ORGANIZER['CN']) ? $mainComponent->ORGANIZER['CN'] : null;
     }
     $broker = new Broker();
     if (is_string($existingObject)) {
         $existingObject = str_replace('%foo%', "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject {$version}//EN\nCALSCALE:GREGORIAN", $existingObject);
         $existingObject = Reader::read($existingObject);
     }
     $result = $broker->processMessage($message, $existingObject);
     if (is_null($expected)) {
         $this->assertTrue(!$result);
         return;
     }
     $this->assertVObjectEqualsVObject($expected, $result);
 }
Пример #2
0
 /**
  * Event handler for the 'schedule' event.
  *
  * This handler attempts to look at local accounts to deliver the
  * scheduling object.
  *
  * @param ITip\Message $iTipMessage
  * @return void
  */
 function scheduleLocalDelivery(ITip\Message $iTipMessage)
 {
     $aclPlugin = $this->server->getPlugin('acl');
     // Local delivery is not available if the ACL plugin is not loaded.
     if (!$aclPlugin) {
         return;
     }
     $caldavNS = '{' . Plugin::NS_CALDAV . '}';
     $principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
     if (!$principalUri) {
         $iTipMessage->scheduleStatus = '3.7;Could not find principal.';
         return;
     }
     // We found a principal URL, now we need to find its inbox.
     // Unfortunately we may not have sufficient privileges to find this, so
     // we are temporarily turning off ACL to let this come through.
     //
     // Once we support PHP 5.5, this should be wrapped in a try..finally
     // block so we can ensure that this privilege gets added again after.
     $this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
     $result = $this->server->getProperties($principalUri, ['{DAV:}principal-URL', $caldavNS . 'calendar-home-set', $caldavNS . 'schedule-inbox-URL', $caldavNS . 'schedule-default-calendar-URL', '{http://sabredav.org/ns}email-address']);
     // Re-registering the ACL event
     $this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
     if (!isset($result[$caldavNS . 'schedule-inbox-URL'])) {
         $iTipMessage->scheduleStatus = '5.2;Could not find local inbox';
         return;
     }
     if (!isset($result[$caldavNS . 'calendar-home-set'])) {
         $iTipMessage->scheduleStatus = '5.2;Could not locate a calendar-home-set';
         return;
     }
     if (!isset($result[$caldavNS . 'schedule-default-calendar-URL'])) {
         $iTipMessage->scheduleStatus = '5.2;Could not find a schedule-default-calendar-URL property';
         return;
     }
     $calendarPath = $result[$caldavNS . 'schedule-default-calendar-URL']->getHref();
     $homePath = $result[$caldavNS . 'calendar-home-set']->getHref();
     $inboxPath = $result[$caldavNS . 'schedule-inbox-URL']->getHref();
     if ($iTipMessage->method === 'REPLY') {
         $privilege = 'schedule-deliver-reply';
     } else {
         $privilege = 'schedule-deliver-invite';
     }
     if (!$aclPlugin->checkPrivileges($inboxPath, $caldavNS . $privilege, DAVACL\Plugin::R_PARENT, false)) {
         $iTipMessage->scheduleStatus = '3.8;organizer did not have the ' . $privilege . ' privilege on the attendees inbox';
         return;
     }
     // Next, we're going to find out if the item already exits in one of
     // the users' calendars.
     $uid = $iTipMessage->uid;
     $newFileName = 'sabredav-' . \Sabre\DAV\UUIDUtil::getUUID() . '.ics';
     $home = $this->server->tree->getNodeForPath($homePath);
     $inbox = $this->server->tree->getNodeForPath($inboxPath);
     $currentObject = null;
     $objectNode = null;
     $isNewNode = false;
     $result = $home->getCalendarObjectByUID($uid);
     if ($result) {
         // There was an existing object, we need to update probably.
         $objectPath = $homePath . '/' . $result;
         $objectNode = $this->server->tree->getNodeForPath($objectPath);
         $oldICalendarData = $objectNode->get();
         $currentObject = Reader::read($oldICalendarData);
     } else {
         $isNewNode = true;
     }
     $broker = new ITip\Broker();
     $newObject = $broker->processMessage($iTipMessage, $currentObject);
     $inbox->createFile($newFileName, $iTipMessage->message->serialize());
     if (!$newObject) {
         // We received an iTip message referring to a UID that we don't
         // have in any calendars yet, and processMessage did not give us a
         // calendarobject back.
         //
         // The implication is that processMessage did not understand the
         // iTip message.
         $iTipMessage->scheduleStatus = '5.0;iTip message was not processed by the server, likely because we didn\'t understand it.';
         return;
     }
     // Note that we are bypassing ACL on purpose by calling this directly.
     // We may need to look a bit deeper into this later. Supporting ACL
     // here would be nice.
     if ($isNewNode) {
         $calendar = $this->server->tree->getNodeForPath($calendarPath);
         $calendar->createFile($newFileName, $newObject->serialize());
     } else {
         // If the message was a reply, we may have to inform other
         // attendees of this attendees status. Therefore we're shooting off
         // another itipMessage.
         if ($iTipMessage->method === 'REPLY') {
             $this->processICalendarChange($oldICalendarData, $newObject, [$iTipMessage->recipient], [$iTipMessage->sender]);
         }
         $objectNode->put($newObject->serialize());
     }
     $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
 }