diff --git a/api/src/Contacts.php b/api/src/Contacts.php index e5afb9fbbc..9b87c5229d 100755 --- a/api/src/Contacts.php +++ b/api/src/Contacts.php @@ -1928,11 +1928,42 @@ class Contacts extends Contacts\Storage unset($newlinkID); } } + // Update calendar + $this->merge_calendar($contact['id'], $target['id']); + if ($this->delete($contact['id'])) $success++; } return $success; } + /** + * Change the contact ID in any calendar events from the old contact ID + * to the new merged ID + * + * @param int $old_id + * @param int $new_id + */ + protected function merge_calendar($old_id, $new_id) + { + static $bo; + if(!is_object($bo)) + { + $bo = new \calendar_boupdate(); + } + + // Find all events with this contact + $events = $bo->search(array('users' => "c$old_id", 'ignore_acl' => true)); + + foreach($events as $event) + { + $event['participants']["c$new_id"] = $event['participants']["c$old_id"]; + unset($event['participants']["c$old_id"]); + + // Quietly update, ignoring ACL & no notifications + $bo->update($event, true, true, true, true, $messages, true); + } + } + /** * Some caching for lists within request *