[Pkg-owncloud-commits] [php-sabre-vobject] 37/106: Fixed issues related to attendees accepting specific instances of recurring events.
David Prévot
taffit at moszumanska.debian.org
Fri Aug 22 15:10:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabre-vobject.
commit 26ad1dbf9c83aee6b4e7ca98af14805f3bd5f29a
Author: Evert Pot <me at evertpot.com>
Date: Thu Jul 24 01:45:44 2014 -0400
Fixed issues related to attendees accepting specific instances of
recurring events.
---
lib/Sabre/VObject/ITip/Broker.php | 55 ++++--
.../Sabre/VObject/ITip/BrokerAttendeeReplyTest.php | 167 ++++++++++++++++
.../VObject/ITip/BrokerProcessMessageTest.php | 213 ++++++++++++++++++++-
3 files changed, 416 insertions(+), 19 deletions(-)
diff --git a/lib/Sabre/VObject/ITip/Broker.php b/lib/Sabre/VObject/ITip/Broker.php
index 4bc2755..b41ec8d 100644
--- a/lib/Sabre/VObject/ITip/Broker.php
+++ b/lib/Sabre/VObject/ITip/Broker.php
@@ -4,6 +4,7 @@ namespace Sabre\VObject\ITip;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Reader;
+use Sabre\VObject\RecurrenceIterator;
/**
* The ITip\Broker class is a utility class that helps with processing
@@ -272,19 +273,22 @@ class Broker {
}
if (isset($instances[$recurId])) {
$attendeeFound = false;
- foreach($vevent->ATTENDEE as $attendee) {
- if ($attendee->getValue() === $itipMessage->sender) {
- $attendeeFound = true;
- $attendee['PARTSTAT'] = $instances[$recurId];
- break;
+ if (isset($vevent->ATTENDEE)) {
+ foreach($vevent->ATTENDEE as $attendee) {
+ if ($attendee->getValue() === $itipMessage->sender) {
+ $attendeeFound = true;
+ $attendee['PARTSTAT'] = $instances[$recurId];
+ break;
+ }
}
}
if (!$attendeeFound) {
- // Adding a new attendee
+ // Adding a new attendee. The iTip documentation calls this
+ // a party crasher.
$attendee = $vevent->add('ATTENDEE', $itipMessage->sender, array(
- 'CN' => $itipMessage->senderName,
'PARTSTAT' => $instances[$recurId]
));
+ if ($itipMessage->senderName) $attendee['CN'] = $itipMessage->senderName;
}
unset($instances[$recurId]);
}
@@ -298,7 +302,24 @@ class Broker {
// original list, it means that new exceptions must be created.
foreach($instances as $recurId=>$partstat) {
- $newObject = clone $masterObject;
+ $recurrenceIterator = new RecurrenceIterator($existingObject, $itipMessage->uid);
+ $found = false;
+ $iterations = 1000;
+ do {
+
+ $newObject = $recurrenceIterator->getEventObject();
+ $recurrenceIterator->next();
+
+ if (isset($newObject->{'RECURRENCE-ID'}) && $newObject->{'RECURRENCE-ID'}->getValue()===$recurId) {
+ $found = true;
+ }
+ $iterations--;
+
+ } while($recurrenceIterator->valid() && !$found && $iterations);
+
+ // Invalid recurrence id. Skipping this object.
+ if (!$found) continue;
+
unset(
$newObject->RRULE,
$newObject->EXDATE,
@@ -306,19 +327,23 @@ class Broker {
);
$newObject->{'RECURRENCE-ID'} = $recurId;
$attendeeFound = false;
- foreach($vevent->ATTENDEE as $attendee) {
- if ($attendee->getValue() === $message->sender) {
- $attendeeFound = true;
- $attendee['PARTSTAT'] = $partstat;
- break;
+ if (isset($newObject->ATTENDEE)) {
+ foreach($newObject->ATTENDEE as $attendee) {
+ if ($attendee->getValue() === $itipMessage->sender) {
+ $attendeeFound = true;
+ $attendee['PARTSTAT'] = $partstat;
+ break;
+ }
}
}
if (!$attendeeFound) {
// Adding a new attendee
- $attendee = $vevent->add('ATTENDEE', $message->sender, array(
- 'CN' => $message->senderName,
+ $attendee = $newObject->add('ATTENDEE', $itipMessage->sender, array(
'PARTSTAT' => $partstat
));
+ if ($itipMessage->senderName) {
+ $attendee['CN'] = $itipMessage->senderName;
+ }
}
$existingObject->add($newObject);
diff --git a/tests/Sabre/VObject/ITip/BrokerAttendeeReplyTest.php b/tests/Sabre/VObject/ITip/BrokerAttendeeReplyTest.php
index 8a5f755..caa2c83 100644
--- a/tests/Sabre/VObject/ITip/BrokerAttendeeReplyTest.php
+++ b/tests/Sabre/VObject/ITip/BrokerAttendeeReplyTest.php
@@ -67,6 +67,173 @@ ICS
}
+ function testRecurringReply() {
+
+ $oldMessage = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=One:mailto:one at example.org
+DTSTART:20140724T120000Z
+RRULE;FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+
+ $newMessage = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=One:mailto:one at example.org
+DTSTART:20140724T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one at example.org
+DTSTART:20140726T120000Z
+RECURRENCE-ID:20140726T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one at example.org
+DTSTART:20140724T120000Z
+RECURRENCE-ID:20140724T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=TENTATIVE;CN=One:mailto:one at example.org
+DTSTART:20140728T120000Z
+RECURRENCE-ID:20140728T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one at example.org
+DTSTART:20140729T120000Z
+RECURRENCE-ID:20140729T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one at example.org
+DTSTART:20140725T120000Z
+RECURRENCE-ID:20140725T120000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $version = \Sabre\VObject\Version::VERSION;
+
+ $expected = array(
+ array(
+ 'uid' => 'foobar',
+ 'method' => 'REPLY',
+ 'component' => 'VEVENT',
+ 'sender' => 'mailto:one at example.org',
+ 'senderName' => 'One',
+ 'recipient' => 'mailto:strunk at example.org',
+ 'recipientName' => 'Strunk',
+ 'message' => <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Sabre//Sabre VObject $version//EN
+CALSCALE:GREGORIAN
+METHOD:REPLY
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+RECURRENCE-ID:20140726T120000Z
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one at example.org
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+RECURRENCE-ID:20140724T120000Z
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one at example.org
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+RECURRENCE-ID:20140728T120000Z
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=TENTATIVE;CN=One:mailto:one at example.org
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+RECURRENCE-ID:20140729T120000Z
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one at example.org
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+RECURRENCE-ID:20140725T120000Z
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one at example.org
+END:VEVENT
+END:VCALENDAR
+ICS
+
+ ),
+
+ );
+
+ $result = $this->parse($oldMessage, $newMessage, $expected);
+
+ }
+
+ function testNoChange() {
+
+ $oldMessage = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=One:mailto:one at example.org
+DTSTART:20140716T120000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+
+ $newMessage = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:foobar
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=One:mailto:one at example.org
+DTSTART:20140716T120000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $expected = array();
+ $result = $this->parse($oldMessage, $newMessage, $expected);
+
+ }
+
function parse($oldMessage, $newMessage, $expected = array()) {
$broker = new Broker();
diff --git a/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php b/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php
index 2ef6678..e4addae 100644
--- a/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php
+++ b/tests/Sabre/VObject/ITip/BrokerProcessMessageTest.php
@@ -231,26 +231,231 @@ ICS;
}
+ function testReplyPartyCrasher() {
+
+ $itip = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:crasher at example.org
+ORGANIZER:mailto:bar at example.org
+SEQUENCE:2
+UID:foobar
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $old = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+ATTENDEE:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+ATTENDEE:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:crasher at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $result = $this->process($itip, $old, $expected);
+
+ }
+
+ function testReplyNewException() {
+
+ // 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 at example.org
+ORGANIZER:mailto:bar at example.org
+SEQUENCE:2
+RECURRENCE-ID:20140725T000000Z
+UID:foobar
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $old = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+RRULE:FREQ=DAILY
+DTSTART:20140724T000000Z
+ATTENDEE:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+RRULE:FREQ=DAILY
+DTSTART:20140724T000000Z
+ATTENDEE:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+DTSTART:20140725T000000Z
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo at example.org
+ORGANIZER:mailto:bar at example.org
+RECURRENCE-ID:20140725T000000Z
+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
+ // exception is missing the attendee.
+ //
+ // The attendee party crashes the instance, so it should show up in the
+ // resulting object.
+ $itip = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=ACCEPTED;CN=Crasher!:mailto:crasher at example.org
+ORGANIZER:mailto:bar at example.org
+SEQUENCE:2
+RECURRENCE-ID:20140725T000000Z
+UID:foobar
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $old = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+RRULE:FREQ=DAILY
+DTSTART:20140724T000000Z
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+RRULE:FREQ=DAILY
+DTSTART:20140724T000000Z
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+DTSTART:20140725T000000Z
+ORGANIZER:mailto:bar at example.org
+RECURRENCE-ID:20140725T000000Z
+ATTENDEE;PARTSTAT=ACCEPTED;CN=Crasher!:mailto:crasher at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $result = $this->process($itip, $old, $expected);
+
+ }
+
+ function testReplyNewExceptionNoMasterEvent() {
+
+ /**
+ * This iTip message would normally create a new exception, but the
+ * server is not able to create this new instance, because there's no
+ * master event to clone from.
+ *
+ * This test checks if the message is ignored.
+ */
+ $itip = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=ACCEPTED;CN=Crasher!:mailto:crasher at example.org
+ORGANIZER:mailto:bar at example.org
+SEQUENCE:2
+RECURRENCE-ID:20140725T000000Z
+UID:foobar
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $old = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+RRULE:FREQ=DAILY
+DTSTART:20140724T000000Z
+RECURRENCE-ID:20140724T000000Z
+ORGANIZER:mailto:bar at example.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $expected = null;
+ $result = $this->process($itip, $old, $expected);
+
+ }
function process($input, $existingObject = null, $expected = false) {
$version = \Sabre\VObject\Version::VERSION;
$vcal = Reader::read($input);
- $mainComponent = $vcal->getBaseComponent();
+ 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->sequence = isset($vcal->VEVENT[0])?$vcal->VEVENT[0]->SEQUENCE:null;
+ $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']:null;
+ $message->senderName = isset($mainComponent->ATTENDEE['CN'])?$mainComponent->ATTENDEE['CN']->getValue():null;
$message->recipient = $mainComponent->ORGANIZER->getValue();
- $message->senderName = isset($mainComponent->ORGANIZER['CN'])?$mainComponent->ORGANIZER['CN']:null;
+ $message->recipientName = isset($mainComponent->ORGANIZER['CN'])?$mainComponent->ORGANIZER['CN']:null;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git
More information about the Pkg-owncloud-commits
mailing list