From a2b393317db59e4fc0dfd422bb978e476c790631 Mon Sep 17 00:00:00 2001 From: Jamie McClymont Date: Thu, 3 Jan 2019 13:57:20 +1300 Subject: [PATCH] Populate first_instance_start and last_instance_end on resource write --- inc/DAVResource.php | 9 +++++++++ inc/WritableCollection.php | 14 +++++++++++--- inc/caldav-PUT-functions.php | 19 +++++++++++++++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index 0cb1f7a3..8c7e973a 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -1287,6 +1287,15 @@ EOQRY; } + /** + * Returns the name of the timezone for this collection, or the collection containing this resource + */ + function timezone_name() { + if ( !isset($this->collection) ) $this->FetchCollection(); + return $this->collection->timezone; + } + + /** * Returns the database row for this resource */ diff --git a/inc/WritableCollection.php b/inc/WritableCollection.php index fc033784..112b073a 100644 --- a/inc/WritableCollection.php +++ b/inc/WritableCollection.php @@ -219,16 +219,23 @@ class WritableCollection extends DAVResource { $calitem_params[':due'] = $first->GetPValue('DUE'); $calitem_params[':percent_complete'] = $first->GetPValue('PERCENT-COMPLETE'); $calitem_params[':status'] = $first->GetPValue('STATUS'); + + $range = getVCalendarRange($vcal, $this->timezone_name()); + $calitem_params[':first_instance_start'] = isset($range->from) ? $range->from->UTC() : null; + $calitem_params[':last_instance_end'] = isset($range->until) ? $range->until->UTC() : null; + if ( $create_resource ) { $sql = <<GetPValue('PERCENT-COMPLETE'); $calitem_params[':status'] = $first->GetPValue('STATUS'); + // Intentionally not populating first_instance_start and last_instance_end + // here, As they may depend on the default tzid of the collection, which as + // I understand it hasn't yet been set + if ( $inserting ) { $created = $first->GetPValue('CREATED'); if ( $created == '00001231T000000Z' ) $created = '20001231T000000Z'; @@ -1596,7 +1600,11 @@ function write_resource( DAVResource $resource, $caldav_data, DAVResource $colle $calitem_params[':percent_complete'] = $first->GetPValue('PERCENT-COMPLETE'); $calitem_params[':status'] = $first->GetPValue('STATUS'); - // force re-render the object (to get the same representation for all attendiees) + $range = getVCalendarRange($vcal, $resource->timezone_name()); + $calitem_params[':first_instance_start'] = isset($range->from) ? $range->from->UTC() : null; + $calitem_params[':last_instance_end'] = isset($range->until) ? $range->until->UTC() : null; + + // force re-render the object (to get the same representation for all attendees) $vcal->Render(null, true); if ( !$collection->IsSchedulingCollection() ) { @@ -1632,11 +1640,13 @@ function write_resource( DAVResource $resource, $caldav_data, DAVResource $colle INSERT INTO calendar_item (user_no, dav_name, dav_id, dav_etag, uid, dtstamp, dtstart, dtend, summary, location, class, transp, description, rrule, tz_id, last_modified, url, priority, - created, due, percent_complete, status, collection_id ) + created, due, percent_complete, status, collection_id, + first_instance_start, last_instance_end ) VALUES ( :user_no, :dav_name, :dav_id, :etag, :uid, :dtstamp, :dtstart, $dtend, :summary, :location, :class, :transp, :description, :rrule, :tzid, :modified, :url, :priority, - :created, :due, :percent_complete, :status, :collection_id ) + :created, :due, :percent_complete, :status, $collection_id, + :first_instance_start, :last_instance_end) EOSQL; $sync_change = 201; $calitem_params[':collection_id'] = $collection_id; @@ -1650,7 +1660,8 @@ UPDATE calendar_item SET dav_etag=:etag, uid=:uid, dtstamp=:dtstamp, dtstart=:dtstart, dtend=$dtend, summary=:summary, location=:location, class=:class, transp=:transp, description=:description, rrule=:rrule, tz_id=:tzid, last_modified=:modified, url=:url, priority=:priority, - due=:due, percent_complete=:percent_complete, status=:status + due=:due, percent_complete=:percent_complete, status=:status, + first_instance_start=:first_instance_start, last_instance_end=:last_instance_end WHERE dav_id=:dav_id EOSQL; $sync_change = 200;