Addressbook cleanups from backport

This commit is contained in:
Jörg Lehrke 2010-02-26 15:47:51 +00:00
parent 0412ebbb33
commit e377d1914c
3 changed files with 48 additions and 45 deletions

View File

@ -682,13 +682,14 @@ class addressbook_bo extends addressbook_so
$ok = $this->save($delete); $ok = $this->save($delete);
egw_link::unlink(0,'addressbook',$id,'','!file'); egw_link::unlink(0,'addressbook',$id,'','!file');
} }
elseif($ok = parent::delete($id,$check_etag)) elseif (($ok = parent::delete($id,$check_etag)))
{ {
egw_link::unlink(0,'addressbook',$id); egw_link::unlink(0,'addressbook',$id);
} }
// Don't notify of final purge // Don't notify of final purge
if($ok && $old['tid'] != addressbook_so::DELETED_TYPE) { if ($ok && $old['tid'] != addressbook_so::DELETED_TYPE)
{
$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time()); $GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
$this->tracking->track(array('id' => $id), array('id' => $id), null, true); $this->tracking->track(array('id' => $id), array('id' => $id), null, true);
} }
@ -761,11 +762,11 @@ class addressbook_bo extends addressbook_so
$contact['modifier'] = $this->user; $contact['modifier'] = $this->user;
$contact['modified'] = $this->now_su; $contact['modified'] = $this->now_su;
// set full name and fileas from the content // set full name and fileas from the content
if (strlen($fullname = $this->fullname($contact)) > 0 && (!isset($contact['n_fn']) || $contact['n_fn'] != $fullname)) { if (!isset($contact['n_fn']))
$contact['n_fn'] = $fullname; {
$contact['n_fn'] = $this->fullname($contact);
if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact); if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact);
} }
unset($fullname);
$to_write = $contact; $to_write = $contact;
// (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc) // (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc)
if (!$ignore_acl && !$contact['owner'] && !$this->is_admin($contact)) if (!$ignore_acl && !$contact['owner'] && !$this->is_admin($contact))
@ -1715,9 +1716,9 @@ class addressbook_bo extends addressbook_so
. '()[ContactID]: ' . $contact['id']); . '()[ContactID]: ' . $contact['id']);
} }
// We only do a simple consistency check // We only do a simple consistency check
if ((empty($found['n_family']) || $found['n_family'] == $contact['n_family']) if (!$relax || ((empty($found['n_family']) || $found['n_family'] == $contact['n_family'])
&& (empty($found['n_given']) || $found['n_given'] == $contact['n_given']) && (empty($found['n_given']) || $found['n_given'] == $contact['n_given'])
&& (empty($found['org_name']) || $found['org_name'] == $contact['org_name'])) && (empty($found['org_name']) || $found['org_name'] == $contact['org_name'])))
{ {
return array($found['id']); return array($found['id']);
} }

View File

@ -99,21 +99,26 @@ class addressbook_sif extends addressbook_bo
const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>'; const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>';
const SIF_decl = '<SIFVersion>1.1</SIFVersion>'; const SIF_decl = '<SIFVersion>1.1</SIFVersion>';
function startElement($_parser, $_tag, $_attributes) { function startElement($_parser, $_tag, $_attributes)
{
} }
function endElement($_parser, $_tag) { function endElement($_parser, $_tag)
if(!empty($this->sifMapping[$_tag])) { {
if (!empty($this->sifMapping[$_tag]))
{
$this->contact[$this->sifMapping[$_tag]] = trim($this->sifData); $this->contact[$this->sifMapping[$_tag]] = trim($this->sifData);
} }
unset($this->sifData); unset($this->sifData);
} }
function characterData($_parser, $_data) { function characterData($_parser, $_data)
{
$this->sifData .= $_data; $this->sifData .= $_data;
} }
function siftoegw($sifData, $_abID=null) { function siftoegw($sifData, $_abID=null)
{
#$tmpfname = tempnam('/tmp/sync/contents','sifc_'); #$tmpfname = tempnam('/tmp/sync/contents','sifc_');
@ -129,14 +134,16 @@ class addressbook_sif extends addressbook_bo
xml_set_element_handler($this->xml_parser, "startElement", "endElement"); xml_set_element_handler($this->xml_parser, "startElement", "endElement");
xml_set_character_data_handler($this->xml_parser, "characterData"); xml_set_character_data_handler($this->xml_parser, "characterData");
$this->strXmlData = xml_parse($this->xml_parser, $sifData); $this->strXmlData = xml_parse($this->xml_parser, $sifData);
if(!$this->strXmlData) { if (!$this->strXmlData)
{
error_log(sprintf("XML error: %s at line %d", error_log(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->xml_parser)), xml_error_string(xml_get_error_code($this->xml_parser)),
xml_get_current_line_number($this->xml_parser))); xml_get_current_line_number($this->xml_parser)));
return false; return false;
} }
foreach($this->contact as $key => $value) { foreach ($this->contact as $key => $value)
{
$value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value); $value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value);
$value = $GLOBALS['egw']->translation->convert($value, 'utf-8'); $value = $GLOBALS['egw']->translation->convert($value, 'utf-8');
switch ($key) { switch ($key) {
@ -146,7 +153,7 @@ class addressbook_sif extends addressbook_bo
$categories1 = explode(',', $value); $categories1 = explode(',', $value);
$categories2 = explode(';', $value); $categories2 = explode(';', $value);
$categories = count($categories1) > count($categories2) ? $categories1 : $categories2; $categories = count($categories1) > count($categories2) ? $categories1 : $categories2;
$finalContact[$key] = implode(",", $this->find_or_add_categories($categories, $_abID)); $finalContact[$key] = implode(',', $this->find_or_add_categories($categories, $_abID));
} }
else else
{ {
@ -179,7 +186,7 @@ class addressbook_sif extends addressbook_bo
{ {
$result = array(); $result = array();
if($contact = $this->siftoegw($_sifdata, $contentID)) if (($contact = $this->siftoegw($_sifdata, $contentID)))
{ {
if ($contentID) if ($contentID)
{ {
@ -254,9 +261,7 @@ class addressbook_sif extends addressbook_bo
$fields = array_unique(array_values($this->sifMapping)); $fields = array_unique(array_values($this->sifMapping));
sort($fields); sort($fields);
if(!($entry = $this->read($_id))) { if (!($entry = $this->read($_id))) return false;
return false;
}
$sifContact = self::xml_decl . "\n<contact>" . self::SIF_decl; $sifContact = self::xml_decl . "\n<contact>" . self::SIF_decl;

View File

@ -123,10 +123,7 @@ class addressbook_vcal extends addressbook_bo
*/ */
function addVCard($_vcard, $_abID=null, $merge=false) function addVCard($_vcard, $_abID=null, $merge=false)
{ {
if(!$contact = $this->vcardtoegw($_vcard, $_abID)) if (!($contact = $this->vcardtoegw($_vcard, $_abID))) return false;
{
return false;
}
if ($_abID) if ($_abID)
{ {