From 1fa25b0e6a71e2505b60ac5d5aa6bef28851d6b8 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 15 Dec 2015 22:43:33 +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 96d5ed3089..961153c74a 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -1054,7 +1054,7 @@ class addressbook_ui extends addressbook_bo $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; } @@ -1069,20 +1069,19 @@ class addressbook_ui extends addressbook_bo 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); + } } } } @@ -1100,6 +1099,38 @@ class addressbook_ui extends addressbook_bo 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 * @@ -1791,25 +1822,7 @@ class addressbook_ui extends addressbook_bo 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'); } else