Branch 'dev/sabre-vobject3' - 2 commits - plugins/libcalendaring
Thomas Brüderli
bruederli at kolabsys.com
Wed Nov 12 15:21:36 CET 2014
plugins/libcalendaring/libvcalendar.php | 31 ++++++++++++----------
plugins/libcalendaring/tests/libvcalendar.php | 4 ++
plugins/libcalendaring/tests/resources/alarms.ics | 5 +++
3 files changed, 26 insertions(+), 14 deletions(-)
New commits:
commit 998b25171d60485e2c73203423aa998af4ff6f78
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Nov 12 15:21:32 2014 +0100
Accept events with METHOD:CANCEL and no end date
diff --git a/plugins/libcalendaring/libvcalendar.php b/plugins/libcalendaring/libvcalendar.php
index 0965064..4d43248 100644
--- a/plugins/libcalendaring/libvcalendar.php
+++ b/plugins/libcalendaring/libvcalendar.php
@@ -653,6 +653,11 @@ class libvcalendar implements Iterator
unset($event['end']);
}
+ // some iTip CANCEL messages only contain the start date
+ if (!$event['end'] && $event['start'] && $this->method == 'CANCEL') {
+ $event['end'] = clone $event['start'];
+ }
+
// minimal validation
if (empty($event['uid']) || ($event['_type'] == 'event' && empty($event['start']) != empty($event['end']))) {
throw new VObject\ParseException('Object validation failed: missing mandatory object properties');
commit 1e2898da5ac091607d006365388bc416de8b122a
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Nov 12 11:54:24 2014 +0100
Fix TRIGGER properties with absilute date-time values (#3881)
diff --git a/plugins/libcalendaring/libvcalendar.php b/plugins/libcalendaring/libvcalendar.php
index 3331b4e..0965064 100644
--- a/plugins/libcalendaring/libvcalendar.php
+++ b/plugins/libcalendaring/libvcalendar.php
@@ -500,7 +500,7 @@ class libvcalendar implements Iterator
}
}
$attendee = self::map_keys($params, array_flip($this->attendee_keymap));
- $attendee['email'] = preg_replace('/^mailto:/i', '', $value);
+ $attendee['email'] = preg_replace('!^mailto:!i', '', $value);
if ($prop->name == 'ORGANIZER') {
$attendee['role'] = 'ORGANIZER';
@@ -583,11 +583,9 @@ class libvcalendar implements Iterator
switch ($prop->name) {
case 'TRIGGER':
- foreach ($prop->parameters() as $pname => $pvalue) {
- if ($pname == 'VALUE' && $pvalue == 'DATE-TIME') {
- $trigger = '@' . $prop->getDateTime()->format('U');
- $alarm['trigger'] = $prop->getDateTime();
- }
+ if ($prop['VALUE'] == 'DATE-TIME') {
+ $trigger = '@' . $prop->getDateTime()->format('U');
+ $alarm['trigger'] = $prop->getDateTime();
}
if (!$trigger && ($values = libcalendaring::parse_alaram_value($value))) {
$trigger = $values[2];
@@ -616,7 +614,7 @@ class libvcalendar implements Iterator
break;
case 'ATTENDEE':
- $alarm['attendees'][] = preg_replace('/^mailto:/i', '', $value);
+ $alarm['attendees'][] = preg_replace('!^mailto:!i', '', $value);
break;
case 'ATTACH':
@@ -688,7 +686,7 @@ class libvcalendar implements Iterator
break;
case 'ORGANIZER':
- $this->freebusy['organizer'] = preg_replace('/^mailto:/i', '', $value);
+ $this->freebusy['organizer'] = preg_replace('!^mailto:!i', '', $value);
break;
case 'FREEBUSY':
@@ -813,7 +811,7 @@ class libvcalendar implements Iterator
* @param boolean Set as UTC date
* @param boolean Set as VALUE=DATE property
*/
- public function datetime_prop($cal, $name, $dt, $utc = false, $dateonly = null)
+ public function datetime_prop($cal, $name, $dt, $utc = false, $dateonly = null, $set_type = false)
{
if ($utc) {
$dt->setTimeZone(new \DateTimeZone('UTC'));
@@ -823,12 +821,14 @@ class libvcalendar implements Iterator
$is_utc = ($tz = $dt->getTimezone()) && in_array($tz->getName(), array('UTC','GMT','Z'));
}
$is_dateonly = $dateonly === null ? (bool)$dt->_dateonly : (bool)$dateonly;
- $vdt = $cal->createProperty($name);
- $vdt->setValue($dt);
+ $vdt = $cal->createProperty($name, $dt, null, $is_dateonly ? 'DATE' : 'DATE-TIME');
if ($is_dateonly) {
$vdt['VALUE'] = 'DATE';
}
+ else if ($set_type) {
+ $vdt['VALUE'] = 'DATE-TIME';
+ }
// register timezone for VTIMEZONE block
if (!$is_utc && !$dateonly && $tz && ($tzname = $tz->getName())) {
@@ -1055,7 +1055,7 @@ class libvcalendar implements Iterator
$va = $cal->createComponent('VALARM');
$va->action = $alarm['action'];
if ($alarm['trigger'] instanceof DateTime) {
- $va->add($this->datetime_prop($cal, 'TRIGGER', $alarm['trigger'], true));
+ $va->add($this->datetime_prop($cal, 'TRIGGER', $alarm['trigger'], true, null, true));
}
else {
$va->add('TRIGGER', $alarm['trigger']);
@@ -1090,7 +1090,7 @@ class libvcalendar implements Iterator
if ($val[3])
$va->add('TRIGGER', $val[3]);
else if ($val[0] instanceof DateTime)
- $va->add($this->datetime_prop($cal, 'TRIGGER', $val[0]));
+ $va->add($this->datetime_prop($cal, 'TRIGGER', $val[0], true, null, true));
$ve->add($va);
}
diff --git a/plugins/libcalendaring/tests/libvcalendar.php b/plugins/libcalendaring/tests/libvcalendar.php
index eff827c..80752c0 100644
--- a/plugins/libcalendaring/tests/libvcalendar.php
+++ b/plugins/libcalendaring/tests/libvcalendar.php
@@ -215,13 +215,14 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase
$this->assertEquals('DISPLAY', $event['valarms'][0]['action'], "First alarm action");
$this->assertEquals('This is the first event reminder', $event['valarms'][0]['description'], "First alarm text");
- $this->assertEquals(2, count($event['valarms']), "List all VALARM blocks");
+ $this->assertEquals(3, count($event['valarms']), "List all VALARM blocks");
$valarm = $event['valarms'][1];
$this->assertEquals(1, count($valarm['attendees']), "Email alarm attendees");
$this->assertEquals('EMAIL', $valarm['action'], "Second alarm item (action)");
$this->assertEquals('-P1D', $valarm['trigger'], "Second alarm item (trigger)");
$this->assertEquals('This is the reminder message', $valarm['summary'], "Email alarm text");
+ $this->assertInstanceOf('DateTime', $event['valarms'][2]['trigger'], "Absolute trigger date/time");
// test alarms export
$ics = $ical->export(array($event));
@@ -230,6 +231,7 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase
$this->assertContains('DESCRIPTION:This is the first event reminder', $ics, "Alarm description");
$this->assertContains('SUMMARY:This is the reminder message', $ics, "Email alarm summary");
$this->assertContains('ATTENDEE:mailto:reminder-recipient at example.org', $ics, "Email alarm recipient");
+ $this->assertContains('TRIGGER;VALUE=DATE-TIME:20130812', $ics, "Date-Time trigger");
}
/**
diff --git a/plugins/libcalendaring/tests/resources/alarms.ics b/plugins/libcalendaring/tests/resources/alarms.ics
index d6f9d54..9d58854 100644
--- a/plugins/libcalendaring/tests/resources/alarms.ics
+++ b/plugins/libcalendaring/tests/resources/alarms.ics
@@ -46,6 +46,11 @@ ATTENDEE:mailto:reminder-recipient at example.org
SUMMARY:This is the reminder message
DESCRIPTION:This is the second event reminder
END:VALARM
+BEGIN:VALARM
+ACTION:DISPLAY
+DESCRIPTION:An absolute reminder
+TRIGGER;VALUE=DATE-TIME:20130812T160000Z
+END:VALARM
END:VEVENT
END:VCALENDAR
More information about the commits
mailing list