From 9981730b29dc158004de1a76b69e69772d468bca Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 2 Dec 2010 22:27:32 +0000 Subject: [PATCH] moved ctag to calendar_bo, to use it in CalDAV and ActiveSync, thought it needs to be reworked, as it is to expensive performance-wise --- .../inc/class.calendar_activesync.inc.php | 26 ++++++++++++-- calendar/inc/class.calendar_bo.inc.php | 36 +++++++++++++++++++ calendar/inc/class.calendar_groupdav.inc.php | 30 +--------------- 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/calendar/inc/class.calendar_activesync.inc.php b/calendar/inc/class.calendar_activesync.inc.php index f2419b1c88..ef4da1a1d6 100644 --- a/calendar/inc/class.calendar_activesync.inc.php +++ b/calendar/inc/class.calendar_activesync.inc.php @@ -308,10 +308,32 @@ list(,,$etag) = explode(':',$etag); } /** - * @todo implement using ctag + * Return a changes array + * + * if changes occurr default diff engine computes the actual changes + * + * @param string $folderid + * @param string &$syncstate on call old syncstate, on return new syncstate + * @return array|boolean false if $folderid not found, array() if no changes or array(array("type" => "fakeChange")) */ function AlterPingChanges($folderid, &$syncstate) { - return false; + $this->backend->splitID($folderid, $type, $owner); + + if ($type != 'calendar') return false; + + if (!isset($this->calendar)) $this->calendar = new calendar_boupdate(); + $ctag = $this->calendar->get_ctag($owner); + + $changes = array(); // no change + $syncstate_was = $syncstate; + + if ($ctag !== $syncstate) + { + $syncstate = $ctag; + $changes = array(array('type' => 'fakeChange')); + } + //error_log(__METHOD__."('$folderid','$syncstate_was') syncstate='$syncstate' returning ".array2string($changes)); + return $changes; } } diff --git a/calendar/inc/class.calendar_bo.inc.php b/calendar/inc/class.calendar_bo.inc.php index 03c5db2477..d17815c081 100644 --- a/calendar/inc/class.calendar_bo.inc.php +++ b/calendar/inc/class.calendar_bo.inc.php @@ -1908,4 +1908,40 @@ class calendar_bo //error_log(__METHOD__ . "($entry[id] ($entry[etag]): $entry[title] --> etag=$etag"); return $etag; } + + /** + * Query ctag for calendar + * + * @param $user + * @param $filter='owner' + * @return string + * @todo use MAX(modified) to query everything in one sql query, currently we do one query per event (more then the search) + */ + public function get_ctag($user,$filter='owner') + { + $filter = array( + 'users' => $user, + 'start' => $this->bo->now - 100*24*3600, // default one month back -30 breaks all sync recurrences + 'end' => $this->bo->now + 365*24*3600, // default one year into the future +365 + 'enum_recuring' => false, + 'daywise' => false, + 'date_format' => 'server', + 'cols' => array('egw_cal.cal_id', 'cal_start', 'cal_modified'), + 'filter' => $filter, + ); + + $ctag = 0; + if (($events =& $this->bo->search($filter))) + { + foreach ($events as $event) + { + $modified = max($this->bo->so->max_user_modified($event['cal_id']), $event['cal_modified']); + if ($ctag < $modified) $ctag = $modified; + } + } + + if ($this->debug > 1) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. "($path)[$user] = $ctag"); + + return $ctag; + } } diff --git a/calendar/inc/class.calendar_groupdav.inc.php b/calendar/inc/class.calendar_groupdav.inc.php index 1c10d586bd..9959f9918e 100644 --- a/calendar/inc/class.calendar_groupdav.inc.php +++ b/calendar/inc/class.calendar_groupdav.inc.php @@ -790,35 +790,7 @@ error_log(__METHOD__."($path,,".array2string($start).") filter=".array2string($f */ public function getctag($path,$user) { - $filter = array( - 'users' => $user, - 'start' => $this->bo->now - 100*24*3600, // default one month back -30 breaks all sync recurrences - 'end' => $this->bo->now + 365*24*3600, // default one year into the future +365 - 'enum_recuring' => false, - 'daywise' => false, - 'date_format' => 'server', - 'cols' => array('egw_cal.cal_id', 'cal_start', 'cal_modified'), - ); - - if ($path == '/calendar/') - { - $filter['filter'] = 'owner'; - } - else - { - $filter['filter'] = 'default'; // not rejected - } - - $ctag = 0; - - if (($events =& $this->bo->search($filter))) - { - foreach ($events as $event) - { - $modified = max($this->bo->so->max_user_modified($event['cal_id']), $event['cal_modified']); - if ($ctag < $modified) $ctag = $modified; - } - } + $ctag = $this->bo->get_ctag($user,$path == '/calendar/' ? 'owner' : 'default'); // default = not rejected if ($this->debug > 1) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. "($path)[$user] = $ctag");