From eb73fb2ec383119f895420290fcf7ca59ccc100b Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 15 Dec 2015 22:38:22 +0000 Subject: [PATCH] * Addressbook/CardDAV: fix contacts created with "Copy instead of move" checked in "Move to addressbook" context menu sync not correctly (already created ones need to be deleted!) Using now behavior like interactive "copy", but copying all fields, but ones never to copy like uid etc. This includes creating a link to the copied contact --- addressbook/inc/class.addressbook_ui.inc.php | 71 ++++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 7dbbbd47c8..149af79978 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -1225,7 +1225,7 @@ window.egw_LAB.wait(function() { $action_msg = lang('moved'); if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(EGW_ACL_DELETE,$contact))) { - if (!$contact['owner']) // no mass-change of accounts + if (!$contact['owner']) // no (mass-)move of accounts { $Ok = false; } @@ -1240,20 +1240,19 @@ window.egw_LAB.wait(function() { else { $action_msg = lang('copied'); - if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(EGW_ACL_DELETE,$contact))) + if (($Ok = !!($contact = $this->read($id)) && $this->check_perms(EGW_ACL_READ,$contact))) { - if (!$contact['owner']) // no mass-change of accounts + if ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action,-1) == 'p')) { - $Ok = false; - } - elseif ($contact['owner'] != (int)$action || $contact['private'] != (int)(substr($action,-1) == 'p')) - { - unset($contact['id']); - unset($contact['uid']); - unset($contact['etag']); + $this->copy_contact($contact, false); // do NOT use self::$copy_fields, copy everything but uid etc. + $links = $contact['link_to']['to_id']; $contact['owner'] = (int) $action; $contact['private'] = (int)(substr($action,-1) == 'p'); $Ok = $this->save($contact); + if ($Ok && is_array($links)) + { + egw_link::link('addressbook', $contact['id'], $links); + } } } } @@ -1271,6 +1270,38 @@ window.egw_LAB.wait(function() { return !$failed; } + /** + * Copy a given contact (not storing it!) + * + * Taken care only configured fields get copied and certain fields never to copy (uid etc.). + * + * @param array& $content + * @param boolean $only_copy_fields =true true: only copy fields configured for copying (eg. no name), + * false: copy everything, but never to copy fields + */ + function copy_contact(array &$content, $only_copy_fields=true) + { + $content['link_to']['to_id'] = 0; + egw_link::link('addressbook',$content['link_to']['to_id'],'addressbook',$content['id'], + lang('Copied by %1, from record #%2.',common::display_fullname('', + $GLOBALS['egw_info']['user']['account_firstname'],$GLOBALS['egw_info']['user']['account_lastname']), + $content['id'])); + // create a new contact with the content of the old + foreach(array_keys($content) as $key) + { + if($only_copy_fields && !in_array($key, self::$copy_fields) || in_array($key, array('id','etag','carddav_name','uid'))) + { + unset($content[$key]); + } + } + if(!isset($content['owner'])) + { + $content['owner'] = $this->default_private ? $this->user.'p' : $this->default_addressbook; + } + $content['creator'] = $this->user; + $content['created'] = $this->now_su; + } + /** * rows callback for index nextmatch * @@ -2106,25 +2137,7 @@ window.egw_LAB.wait(function() { if($content && $_GET['makecp']) // copy the contact { - $content['link_to']['to_id'] = 0; - egw_link::link('addressbook',$content['link_to']['to_id'],'addressbook',$content['id'], - lang('Copied by %1, from record #%2.',common::display_fullname('', - $GLOBALS['egw_info']['user']['account_firstname'],$GLOBALS['egw_info']['user']['account_lastname']), - $content['id'])); - // create a new contact with the content of the old - foreach($content as $key => $value) - { - if(!in_array($key, self::$copy_fields) || in_array($key, array('etag','carddav_name','uid'))) - { - unset($content[$key]); - } - } - if(!isset($content['owner'])) - { - $content['owner'] = $this->default_private ? $this->user.'p' : $this->default_addressbook; - } - $content['creator'] = $this->user; - $content['created'] = $this->now_su; + $this->copy_contact($content); $content['msg'] = lang('Contact copied'); $view = false; }