Skip to content

Commit

Permalink
358 Bugfix Broker::processMessageReply
Browse files Browse the repository at this point in the history
Before this commit processMessageReply did not work for exceptions with
a reccurent id in an other timezone than the dtstart of the master event.
  • Loading branch information
Luc DUZAN committed Dec 21, 2016
1 parent d0fde2f commit b523a00
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/ITip/Broker.php
Expand Up @@ -352,7 +352,10 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing
foreach ($itipMessage->message->VEVENT as $vevent) {
$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getValue() : 'master';
$attendee = $vevent->ATTENDEE;
$instances[$recurId] = $attendee['PARTSTAT']->getValue();
$instances[$recurId] = [
'partstat' => $attendee['PARTSTAT']->getValue(),
'recurIdDateTime' => isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getDateTime() : null
];
if (isset($vevent->{'REQUEST-STATUS'})) {
$requestStatus = $vevent->{'REQUEST-STATUS'}->getValue();
list($requestStatus) = explode(';', $requestStatus);
Expand All @@ -363,6 +366,7 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing
// all the instances where we have a reply for.
$masterObject = null;
foreach ($existingObject->VEVENT as $vevent) {

$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getValue() : 'master';
if ($recurId === 'master') {
$masterObject = $vevent;
Expand All @@ -373,7 +377,7 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing
foreach ($vevent->ATTENDEE as $attendee) {
if ($attendee->getValue() === $itipMessage->sender) {
$attendeeFound = true;
$attendee['PARTSTAT'] = $instances[$recurId];
$attendee['PARTSTAT'] = $instances[$recurId]['partstat'];
$attendee['SCHEDULE-STATUS'] = $requestStatus;
// Un-setting the RSVP status, because we now know
// that the attendee already replied.
Expand All @@ -386,7 +390,7 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing
// Adding a new attendee. The iTip documentation calls this
// a party crasher.
$attendee = $vevent->add('ATTENDEE', $itipMessage->sender, [
'PARTSTAT' => $instances[$recurId]
'PARTSTAT' => $instances[$recurId]['partstat']
]);
if ($itipMessage->senderName) $attendee['CN'] = $itipMessage->senderName;
}
Expand All @@ -400,17 +404,17 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing
}
// If we got replies to instances that did not exist in the
// original list, it means that new exceptions must be created.
foreach ($instances as $recurId => $partstat) {
foreach ($instances as $recurId => $instance) {

$recurrenceIterator = new EventIterator($existingObject, $itipMessage->uid);
$found = false;
$iterations = 1000;
$recurIdDate = $instance['recurIdDateTime'];
do {

$newObject = $recurrenceIterator->getEventObject();
$recurrenceIterator->next();

if (isset($newObject->{'RECURRENCE-ID'}) && $newObject->{'RECURRENCE-ID'}->getValue() === $recurId) {
if (isset($newObject->{'RECURRENCE-ID'}) && $newObject->{'RECURRENCE-ID'}->getDateTime() == $recurIdDate) {
$found = true;
}
$iterations--;
Expand All @@ -430,15 +434,15 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing
foreach ($newObject->ATTENDEE as $attendee) {
if ($attendee->getValue() === $itipMessage->sender) {
$attendeeFound = true;
$attendee['PARTSTAT'] = $partstat;
$attendee['PARTSTAT'] = $instance['partstat'];
break;
}
}
}
if (!$attendeeFound) {
// Adding a new attendee
$attendee = $newObject->add('ATTENDEE', $itipMessage->sender, [
'PARTSTAT' => $partstat
'PARTSTAT' => $instance['partstat']
]);
if ($itipMessage->senderName) {
$attendee['CN'] = $itipMessage->senderName;
Expand Down
125 changes: 125 additions & 0 deletions tests/VObject/ITip/BrokerProcessReplyTest.php
Expand Up @@ -281,6 +281,131 @@ function testReplyNewExceptionTz() {

}

function testReplyNewExceptionReccurenceIdInDifferentTz() {

// This is a reply to 1 instance of a recurring event. This should
// automatically create an exception.
$itip = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
SEQUENCE:2
RECURRENCE-ID;TZID=Asia/Ho_Chi_Minh:20140725T110000
UID:foobar
END:VEVENT
END:VCALENDAR
ICS;

$old = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
END:VEVENT
END:VCALENDAR
ICS;

$expected = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
END:VEVENT
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
DTSTART;TZID=America/Toronto:20140725T000000
DTEND;TZID=America/Toronto:20140725T010000
ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
RECURRENCE-ID;TZID=America/Toronto:20140725T000000
END:VEVENT
END:VCALENDAR
ICS;

$result = $this->process($itip, $old, $expected);

}

/**
* @group failing
*/
function testReplyNewExceptionReccurenceIdInUTC() {

// This is a reply to 1 instance of a recurring event. This should
// automatically create an exception.
$itip = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
SEQUENCE:2
RECURRENCE-ID:20140725T040000Z
UID:foobar
END:VEVENT
END:VCALENDAR
ICS;

$old = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
END:VEVENT
END:VCALENDAR
ICS;

$expected = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
END:VEVENT
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
DTSTART;TZID=America/Toronto:20140725T000000
DTEND;TZID=America/Toronto:20140725T010000
ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
ORGANIZER:mailto:bar@example.org
RECURRENCE-ID;TZID=America/Toronto:20140725T000000
END:VEVENT
END:VCALENDAR
ICS;

$result = $this->process($itip, $old, $expected);

}

function testReplyPartyCrashCreateExcepton() {

// IN this test there's a recurring event that has an exception. The
Expand Down

0 comments on commit b523a00

Please sign in to comment.