different method to read the next occourrence of a series; (as old method also fetched deleted exeptions as next occurrence)

This commit is contained in:
Klaus Leithoff 2012-12-07 14:10:51 +00:00
parent 9fc51055cd
commit 0be74c9b87
2 changed files with 58 additions and 6 deletions

View File

@ -1004,10 +1004,11 @@ class calendar_boupdate extends calendar_bo
$ret = $this->send_update(MSG_ALARM,$to_notify,$event,False,$alarm['owner']);
// create a new alarm for recuring events for the next event, if one exists
if ($event['recur_type'] && ($event = $this->read($alarm['cal_id'],$event_time_user+1)))
if ($event['recur_type'] != MCAL_RECUR_NONE && ($event = $this->read($alarm['cal_id'],$event_time_user+1)))
{
$alarm['time'] = $this->date2ts($event['start']) - $alarm['offset'];
unset($alarm['times']);
unset($alarm['next']);
$this->save_alarm($alarm['cal_id'],$alarm);
}
return $ret;
@ -1503,26 +1504,43 @@ class calendar_boupdate extends calendar_bo
{
foreach($event['alarm'] as &$alarm)
{
if ($alarm['time'] == $recur_date)
if (($alarm['time'] == $recur_date) || ($alarm['time']+$alarm['offset'] == $recur_date))
{
//error_log(__METHOD__.__LINE__.'->'.array2string($recur_date));
//error_log(__METHOD__.__LINE__.array2string($event));
if (is_null($next_recurrance))
{
$checkdate = $recur_date;
//if ($alarm['time']+$alarm['offset'] == $recur_date) $checkdate = $recur_date + $alarm['offset'];
if ($e = $this->read($cal_id,$checkdate+1))
{
$next_recurrance = $this->date2ts($e['start']);
}
/*
foreach(calendar_rrule::event2rrule($event, true) as $time)
{
$time->setUser(); // $time is in timezone of event, convert it to usertime used here
if (($next_recurrance = $this->date2ts($time)) > $recur_date) break;
$next_recurrance = $this->date2ts($time);
if ($next_recurrance > $checkdate) break;
}
*/
//error_log(__METHOD__.__LINE__." $next_recurrance > $checkdate");
}
$alarm['time'] = $this->date2ts($next_recurrance, true); // user to server-time
$alarm['cal_id'] = $cal_id;
unset($alarm['times']);
unset($alarm['next']);
$this->so->save_alarm($event['id'], $alarm);
}
}
}
// need to read series master, as otherwise existing exceptions will be lost!
$recur_date = $this->date2ts($event['start']);
//if ($event['alarm']) $alarmbuffer = $event['alarm'];
$event = $this->read($cal_id);
//if (isset($alarmbuffer)) $event['alarm'] = $alarmbuffer;
$event['recur_exception'][] = $recur_date;
$this->save($event); // updates the content-history
$this->save($event);// updates the content-history
}
if ($event['reference'])
{

View File

@ -136,6 +136,7 @@ class calendar_so
*/
function read($ids,$recur_date=0)
{
//_debug_array(__METHOD__.__LINE__.'#'.$recur_date.'#'.function_backtrace());
if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
{
$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
@ -225,6 +226,39 @@ class calendar_so
}
break; // as above select read all exceptions (and I dont think too short uid problem still exists)
}
// make sure we fetch only real exceptions (deleted occurrences of a series should not show up)
if (($recur_date && $event['recur_type'] != MCAL_RECUR_NONE))
{
//_debug_array(__METHOD__.__LINE__.' recur_date:'.$recur_date.' check cal_start:'.$event['start']);
foreach(($i=$this->db->select($this->dates_table, 'cal_id,cal_start', array(
'cal_id' => $event['id'],
'cal_start' => $event['start'],
'recur_exception' => true,
), __LINE__, __FILE__, false, '', 'calendar')) as $row)
{
$isException[$row['cal_id']] = true;
}
//_debug_array($i->sql.'-> found Rows:'.$i->_numOfRows);
if ($isException[$event['id']])
{
$x = $this->db->select($this->cal_table, 'cal_id', array(
'cal_uid' => $event['uid'],
'cal_recurrence' => $event['start'],
'cal_deleted' => NULL
), __LINE__, __FILE__, false, '', 'calendar');
//_debug_array(__METHOD__.__LINE__.$x->sql.'-> found Rows:'.$x->_numOfRows);
if (empty($x->_numOfRows))
{
$e = $this->read($event['id'],$event['start']+1);
$event = $e[$event['id']];
break;
}
else
{
//real exception -> should we return it? probably not, so we live with the result of the next occurrence of the series
}
}
}
}
// check if we have a real recurance, if not set $recur_date=0
@ -1825,7 +1859,7 @@ ORDER BY cal_user_type, cal_usre_id
$this->async->cancel_timer($id);
}
$alarm['cal_id'] = $cal_id; // we need the back-reference
//error_log(__METHOD__.__LINE__.' Save Alarm for CalID:'.$cal_id.'->'.array2string($alarm).'-->'.$id.'#'.function_backtrace());
// allways store job with the alarm owner as job-owner to get eg. the correct from address
if (!$this->async->set_timer($alarm['time'],$id,'calendar.calendar_boupdate.send_alarm',$alarm,$alarm['owner']))
{