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

This commit is contained in:
Ralf Becker 2010-12-02 22:27:32 +00:00
parent 96d44948f7
commit 9981730b29
3 changed files with 61 additions and 31 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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");