From 1bf11ef2d0716bdfa839d0f06bb9c90c9ce2eed2 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 4 Mar 2020 07:07:37 -0700 Subject: [PATCH] Contacts - Import: Change Google import to use class delete() method to remove duplicates. --- app/contacts/contact_import_google.php | 53 +++++++++++++++++--------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/app/contacts/contact_import_google.php b/app/contacts/contact_import_google.php index 7bb29e2c97..ec9703a643 100644 --- a/app/contacts/contact_import_google.php +++ b/app/contacts/contact_import_google.php @@ -17,25 +17,28 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2013 + Portions created by the Initial Developer are Copyright (C) 2008-2020 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ -require_once "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; -require_once "resources/functions/google_get_groups.php"; -require_once "resources/functions/google_get_contacts.php"; -if (permission_exists('contact_add')) { - //access granted -} -else { - echo "access denied"; - exit; -} +//includes + require_once "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + require_once "resources/functions/google_get_groups.php"; + require_once "resources/functions/google_get_contacts.php"; + +//check permissions + if (permission_exists('contact_add')) { + //access granted + } + else { + echo "access denied"; + exit; + } //add multi-lingual support $language = new text; @@ -99,11 +102,25 @@ if ($_POST['a'] == 'import') { } //replace contact (delete before inserts below) else if ($duplicate_exists && $_POST['import_duplicates'] == 'replace') { - $contact_uuid = $duplicate_contact_uuid; - $included = true; - require_once "contact_delete.php"; - unset($contact_uuid, $duplicate_contact_uuid); - $contacts_replaced++; + //build array + $array[0]['checked'] = 'true'; + $array[0]['uuid'] = $duplicate_contact_uuid; + unset($duplicate_contact_uuid); + + //grant temporary permissions + $p = new permissions; + $p->add('contact_delete', 'temp'); + + //delete duplicate contact + $obj = new contacts; + $obj->delete($array); + unset($array) + + //revoke temporary permissions + $p->delete('contact_delete', 'temp'); + + //increase counter + $contacts_replaced++; } //extract contact record from array using contact id