- moved ctag generation to addressbook_bo

- include deleted contacts in ctag generation, as otherwise deleting entries does NOT change ctag
This commit is contained in:
Ralf Becker 2011-01-05 05:26:32 +00:00
parent 907cb1aaa4
commit a7654640c4
3 changed files with 57 additions and 27 deletions

View File

@ -2066,4 +2066,40 @@ class addressbook_bo extends addressbook_so
}
return $matchingContacts;
}
/**
* Get a ctag (collection tag) for one addressbook or all addressbooks readable by a user
*
* Currently implemented as maximum modification date (1 seconde granularity!)
*
* We have to include deleted entries, as otherwise the ctag will not change if an entry gets deleted!
* (Only works if tracking of deleted entries / history is switched on!)
*
* @param int $owner=null 0=accounts, null=all addressbooks or integer account_id of user or group
* @return string
*/
public function get_ctag($owner=null)
{
$filter = array('tid' => null); // tid=null --> use all entries incl. deleted (tid='D')
// show addressbook of a single user?
if (!is_null($owner)) $filter['contact_owner'] = $owner;
// should we hide the accounts addressbook
if (!$owner && $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'])
{
$filter['account_id'] = null;
}
$result = $this->search(array(),'MAX(contact_modified) AS contact_modified','','','',false,'AND',false,$filter);
if (!$result || !isset($result[0]['contact_modified']))
{
$ctag = 'empty'; // ctag for empty addressbook
}
else
{
$ctag = $result[0]['contact_modified'];
}
//error_log(__METHOD__.'('.array2string($owner).') returning '.array2string($ctag));
return $ctag;
}
}

View File

@ -67,8 +67,8 @@ class addressbook_groupdav extends groupdav_handler
'X-ASSISTANT' => array('assistent'),
'X-ASSISTANT-TEL' => array('tel_assistent'),
'UID' => array('uid'),
);
);
/**
* Charset for exporting data, as some clients ignore the headers specifying the charset
*
@ -333,7 +333,7 @@ class addressbook_groupdav extends groupdav_handler
$charset = strtoupper(substr($value,1,-1));
}
}
}
}
}
if (is_array($oldContact))
@ -387,7 +387,7 @@ class addressbook_groupdav extends groupdav_handler
// only set owner, if user is explicitly specified in URL (check via prefix, NOT for /addressbook/ !)
if ($prefix)
{
// check for modified owners, if user has an add right for the new addressbook and
// check for modified owners, if user has an add right for the new addressbook and
// delete rights for the old addressbook (_common_get_put_delete checks for PUT only EGW_ACL_EDIT)
if ($oldContact && $user != $oldContact['owner'] && !($this->bo->grants[$user] & EGW_ACL_ADD) &&
(!$this->bo->grants[$oldContact['owner']] & EGW_ACL_DELETE))
@ -431,23 +431,11 @@ class addressbook_groupdav extends groupdav_handler
*/
public function getctag($path,$user)
{
$filter = array();
// show addressbook of a single user?
if ($user && $path != '/addressbook/') $filter['contact_owner'] = $user;
// should we hide the accounts addressbook
if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $filter['account_id'] = null;
// not showing addressbook of a single user?
if (!$user || $path == '/addressbook/') $user = null;
$ctag = $this->bo->get_ctag($user);
$result = $this->bo->search(array(),'MAX(contact_modified) AS contact_modified','','','',false,'AND',false,$filter);
if (empty($result))
{
$ctag = 0;
}
else
{
$ctag = $result[0]['contact_modified'];
}
return 'EGw-'.$ctag.'-wGE';
}

View File

@ -571,7 +571,9 @@ class addressbook_so
// Hide deleted items unless type is specifically deleted
if(!is_array($filter)) $filter = $filter ? (array) $filter : array();
if($filter['tid'] !== self::DELETED_TYPE)
// if no tid set or tid==='' do NOT return deleted entries ($tid === null returns all entries incl. deleted)
if(!array_key_exists('tid', $filter) || $filter['tid'] === '')
{
if ($join && strpos($join,'RIGHT JOIN') !== false) // used eg. to search for groups
{
@ -582,6 +584,10 @@ class addressbook_so
$filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\'';
}
}
elseif(is_null($filter['tid']))
{
unset($filter['tid']); // return all entries incl. deleted
}
$backend =& $this->get_backend(null,$filter['owner']);
// single string to search for --> create so_sql conformant search criterial for the standard search columns
@ -600,16 +606,16 @@ class addressbook_so
{
$cols = $this->account_cols_to_search;
}
if($backend instanceof addressbook_sql)
if($backend instanceof addressbook_sql)
{
// Keep a string, let the parent handle it
$criteria = $search;
foreach($cols as $key => &$col)
foreach($cols as $key => &$col)
{
if(!array_key_exists($col, $backend->db_cols))
if(!array_key_exists($col, $backend->db_cols))
{
if(!($col = array_search($col, $backend->db_cols)))
if(!($col = array_search($col, $backend->db_cols)))
{
// Can't search this column, it will error if we try
unset($cols[$key]);
@ -619,7 +625,7 @@ class addressbook_so
}
$backend->columns_to_search = $cols;
}
}
else
{
foreach($cols as $col)
@ -754,7 +760,7 @@ class addressbook_so
if (!$new_owner)
{
$this->somain->delete(array('owner' => $account_id));
if(!($this->somain instanceof addressbook_sql))
if(!($this->somain instanceof addressbook_sql))
{
$this->soextra->delete_customfields(array($this->extra_owner => $account_id));
}