/** * Delete a contact and all its associated records * * @param int $id id of the contact to delete * @param bool $restore whether to actually restore, not delete * @param bool $skipUndelete whether to force contact delete or not * * @return boolean true if contact deleted, false otherwise * @access public * @static */ function deleteContact($id, $restore = false, $skipUndelete = false) { require_once 'CRM/Activity/BAO/Activity.php'; if (!$id) { return false; } // make sure we have edit permission for this contact // before we delete require_once 'CRM/Contact/BAO/Contact/Permission.php'; if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) { return false; } // make sure this contact_id does not have any membership types $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id'); if ($membershipTypeID) { return false; } $contact = new CRM_Contact_DAO_Contact(); $contact->id = $id; if (!$contact->find(true)) { return false; } if ($restore) { self::contactTrashRestore($contact->id, true); return true; } $contactType = $contact->contact_type; // currently we only clear employer cache. // we are not deleting inherited membership if any. if ($contact->contact_type == 'Organization') { require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id); } require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::pre('delete', $contactType, $id, CRM_Core_DAO::$_nullArray); // start a new transaction require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $config =& CRM_Core_Config::singleton(); if ($skipUndelete or !$config->contactUndelete) { //delete billing address if exists. require_once 'CRM/Contribute/BAO/Contribution.php'; CRM_Contribute_BAO_Contribution::deleteAddress(null, $id); // delete the log entries since we dont have triggers enabled as yet require_once 'CRM/Core/DAO/Log.php'; $logDAO =& new CRM_Core_DAO_Log(); $logDAO->entity_table = 'civicrm_contact'; $logDAO->entity_id = $id; $logDAO->delete(); // do activity cleanup, CRM-5604 require_once 'CRM/Activity/BAO/Activity.php'; CRM_Activity_BAO_activity::cleanupActivity($id); $contact->delete(); } else { self::contactTrashRestore($contact->id); } //delete the contact id from recently view require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::delContact($id); // reset the group contact cache for this group require_once 'CRM/Contact/BAO/GroupContactCache.php'; CRM_Contact_BAO_GroupContactCache::remove(); $transaction->commit(); CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact); // also reset the DB_DO global array so we can reuse the memory // http://issues.civicrm.org/jira/browse/CRM-4387 CRM_Core_DAO::freeResult(); return true; }
protected function tearDown() { $this->contact->delete(); }