[dev] [kronolith-patch] delete events
Francois Marier
francois at nit.ca
Tue Jul 27 16:07:16 PDT 2004
Here's a patch that fixes two minor bugs related to deleting recurring
events in Kronolith:
1- If you delete all recurrences of an event one by one by clicking
the "Current" button on the Delete page, each of these deletes will
add an exception to the Event in the Database (I am using the MySQL
driver). After deleting all recurrences, nothing will be shown on the
Monthly page for example, but the event will still be in the Database.
2- If you create a recurring event and then delete the first
recurrence and click "Future", then the first recurrence will not be
deleted (it is still shown in the Monthly page), contrary to what the
caption says. This patch will add an exception so that it is not
shown.
There is however one remaining bug (not introduced by this patch
though):
When creating a recurring event and deleting all recurrences
by clicking the delete button on the first recurrence and then
clicking the "Future" button, the event will still remain in the
database even though it's not shown anymore.
>From what I gathered, the Driver's nextRecurrence() method returns a
date after the recurrence end and so the check introduced by this
patch ( roughly: if !exceptionOn(nextRecurrence) ) will return false.
It looks like this last bug was introduced more or less recently since
it doesn't occur in the Alpha version of Kronolith.
Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/kronolith/deleventaction.php kronolith/deleventaction.php
--- ../build/kronolith/deleventaction.php Thu Mar 11 22:40:06 2004
+++ kronolith/deleventaction.php Tue Jul 13 19:51:41 2004
@@ -11,6 +11,28 @@
define('KRONOLITH_BASE', dirname(__FILE__));
require_once KRONOLITH_BASE . '/lib/base.php';
+function hasActiveRecur($calendar, $event)
+{
+ if (!$event->hasRecurEnd()) {
+ return true;
+ }
+
+ $eventID = $event->getID();
+ $start_date = array('year' => $event->getStartDate('Y'),
+ 'month' => $event->getStartDate('m'),
+ 'mday' => $event->getStartDate('d'));
+
+ $next = $calendar->nextRecurrence($eventID, $start_date);
+ while (is_object($next)) {
+ if (!$event->hasException($next->year, $next->month, $next->mday))
+ return true;
+
+ $next = $calendar->nextRecurrence($eventID, array('year' => $next->year, 'month' => $next->month, 'mday' => $next->mday + 1, 'hour' => $next->hour, 'min' => $next->min, 'sec' => $next->sec));
+ }
+
+ return false;
+}
+
$kronolith->open(Util::getFormData('calendar'));
if ($eventID = Util::getFormData('eventID')) {
$event = &$kronolith->getEvent($eventID);
@@ -29,19 +51,25 @@ if ($eventID = Util::getFormData('eventI
Kronolith::sendITipNotifications($event, $notification, KRONOLITH_ITIP_CANCEL);
}
- if ($event->hasRecurType(KRONOLITH_RECUR_NONE) || Util::getFormData('all')) {
- $kronolith->deleteEvent($event->getID());
- } elseif (Util::getFormData('future')) {
+ if (Util::getFormData('future')) {
$event->setRecurEndTimestamp(mktime(1, 1, 1,
Util::getFormData('month', date('n')),
Util::getFormData('mday', date('j')) - 1,
Util::getFormData('year', date('Y'))));
+ $event->addException(Util::getFormData('year'),
+ Util::getFormData('month'),
+ Util::getFormData('mday'));
$event->save();
} elseif (Util::getFormData('current')) {
$event->addException(Util::getFormData('year'),
Util::getFormData('month'),
Util::getFormData('mday'));
$event->save();
+ }
+
+ if ($event->hasRecurType(KRONOLITH_RECUR_NONE) ||
+ Util::getFormData('all') || !hasActiveRecur($kronolith, $event)) {
+ $kronolith->deleteEvent($event->getID());
}
}
}
More information about the dev
mailing list