From 8e12bf072fe613c29da39614c8999a4041d7e1d2 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 17 Mar 2020 20:42:56 +1300 Subject: [PATCH] Deprecate calling deleteContact in order to undelete This pattern really is very silly. We have one function doing both delete & an update that is no different to the update done by a normal create call --- CRM/Contact/BAO/Contact.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 2f7727a35e..42ae711feb 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -965,7 +965,13 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $contactType = $contact->contact_type; if ($restore) { - return self::contactTrashRestore($contact, TRUE); + // @todo deprecate calling contactDelete with the intention to restore. + $updateParams = [ + 'id' => $contact->id, + 'is_deleted' => FALSE, + ]; + self::create($updateParams); + return TRUE; } // start a new transaction @@ -1203,11 +1209,22 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * i.e. is_delete = 0 * * @return bool + * @throws \CRM_Core_Exception */ public static function contactTrashRestore($contact, $restore = FALSE) { + if ($restore) { + CRM_Core_Error::deprecatedFunctionWarning('Use contact.create to restore - this does nothing much'); + // @todo deprecate calling contactDelete with the intention to restore. + $updateParams = [ + 'id' => $contact->id, + 'is_deleted' => FALSE, + ]; + self::create($updateParams); + return TRUE; + } $updateParams = [ 'id' => $contact->id, - 'is_deleted' => $restore ? 0 : 1, + 'is_deleted' => 1, ]; CRM_Utils_Hook::pre('update', $contact->contact_type, $contact->id, $updateParams); -- 2.25.1