From 844bdf39996efe90e56809852d253662a57aa83b Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 17 Mar 2020 23:20:50 +1300 Subject: [PATCH] Complete deprecation of trashRestore --- CRM/Contact/BAO/Contact.php | 57 +++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 42ae711feb..7101d33cc8 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -685,6 +685,36 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); return 'address'; } + /** + * Soft delete a contact. + * + * Call this via the api, not directly. + * + * @param \CRM_Contact_BAO_Contact $contact + * + * @return bool + * @throws \CRM_Core_Exception + */ + protected static function contactTrash($contact): bool { + $updateParams = [ + 'id' => $contact->id, + 'is_deleted' => 1, + ]; + CRM_Utils_Hook::pre('update', $contact->contact_type, $contact->id, $updateParams); + + $params = [1 => [$contact->id, 'Integer']]; + $query = 'DELETE FROM civicrm_uf_match WHERE contact_id = %1'; + CRM_Core_DAO::executeQuery($query, $params); + + $contact->copyValues($updateParams); + $contact->save(); + CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id); + + CRM_Utils_Hook::post('update', $contact->contact_type, $contact->id, $contact); + + return TRUE; + } + /** * Create last viewed link to recently updated contact. * @@ -1016,7 +1046,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $contact->delete(); } else { - self::contactTrashRestore($contact); + self::contactTrash($contact); } // currently we only clear employer cache. // we are now deleting inherited membership if any. @@ -1208,10 +1238,14 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * True to set the is_delete = 1 else false to restore deleted contact, * i.e. is_delete = 0 * + * @deprecated + * * @return bool * @throws \CRM_Core_Exception */ public static function contactTrashRestore($contact, $restore = FALSE) { + CRM_Core_Error::deprecatedFunctionWarning('Use the api'); + if ($restore) { CRM_Core_Error::deprecatedFunctionWarning('Use contact.create to restore - this does nothing much'); // @todo deprecate calling contactDelete with the intention to restore. @@ -1222,26 +1256,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); self::create($updateParams); return TRUE; } - $updateParams = [ - 'id' => $contact->id, - 'is_deleted' => 1, - ]; - - CRM_Utils_Hook::pre('update', $contact->contact_type, $contact->id, $updateParams); - - $params = [1 => [$contact->id, 'Integer']]; - if (!$restore) { - $query = "DELETE FROM civicrm_uf_match WHERE contact_id = %1"; - CRM_Core_DAO::executeQuery($query, $params); - } - - $contact->copyValues($updateParams); - $contact->save(); - CRM_Core_BAO_Log::register($contact->id, 'civicrm_contact', $contact->id); - - CRM_Utils_Hook::post('update', $contact->contact_type, $contact->id, $contact); - - return TRUE; + return self::contactTrash($contact); } /** -- 2.25.1