Fix egw_ical_iterator issue; special CalDAV treatment for lightning

This commit is contained in:
Jörg Lehrke 2010-05-21 16:52:05 +00:00
parent 3650f8f222
commit 2c1e4b28ce
2 changed files with 97 additions and 63 deletions

View File

@ -249,13 +249,20 @@ class calendar_ical extends calendar_boupdate
{ {
if ($this->read($event, $recurrence, true, 'server')) if ($this->read($event, $recurrence, true, 'server'))
{ {
if ($this->log) if ($this->bo->check_perms(EGW_ACL_FREEBUSY, $event, 0, 'server'))
{ {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. $this->bo->clear_private_infos($event, array($this->user, $event['owner']));
'() User does not have the permission to read event ' . $event['id']. "\n", }
3,$this->logfile); else
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'() User does not have the permission to read event ' . $event['id']. "\n",
3,$this->logfile);
}
return -1; // Permission denied
} }
return -1; // Permission denied
} }
else else
{ {
@ -574,16 +581,20 @@ class calendar_ical extends calendar_boupdate
break; break;
case 'DTSTART': case 'DTSTART':
if (!isset($event['whole_day'])) if (empty($event['whole_day']))
{ {
$attributes['DTSTART'] = self::getDateTime($event['start'],$tzid,$parameters['DTSTART']); $attributes['DTSTART'] = self::getDateTime($event['start'],$tzid,$parameters['DTSTART']);
} }
break; break;
case 'DTEND': case 'DTEND':
// write start + end of whole day events as dates if (empty($event['whole_day']))
if (isset($event['whole_day']))
{ {
$attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']);
}
else
{
// write start + end of whole day events as dates
$event['end-nextday'] = $event['end'] + 12*3600; // we need the date of the next day, as DTEND is non-inclusive (= exclusive) in rfc2445 $event['end-nextday'] = $event['end'] + 12*3600; // we need the date of the next day, as DTEND is non-inclusive (= exclusive) in rfc2445
foreach (array('start' => 'DTSTART','end-nextday' => 'DTEND') as $f => $t) foreach (array('start' => 'DTSTART','end-nextday' => 'DTEND') as $f => $t)
{ {
@ -594,10 +605,6 @@ class calendar_ical extends calendar_boupdate
} }
unset($attributes['DTSTART']); unset($attributes['DTSTART']);
} }
else
{
$attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']);
}
break; break;
case 'RRULE': case 'RRULE':
@ -619,9 +626,17 @@ class calendar_ical extends calendar_boupdate
if ($event['recur_type'] == MCAL_RECUR_NONE) break; if ($event['recur_type'] == MCAL_RECUR_NONE) break;
if (!empty($event['recur_exception'])) if (!empty($event['recur_exception']))
{ {
// use 'DATE' instead of 'DATE-TIME' on whole day events if (empty($event['whole_day']))
if (isset($event['whole_day']))
{ {
$value_type = 'DATE-TIME';
foreach ($event['recur_exception'] as $key => $timestamp)
{
$event['recur_exception'][$key] = self::getDateTime($timestamp,$tzid,$parameters['EXDATE']);
}
}
else
{
// use 'DATE' instead of 'DATE-TIME' on whole day events
$value_type = 'DATE'; $value_type = 'DATE';
foreach ($event['recur_exception'] as $id => $timestamp) foreach ($event['recur_exception'] as $id => $timestamp)
{ {
@ -636,14 +651,7 @@ class calendar_ical extends calendar_boupdate
} }
$event['recur_exception'] = $days; $event['recur_exception'] = $days;
} }
else
{
$value_type = 'DATE-TIME';
foreach ($event['recur_exception'] as $key => $timestamp)
{
$event['recur_exception'][$key] = self::getDateTime($timestamp,$tzid,$parameters['EXDATE']);
}
}
$attributes['EXDATE'] = ''; $attributes['EXDATE'] = '';
$values['EXDATE'] = $event['recur_exception']; $values['EXDATE'] = $event['recur_exception'];
$parameters['EXDATE']['VALUE'] = $value_type; $parameters['EXDATE']['VALUE'] = $value_type;
@ -700,7 +708,11 @@ class calendar_ical extends calendar_boupdate
if ($recur_date) if ($recur_date)
{ {
// We handle a pseudo exception // We handle a pseudo exception
if (isset($event['whole_day'])) if (empty($event['whole_day']))
{
$attributes[$icalFieldName] = self::getDateTime($recur_date,$tzid,$parameters[$icalFieldName]);
}
else
{ {
$time = new egw_time($recur_date,egw_time::$server_timezone); $time = new egw_time($recur_date,egw_time::$server_timezone);
$time->setTimezone(self::$tz_cache[$event['tzid']]); $time->setTimezone(self::$tz_cache[$event['tzid']]);
@ -712,17 +724,17 @@ class calendar_ical extends calendar_boupdate
array('VALUE' => 'DATE') array('VALUE' => 'DATE')
); );
} }
else
{
$attributes[$icalFieldName] = self::getDateTime($recur_date,$tzid,$parameters[$icalFieldName]);
}
} }
elseif ($event['recurrence'] && $event['reference']) elseif ($event['recurrence'] && $event['reference'])
{ {
// $event['reference'] is a calendar_id, not a timestamp // $event['reference'] is a calendar_id, not a timestamp
if (!($revent = $this->read($event['reference']))) break; // referenced event does not exist if (!($revent = $this->read($event['reference']))) break; // referenced event does not exist
if (isset($revent['whole_day'])) if (empty($revent['whole_day']))
{
$attributes[$icalFieldName] = self::getDateTime($event['recurrence'],$tzid,$parameters[$icalFieldName]);
}
else
{ {
$time = new egw_time($event['recurrence'],egw_time::$server_timezone); $time = new egw_time($event['recurrence'],egw_time::$server_timezone);
$time->setTimezone(self::$tz_cache[$event['tzid']]); $time->setTimezone(self::$tz_cache[$event['tzid']]);
@ -734,10 +746,7 @@ class calendar_ical extends calendar_boupdate
array('VALUE' => 'DATE') array('VALUE' => 'DATE')
); );
} }
else
{
$attributes[$icalFieldName] = self::getDateTime($event['recurrence'],$tzid,$parameters[$icalFieldName]);
}
unset($revent); unset($revent);
} }
break; break;
@ -1059,13 +1068,25 @@ class calendar_ical extends calendar_boupdate
// and for real (not status only) exceptions their recurrence-id need // and for real (not status only) exceptions their recurrence-id need
// to be included as recur_exception to the master // to be included as recur_exception to the master
if ($this->productManufacturer == 'groupdav' && $cal_id > 0 && if ($this->productManufacturer == 'groupdav' && $cal_id > 0 &&
count($events) > 1 && !$events[1]['id'] &&
$events[0]['recur_type'] != MCAL_RECUR_NONE) $events[0]['recur_type'] != MCAL_RECUR_NONE)
{ {
calendar_groupdav::fix_series($events); calendar_groupdav::fix_series($events);
} }
if ($this->tzid)
{
$tzid = $this->tzid;
}
else
{
$tzid = egw_time::$user_timezone->getName();
}
date_default_timezone_set($tzid);
foreach ($events as $event) foreach ($events as $event)
{ {
if (!is_array($event)) continue; // the iterator may return false
++$this->events_imported; ++$this->events_imported;
if ($this->so->isWholeDay($event)) $event['whole_day'] = true; if ($this->so->isWholeDay($event)) $event['whole_day'] = true;
@ -1122,6 +1143,12 @@ class calendar_ical extends calendar_boupdate
// common adjustments for existing events // common adjustments for existing events
if (is_array($event_info['stored_event'])) if (is_array($event_info['stored_event']))
{ {
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
. "(UPDATE Event)\n"
. array2string($event_info['stored_event'])."\n",3,$this->logfile);
}
if (empty($event['uid'])) if (empty($event['uid']))
{ {
$event['uid'] = $event_info['stored_event']['uid']; // restore the UID if it was not delivered $event['uid'] = $event_info['stored_event']['uid']; // restore the UID if it was not delivered
@ -1225,7 +1252,7 @@ class calendar_ical extends calendar_boupdate
} }
} }
if ($event['whole_day'] && $event['tzid'] != $event_info['stored_event']['tzid']) if (!empty($event['whole_day']) && $event['tzid'] != $event_info['stored_event']['tzid'])
{ {
// Adjust dates to original TZ // Adjust dates to original TZ
$time = new egw_time($event['start'],egw_time::$server_timezone); $time = new egw_time($event['start'],egw_time::$server_timezone);
@ -1244,7 +1271,7 @@ class calendar_ical extends calendar_boupdate
$event['recur_exception'][$key] = egw_time::to($time,'server'); $event['recur_exception'][$key] = egw_time::to($time,'server');
} }
} }
elseif($event['recurrence']) elseif ($event['recurrence'])
{ {
$time = new egw_time($event['recurrence'],egw_time::$server_timezone); $time = new egw_time($event['recurrence'],egw_time::$server_timezone);
$time =& $this->so->startOfDay($time, $event_info['stored_event']['tzid']); $time =& $this->so->startOfDay($time, $event_info['stored_event']['tzid']);
@ -1264,7 +1291,7 @@ class calendar_ical extends calendar_boupdate
{ {
unset($event['id']); unset($event['id']);
// set non blocking all day depending on the user setting // set non blocking all day depending on the user setting
if (isset($event['whole_day']) && $this->nonBlockingAllday) if (!empty($event['whole_day']) && $this->nonBlockingAllday)
{ {
$event['non_blocking'] = 1; $event['non_blocking'] = 1;
} }
@ -1277,6 +1304,7 @@ class calendar_ical extends calendar_boupdate
} }
else else
{ {
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
return 0; // no permission return 0; // no permission
} }
} }
@ -1375,6 +1403,13 @@ class calendar_ical extends calendar_boupdate
} }
} }
} }
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '('
. $event_info['type'] . ")\n"
. array2string($event)."\n",3,$this->logfile);
}
// save event depending on the given event type // save event depending on the given event type
switch ($event_info['type']) switch ($event_info['type'])
@ -1681,10 +1716,7 @@ class calendar_ical extends calendar_boupdate
array2string($event_info['stored_event'])."\n",3,$this->logfile); array2string($event_info['stored_event'])."\n",3,$this->logfile);
} }
} }
if (is_resource($_vcalData)) date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
{
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
}
return $return_id; return $return_id;
} }
@ -2077,6 +2109,14 @@ class calendar_ical extends calendar_boupdate
array2string($_vcalData)."\n",3,$this->logfile); array2string($_vcalData)."\n",3,$this->logfile);
} }
if (!is_array($this->supportedFields)) $this->setSupportedFields();
// we use egw_ical_iterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0])
if (is_resource($_vcalData))
{
return new egw_ical_iterator($_vcalData,'VCALENDAR',$charset,array($this,'_ical2egw_callback'),array($this->tzid,$principalURL));
}
if ($this->tzid) if ($this->tzid)
{ {
$tzid = $this->tzid; $tzid = $this->tzid;
@ -2085,16 +2125,9 @@ class calendar_ical extends calendar_boupdate
{ {
$tzid = egw_time::$user_timezone->getName(); $tzid = egw_time::$user_timezone->getName();
} }
date_default_timezone_set($tzid); date_default_timezone_set($tzid);
if (!is_array($this->supportedFields)) $this->setSupportedFields();
// we use egw_ical_iterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0])
if (is_resource($_vcalData))
{
return new egw_ical_iterator($_vcalData,'VCALENDAR',$charset,array($this,'_ical2egw_callback'),array($tzid,$principalURL));
}
$events = array(); $events = array();
$vcal = new Horde_iCalendar; $vcal = new Horde_iCalendar;
if (!$vcal->parsevCalendar($_vcalData, 'VCALENDAR', $charset)) if (!$vcal->parsevCalendar($_vcalData, 'VCALENDAR', $charset))
@ -2104,17 +2137,14 @@ class calendar_ical extends calendar_boupdate
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"(): No vCalendar Container found!\n",3,$this->logfile); "(): No vCalendar Container found!\n",3,$this->logfile);
} }
if ($this->tzid) date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
{
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
}
return false; return false;
} }
$version = $vcal->getAttribute('VERSION'); $version = $vcal->getAttribute('VERSION');
foreach ($vcal->getComponents() as $n => $component) foreach ($vcal->getComponents() as $n => $component)
{ {
if (($event = $this->_ical2egw_callback($component,$tzid,$principalURL))) if (($event = $this->_ical2egw_callback($component,$this->tzid,$principalURL)))
{ {
$events[] = $event; $events[] = $event;
} }
@ -2132,17 +2162,18 @@ class calendar_ical extends calendar_boupdate
* @param string $principalURL='' Used for CalDAV imports * @param string $principalURL='' Used for CalDAV imports
* @return array|boolean event array or false if $component is no Horde_iCalendar_vevent * @return array|boolean event array or false if $component is no Horde_iCalendar_vevent
*/ */
function _ical2egw_callback(Horde_iCalendar $component,$tzid,$principalURL='') function _ical2egw_callback(Horde_iCalendar &$component, $tzid, $principalURL='')
{ {
//unset($component->_container); _debug_array($component); //unset($component->_container); _debug_array($component);
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'() '.get_class($component)." found\n",3,$this->logfile);
}
if (!is_a($component, 'Horde_iCalendar_vevent') || if (!is_a($component, 'Horde_iCalendar_vevent') ||
!($event = $this->vevent2egw($component, $component->getAttribute('VERSION'), $this->supportedFields, $principalURL))) !($event = $this->vevent2egw($component, $component->getAttribute('VERSION'), $this->supportedFields, $principalURL)))
{ {
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'() '.get_class($component)." found\n",3,$this->logfile);
}
return false; return false;
} }
//common adjustments //common adjustments
@ -2167,7 +2198,7 @@ class calendar_ical extends calendar_boupdate
} }
} }
$event['alarm'] = $alarms; $event['alarm'] = $alarms;
if ($this->tzid || empty($event['tzid'])) if ($tzid || empty($event['tzid']))
{ {
$event['tzid'] = $tzid; $event['tzid'] = $tzid;
} }
@ -2197,7 +2228,7 @@ class calendar_ical extends calendar_boupdate
} }
$mozillaACK = $component->getAttribute('X-MOZ-LASTACK'); $mozillaACK = $component->getAttribute('X-MOZ-LASTACK');
if (!is_a($mozillaACK, 'PEAR_Error')) if ($this->productName == 'lightning' && !is_a($mozillaACK, 'PEAR_Error'))
{ {
if ($this->log) if ($this->log)
{ {
@ -3055,4 +3086,4 @@ class calendar_ical extends calendar_boupdate
return $vcal->exportvCalendar($charset); return $vcal->exportvCalendar($charset);
} }
} }

View File

@ -193,8 +193,10 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
//error_log(__METHOD__."() returning a ".gettype($this->component)); //error_log(__METHOD__."() returning a ".gettype($this->component));
if ($this->callback) if ($this->callback)
{ {
$ret = is_a($this->component,'Horde_iCalendar');
do { do {
if ($ret === false) $this->next(); if ($ret === false) $this->next();
if (!is_a($this->component,'Horde_iCalendar')) return false;
$params = $this->callback_params; $params = $this->callback_params;
array_unshift($params,$this->component); array_unshift($params,$this->component);
} }
@ -248,6 +250,7 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
if ($this->component === false) if ($this->component === false)
{ {
error_log(__METHOD__."() Horde_iCalendar::newComponent('$type', \$this) returned FALSE"); error_log(__METHOD__."() Horde_iCalendar::newComponent('$type', \$this) returned FALSE");
return;
//return PEAR::raiseError("Unable to create object for type $type"); //return PEAR::raiseError("Unable to create object for type $type");
} }
//error_log(__METHOD__."() about to call parsevCalendar('".substr($data,0,100)."...','$type','$this->charset')"); //error_log(__METHOD__."() about to call parsevCalendar('".substr($data,0,100)."...','$type','$this->charset')");
@ -292,7 +295,7 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
} }
$data .= $line; $data .= $line;
} }
// fake end of container, to get it parsed by Horde code // fake end of container to get it parsed by Horde code
if ($this->container) if ($this->container)
{ {
$data .= "END:$this->base\n"; $data .= "END:$this->base\n";