Hi devs,
while migrating from my 1.7. /trunk setup to a more current version I encountered an issue with repeating events. I am aware that having /trunk in production is not a good idea in most cases and I have to care for myself with the problems created by this. But maybe this will help other users to have a more clean install.
Ok, now the problem:
On my /trunk install a repeating event does not delete exceptions which are older than the start date of the event if the user moves the start date onwards. This is fixed in current EGw versions but I think the upgrade routine should handle this also when moving the recur_exception field to egw_cal_dates.
This is the current process:
function calendar_upgrade1_9_004()
{
$GLOBALS[‘egw_setup’]->oProc->AddColumn(‘egw_cal_dates’,‘recur_exception’,array(
…
// migrate existing exceptions to egw_cal_dates
foreach($GLOBALS[‘egw_setup’]->db->select(‘egw_cal_repeats’,
‘egw_cal_repeats.cal_id AS cal_id,egw_cal_repeats.recur_exception AS recur_exception,MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end’,
‘egw_cal_repeats.recur_exception IS NOT NULL’, LINE, FILE, false,
‘GROUP BY egw_cal_repeats.cal_id,egw_cal_repeats.recur_exception’, ‘calendar’, ‘’,
‘JOIN egw_cal_dates ON egw_cal_repeats.cal_id=egw_cal_dates.cal_id’) as $row)
{
foreach($row[‘recur_exception’] ? explode(’,’, $row[‘recur_exception’]) : array() as $recur_exception)
{
$GLOBALS[‘egw_setup’]->db->insert(‘egw_cal_dates’, array(
‘cal_id’ => $row[‘cal_id’],
‘cal_start’ => $recur_exception,
‘cal_end’ => $recur_exception+$row[‘cal_end’]-$row[‘cal_start’],
‘recur_exception’ => true,
), false, LINE, FILE, ‘calendar’);
}
}
We should ignore a $recur_exception < $row[‘cal_start’] here. I post a little example what the current process does:
Before Upgrade (we have an exception which is older than the current start date)
±-------±-----------±--------------±---------------±-----------±----------------+
| cal_id | recur_type | recur_enddate | recur_interval | recur_data | recur_exception |
±-------±-----------±--------------±---------------±-----------±----------------+
| 70807 | 5 | 0 | 1 | 0 | 1268632800 |
±-------±-----------±--------------±---------------±-----------±----------------+
±-------±-----------±-----------±-------------------------+
| cal_id | cal_start | cal_end | from_unixtime(cal_start) |
±-------±-----------±-----------±-------------------------+
| 70807 | 1300143600 | 1300229940 | 2011-03-15 00:00:00 |
| 70807 | 1331766000 | 1331852340 | 2012-03-15 00:00:00 |
| 70807 | 1363302000 | 1363388340 | 2013-03-15 00:00:00 |
| 70807 | 1394838000 | 1394924340 | 2014-03-15 00:00:00 |
| 70807 | 1426374000 | 1426460340 | 2015-03-15 00:00:00 |
±-------±-----------±-----------±-------------------------+
After upgrade (the exception in the past is now the new startdate):
±-------±-----------±-----------±----------------±-------------------------+
| cal_id | cal_start | cal_end | recur_exception | from_unixtime(cal_start) |
±-------±-----------±-----------±----------------±-------------------------+
| 70807 | 1268632800 | 1268719140 | 1 | 2010-03-15 07:00:00 |
| 70807 | 1300143600 | 1300229940 | 0 | 2011-03-15 00:00:00 |
| 70807 | 1331766000 | 1331852340 | 0 | 2012-03-15 00:00:00 |
| 70807 | 1363302000 | 1363388340 | 0 | 2013-03-15 00:00:00 |
| 70807 | 1394838000 | 1394924340 | 0 | 2014-03-15 00:00:00 |
| 70807 | 1426374000 | 1426460340 | 0 | 2015-03-15 00:00:00 |
±-------±-----------±-----------±----------------±-------------------------+
Apart from having a cal_start time at 07:00 now (this is my next problem and should be set to 00:00 in this case), this row does not make sense and should not be created. Instead the exception should be deleted completely for this $recur_exception, including the whole event row of the exception in egw_cal.
What do you think?
Greetings
Christian