/** * Delete the record that are associated with this participation * * @param int $id id of the participation to delete * * @return void * @access public * @static */ static function deleteParticipant($id) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); //delete activity record require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $id, 'activity_type_id' => 5); // activity type id for event registration CRM_Activity_BAO_Activity::deleteActivity($params); // delete the participant payment record // we need to do this since the cascaded constraints // dont work with join tables require_once 'CRM/Event/BAO/ParticipantPayment.php'; $p = array('participant_id' => $id); CRM_Event_BAO_ParticipantPayment::deleteParticipantPayment($p); // cleanup line items. require_once 'CRM/Price/BAO/LineItem.php'; $participantsId = array(); $participantsId = self::getAdditionalParticipantIds($id); $participantsId[] = $id; CRM_Price_BAO_LineItem::deleteLineItems($participantsId, 'civicrm_participant'); $participant = new CRM_Event_DAO_Participant(); $participant->id = $id; $participant->delete(); $transaction->commit(); // delete the recently created Participant require_once 'CRM/Utils/Recent.php'; $participantRecent = array('id' => $id, 'type' => 'Participant'); CRM_Utils_Recent::del($participantRecent); return $participant; }
/** * Delete the notes. * * @param int $id * Note id. * @param bool $showStatus * Do we need to set status or not. * * @return int|NULL * no of deleted notes on success, null otherwise */ public static function del($id, $showStatus = TRUE) { $return = NULL; $recent = array($id); $note = new CRM_Core_DAO_Note(); $note->id = $id; $note->find(); $note->fetch(); if ($note->entity_table == 'civicrm_note') { $status = ts('Selected Comment has been deleted successfully.'); } else { $status = ts('Selected Note has been deleted successfully.'); } // Delete all descendents of this Note foreach (self::getDescendentIds($id) as $childId) { $childNote = new CRM_Core_DAO_Note(); $childNote->id = $childId; $childNote->delete(); $childNote->free(); $recent[] = $childId; } $return = $note->delete(); $note->free(); if ($showStatus) { CRM_Core_Session::setStatus($status, ts('Deleted'), 'success'); } // delete the recently created Note foreach ($recent as $recentId) { $noteRecent = array('id' => $recentId, 'type' => 'Note'); CRM_Utils_Recent::del($noteRecent); } return $return; }
/** * Delete the record that are associated with this case * record are deleted from case * * @param int $caseId id of the case to delete * * @param bool $moveToTrash * * @return bool is successful * @access public * @static */ static function deleteCase($caseId, $moveToTrash = FALSE) { CRM_Utils_Hook::pre('delete', 'Case', $caseId, CRM_Core_DAO::$_nullArray); //delete activities $activities = self::getCaseActivityDates($caseId); if ($activities) { foreach ($activities as $value) { CRM_Activity_BAO_Activity::deleteActivity($value, $moveToTrash); } } if (!$moveToTrash) { $transaction = new CRM_Core_Transaction(); } $case = new CRM_Case_DAO_Case(); $case->id = $caseId; if (!$moveToTrash) { $result = $case->delete(); $transaction->commit(); } else { $result = $case->is_deleted = 1; $case->save(); } if ($result) { // CRM-7364, disable relationships self::enableDisableCaseRelationships($caseId, FALSE); CRM_Utils_Hook::post('delete', 'Case', $caseId, $case); // remove case from recent items. $caseRecent = array('id' => $caseId, 'type' => 'Case'); CRM_Utils_Recent::del($caseRecent); return TRUE; } return FALSE; }
/** * Function to delete the activity * @param array $params associated array * * @return void * @access public * */ public function deleteActivity(&$params, $moveToTrash = false) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $activity =& new CRM_Activity_DAO_Activity(); $activity->copyValues($params); if (!$moveToTrash) { $result = $activity->delete(); } else { $activity->is_deleted = 1; $result = $activity->save(); //log activty delete.CRM-4525. $logMsg = "Case Activity deleted for"; $msgs = array(); $sourceContactId = CRM_Core_DAO::getfieldValue('CRM_Activity_DAO_Activity', $activity->id, 'source_contact_id'); if ($sourceContactId) { $msgs[] = " source={$sourceContactId}"; } //get target contacts. $targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id); if (!empty($targetContactIds)) { $msgs[] = " target =" . implode(',', array_keys($targetContactIds)); } //get assignee contacts. $assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id); if (!empty($assigneeContactIds)) { $msgs[] = " assigne =" . implode(',', array_keys($assigneeContactIds)); } $logMsg .= implode(', ', $msgs); self::logActivityAction($activity, $logMsg); } // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; if ($result) { CRM_Utils_Recent::del($activity->id); } $transaction->commit(); return $result; }
/** * Function to delete the pledge * * @param int $id pledge id * * @access public * @static * */ static function deletePledge($id) { CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); //check for no Completed Payment records with the pledge $payment = new CRM_Pledge_DAO_PledgePayment(); $payment->pledge_id = $id; $payment->find(); while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } $dao = new CRM_Pledge_DAO_Pledge(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Pledge', $dao->id, $dao); // delete the recently created Pledge $pledgeRecent = array('id' => $id, 'type' => 'Pledge'); CRM_Utils_Recent::del($pledgeRecent); return $results; }
/** * Delete the indirect records associated with this contribution first * * @return $results no of deleted Contribution on success, false otherwise * @access public * @static */ static function deleteContribution($id) { require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $id, 'activity_type_id' => 6); // activity type id for contribution CRM_Activity_BAO_Activity::deleteActivity($params); //delete billing address if exists for this contribution. self::deleteAddress($id); //update pledge and pledge payment, CRM-3961 require_once 'CRM/Pledge/BAO/Payment.php'; CRM_Pledge_BAO_Payment::resetPledgePayment($id); // remove entry from civicrm_price_set_entity, CRM-5095 require_once 'CRM/Price/BAO/Set.php'; if (CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution', $id); } // cleanup line items. require_once 'CRM/Price/BAO/Field.php'; require_once 'CRM/Event/BAO/ParticipantPayment.php'; $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id'); // delete any related entity_financial_trxn and financial_trxn records. require_once 'CRM/Core/BAO/FinancialTrxn.php'; CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id, 'civicrm_contribution'); if ($participantId) { require_once 'CRM/Price/BAO/LineItem.php'; CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant'); } else { require_once 'CRM/Price/BAO/LineItem.php'; CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution'); } $dao = new CRM_Contribute_DAO_Contribution(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao); // delete the recently created Contribution require_once 'CRM/Utils/Recent.php'; $contributionRecent = array('id' => $id, 'type' => 'Contribution'); CRM_Utils_Recent::del($contributionRecent); return $results; }
/** * Function to delete the activity * @param array $params associated array * * @return void * @access public * */ public function deleteActivity(&$params, $moveToTrash = false) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); if (!$moveToTrash) { if (!isset($params['id'])) { if (is_array($params['activity_type_id'])) { $activityTypes = implode(',', $params['activity_type_id']); } else { $activityTypes = $params['activity_type_id']; } $query = "DELETE FROM civicrm_activity WHERE source_record_id = {$params['source_record_id']} AND activity_type_id IN ( {$activityTypes} )"; $dao = CRM_Core_DAO::executeQuery($query); } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $result = $activity->delete(); } } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->is_deleted = 1; $result = $activity->save(); //log activty delete.CRM-4525. $logMsg = "Case Activity deleted for"; $msgs = array(); $sourceContactId = CRM_Core_DAO::getfieldValue('CRM_Activity_DAO_Activity', $activity->id, 'source_contact_id'); if ($sourceContactId) { $msgs[] = " source={$sourceContactId}"; } //get target contacts. $targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id); if (!empty($targetContactIds)) { $msgs[] = " target =" . implode(',', array_keys($targetContactIds)); } //get assignee contacts. $assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id); if (!empty($assigneeContactIds)) { $msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds)); } $logMsg .= implode(', ', $msgs); self::logActivityAction($activity, $logMsg); } // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; if ($result) { $activityRecent = array('id' => $activity->id, 'type' => 'Activity'); CRM_Utils_Recent::del($activityRecent); } $transaction->commit(); return $result; }
/** * Delete the relationship. * * @param int $id * Relationship id. * * @return null */ public static function del($id) { // delete from relationship table CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray); $relationship = self::clearCurrentEmployer($id, CRM_Core_Action::DELETE); if (CRM_Core_Permission::access('CiviMember')) { // create $params array which isrequired to delete memberships // of the related contacts. $params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1)); $ids = array(); // calling relatedMemberships to delete the memberships of // related contacts. self::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE, FALSE); } $relationship->delete(); CRM_Core_Session::setStatus(ts('Selected relationship has been deleted successfully.'), ts('Record Deleted'), 'success'); CRM_Utils_Hook::post('delete', 'Relationship', $id, $relationship); // delete the recently created Relationship $relationshipRecent = array('id' => $id, 'type' => 'Relationship'); CRM_Utils_Recent::del($relationshipRecent); return $relationship; }
/** * Function to delete the relationship * * @param int $id relationship id * * @return null * @access public * * @static */ static function del($id) { // delete from relationship table require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray); $relationship =& new CRM_Contact_DAO_Relationship(); $relationship->id = $id; $relationship->find(true); //to delete relationship between household and individual //or between individual and orgnization if ($relationship->relationship_type_id == 4 || $relationship->relationship_type_id == 7) { $sharedContact = new CRM_Contact_DAO_Contact(); $sharedContact->id = $relationship->contact_id_a; $sharedContact->find(true); if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) { require_once 'CRM/Contact/BAO/Contact/Utils.php'; CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a); } else { if ($sharedContact->mail_to_household_id == $relationship->contact_id_b) { self::deleteSharedAddress($relationship->contact_id_a); } } } if (CRM_Core_Permission::access('CiviMember')) { // create $params array which isrequired to delete memberships // of the related contacts. $params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1)); $ids = array(); // calling relatedMemberships to delete the memberships of // related contacts. self::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE); } $relationship->delete(); CRM_Core_Session::setStatus(ts('Selected Relationship has been Deleted Successfuly.')); CRM_Utils_Hook::post('delete', 'Relationship', $relationship->id, $relationship); // delete the recently created Relationship require_once 'CRM/Utils/Recent.php'; $relationshipRecent = array('id' => $id, 'type' => 'Relationship'); CRM_Utils_Recent::del($relationshipRecent); return $relationship; }
/** * Function to delete the notes * * @param int $id note id * * @return $return no of deleted notes on success, false otherwise * @access public * @static * */ static function del($id) { $return = null; $note =& new CRM_Core_DAO_Note(); $note->id = $id; $return = $note->delete(); CRM_Core_Session::setStatus(ts('Selected Note has been Deleted Successfully.')); // delete the recently created Note require_once 'CRM/Utils/Recent.php'; $noteRecent = array('id' => $id, 'type' => 'Note'); CRM_Utils_Recent::del($noteRecent); return $return; }
/** * Function to delete the grant * * @param int $id grant id * * @access public * @static * */ static function del($id) { require_once 'CRM/Grant/DAO/Grant.php'; $grant = new CRM_Grant_DAO_Grant(); $grant->id = $id; $grant->find(); // delete the recently created Grant require_once 'CRM/Utils/Recent.php'; $grantRecent = array('id' => $id, 'type' => 'Grant'); CRM_Utils_Recent::del($grantRecent); while ($grant->fetch()) { return $grant->delete(); } return false; }
/** * Function to delete the pledge * * @param int $id pledge id * * @access public * @static * */ static function deletePledge($id) { CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray); //check for no Completed Payment records with the pledge require_once 'CRM/Pledge/DAO/Payment.php'; $payment = new CRM_Pledge_DAO_Payment(); $payment->pledge_id = $id; $payment->find(); while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { require_once 'CRM/Contribute/BAO/Contribution.php'; CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; $dao = new CRM_Pledge_DAO_Pledge(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Pledge', $dao->id, $dao); // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::del($id); return $results; }
/** * Function to delete membership. * * @param int $membershipId membership id that needs to be deleted * * @static * * @return $results no of deleted Membership on success, false otherwise * @access public */ static function deleteMembership($membershipId) { CRM_Utils_Hook::pre('delete', 'Membership', $membershipId, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); $params = array(); $deleteActivity = false; $membershipActivities = array('Membership Signup', 'Membership Renewal', 'Change Membership Status', 'Change Membership Type', 'Membership Renewal Reminder'); foreach ($membershipActivities as $membershipActivity) { $activityId = array_search($membershipActivity, $activityTypes); if ($activityId) { $params['activity_type_id'][] = $activityId; $deleteActivity = true; } } if ($deleteActivity) { $params['source_record_id'] = $membershipId; CRM_Activity_BAO_Activity::deleteActivity($params); } self::deleteMembershipPayment($membershipId); $membership = new CRM_Member_DAO_Membership(); $membership->id = $membershipId; $results = $membership->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Membership', $membership->id, $membership); // delete the recently created Membership $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * Delete the group and all the object that connect to this group. * * Incredibly destructive. * * @param int $id Group id. */ public static function discard($id) { CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); // added for CRM-1631 and CRM-1794 // delete all subscribed mails with the selected group id $subscribe = new CRM_Mailing_Event_DAO_Subscribe(); $subscribe->group_id = $id; $subscribe->delete(); // delete all Subscription records with the selected group id $subHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subHistory->group_id = $id; $subHistory->delete(); // delete all crm_group_contact records with the selected group id $groupContact = new CRM_Contact_DAO_GroupContact(); $groupContact->group_id = $id; $groupContact->delete(); // make all the 'add_to_group_id' field of 'civicrm_uf_group table', pointing to this group, as null $params = array(1 => array($id, 'Integer')); $query = "UPDATE civicrm_uf_group SET `add_to_group_id`= NULL WHERE `add_to_group_id` = %1"; CRM_Core_DAO::executeQuery($query, $params); $query = "UPDATE civicrm_uf_group SET `limit_listings_group_id`= NULL WHERE `limit_listings_group_id` = %1"; CRM_Core_DAO::executeQuery($query, $params); // make sure u delete all the entries from civicrm_mailing_group and civicrm_campaign_group // CRM-6186 $query = "DELETE FROM civicrm_mailing_group where entity_table = 'civicrm_group' AND entity_id = %1"; CRM_Core_DAO::executeQuery($query, $params); $query = "DELETE FROM civicrm_campaign_group where entity_table = 'civicrm_group' AND entity_id = %1"; CRM_Core_DAO::executeQuery($query, $params); $query = "DELETE FROM civicrm_acl_entity_role where entity_table = 'civicrm_group' AND entity_id = %1"; CRM_Core_DAO::executeQuery($query, $params); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) { // clear any descendant groups cache if exists CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); } // delete from group table $group = new CRM_Contact_DAO_Group(); $group->id = $id; $group->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Group', $id, $group); // delete the recently created Group $groupRecent = array('id' => $id, 'type' => 'Group'); CRM_Utils_Recent::del($groupRecent); }
/** * Function to delete the grant * * @param int $id grant id * * @access public * @static * */ static function del($id) { require_once 'CRM/Grant/DAO/Grant.php'; $grant =& new CRM_Grant_DAO_Grant(); $grant->id = $id; $grant->find(); // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::del($id); while ($grant->fetch()) { return $grant->delete(); } return false; }
/** * Function to delete membership. * * @param int $membershipId membership id that needs to be deleted * * @static * @return $results no of deleted Membership on success, false otherwise * @access public */ static function deleteMembership($membershipId) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record $activityTypes = CRM_Core_Pseudoconstant::activityType(true, false, false, 'name'); require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $membershipId, 'activity_type_id' => array(array_search('Membership Signup', $activityTypes), array_search('Membership Renewal', $activityTypes))); CRM_Activity_BAO_Activity::deleteActivity($params); self::deleteMembershipPayment($membershipId); require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $membershipId; $results = $membership->delete(); $transaction->commit(); // delete the recently created Membership require_once 'CRM/Utils/Recent.php'; $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * Function to delete the group and all the object that connect to * this group. Incredibly destructive * * @param int $id group id * * @return null * @access public * @static * */ static function discard($id) { require_once 'CRM/Utils/Hook.php'; require_once 'CRM/Contact/DAO/SubscriptionHistory.php'; CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); // added for CRM-1631 and CRM-1794 // delete all subscribed mails with the selected group id require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; $subscribe = new CRM_Mailing_Event_BAO_Subscribe(); $subscribe->deleteGroup($id); // delete all Subscription records with the selected group id $subHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subHistory->group_id = $id; $subHistory->delete(); // delete all crm_group_contact records with the selected group id require_once 'CRM/Contact/DAO/GroupContact.php'; $groupContact = new CRM_Contact_DAO_GroupContact(); $groupContact->group_id = $id; $groupContact->delete(); // make all the 'add_to_group_id' field of 'civicrm_uf_group table', pointing to this group, as null $params = array(1 => array($id, 'Integer')); $query = "update civicrm_uf_group SET `add_to_group_id`= NULL where `add_to_group_id` = %1"; CRM_Core_DAO::executeQuery($query, $params); $query = "update civicrm_uf_group SET `limit_listings_group_id`= NULL where `limit_listings_group_id` = %1"; CRM_Core_DAO::executeQuery($query, $params); if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) { // clear any descendant groups cache if exists require_once 'CRM/Core/BAO/Cache.php'; $finalGroups =& CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); } // delete from group table $group = new CRM_Contact_DAO_Group(); $group->id = $id; $group->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Group', $id, $group); // delete the recently created Group require_once 'CRM/Utils/Recent.php'; $groupRecent = array('id' => $id, 'type' => 'Group'); CRM_Utils_Recent::del($groupRecent); }
/** * Delete the indirect records associated with this contribution first. * * @param int $id * * @return mixed|null * $results no of deleted Contribution on success, false otherwise */ public static function deleteContribution($id) { CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $params = array('source_record_id' => $id, 'activity_type_id' => 6); CRM_Activity_BAO_Activity::deleteActivity($params); //delete billing address if exists for this contribution. self::deleteAddress($id); //update pledge and pledge payment, CRM-3961 CRM_Pledge_BAO_PledgePayment::resetPledgePayment($id); // remove entry from civicrm_price_set_entity, CRM-5095 if (CRM_Price_BAO_PriceSet::getFor('civicrm_contribution', $id)) { CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution', $id); } // cleanup line items. $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id'); // delete any related entity_financial_trxn, financial_trxn and financial_item records. CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id); if ($participantId) { CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant'); } else { CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution'); } //delete note. $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_contribution'); $noteId = key($note); if ($noteId) { CRM_Core_BAO_Note::del($noteId, FALSE); } $dao = new CRM_Contribute_DAO_Contribution(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao); // delete the recently created Contribution $contributionRecent = array('id' => $id, 'type' => 'Contribution'); CRM_Utils_Recent::del($contributionRecent); return $results; }
/** * Delete the grant. * * @param int $id * Grant id. * * @return bool|mixed */ public static function del($id) { CRM_Utils_Hook::pre('delete', 'Grant', $id, CRM_Core_DAO::$_nullArray); $grant = new CRM_Grant_DAO_Grant(); $grant->id = $id; $grant->find(); // delete the recently created Grant $grantRecent = array('id' => $id, 'type' => 'Grant'); CRM_Utils_Recent::del($grantRecent); if ($grant->fetch()) { $results = $grant->delete(); CRM_Utils_Hook::post('delete', 'Grant', $grant->id, $grant); return $results; } return FALSE; }
/** * Delete the activity. * * @param array $params * @param bool $moveToTrash * * @return mixed */ public static function deleteActivity(&$params, $moveToTrash = FALSE) { // CRM-9137 if (!empty($params['id']) && !is_array($params['id'])) { CRM_Utils_Hook::pre('delete', 'Activity', $params['id'], $params); } else { CRM_Utils_Hook::pre('delete', 'Activity', NULL, $params); } $transaction = new CRM_Core_Transaction(); if (is_array(CRM_Utils_Array::value('source_record_id', $params))) { $sourceRecordIds = implode(',', $params['source_record_id']); } else { $sourceRecordIds = CRM_Utils_Array::value('source_record_id', $params); } $result = NULL; if (!$moveToTrash) { if (!isset($params['id'])) { if (is_array($params['activity_type_id'])) { $activityTypes = implode(',', $params['activity_type_id']); } else { $activityTypes = $params['activity_type_id']; } $query = "DELETE FROM civicrm_activity WHERE source_record_id IN ({$sourceRecordIds}) AND activity_type_id IN ( {$activityTypes} )"; $dao = CRM_Core_DAO::executeQuery($query); } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $result = $activity->delete(); // CRM-8708 $activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id); // CRM-13994 delete activity entity_tag $query = "DELETE FROM civicrm_entity_tag WHERE entity_table = 'civicrm_activity' AND entity_id = {$activity->id}"; $dao = CRM_Core_DAO::executeQuery($query); } } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->is_deleted = 1; $result = $activity->save(); // CRM-4525 log activity delete $logMsg = 'Case Activity deleted for'; $msgs = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $sourceContactId = self::getActivityContact($activity->id, $sourceID); if ($sourceContactId) { $msgs[] = " source={$sourceContactId}"; } // get target contacts. $targetContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $targetID); if (!empty($targetContactIds)) { $msgs[] = " target =" . implode(',', array_keys($targetContactIds)); } // get assignee contacts. $assigneeContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID); if (!empty($assigneeContactIds)) { $msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds)); } $logMsg .= implode(', ', $msgs); self::logActivityAction($activity, $logMsg); } // delete the recently created Activity if ($result) { $activityRecent = array('id' => $activity->id, 'type' => 'Activity'); CRM_Utils_Recent::del($activityRecent); } $transaction->commit(); if (isset($activity)) { // CRM-8708 $activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id); CRM_Utils_Hook::post('delete', 'Activity', $activity->id, $activity); } return $result; }
/** * Function to delete membership. * * @param int $membershipId membership id that needs to be deleted * * @static * @return $results no of deleted Membership on success, false otherwise * @access public */ static function deleteMembership($membershipId) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $membershipId, 'activity_type_id' => 7); // activity type id for membership CRM_Activity_BAO_Activity::deleteActivity($params); self::deleteMembershipPayment($membershipId); require_once 'CRM/Member/DAO/Membership.php'; $membership =& new CRM_Member_DAO_Membership(); $membership->id = $membershipId; $results = $membership->delete(); $transaction->commit(); // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::del($membershipId); return $results; }
/** * Delete the records that are associated with this participation. * * @param int $id * Id of the participation to delete. * * @return \CRM_Event_DAO_Participant */ public static function deleteParticipant($id) { CRM_Utils_Hook::pre('delete', 'Participant', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); //delete activity record $params = array('source_record_id' => $id, 'activity_type_id' => 5); CRM_Activity_BAO_Activity::deleteActivity($params); // delete the participant payment record // we need to do this since the cascaded constraints // dont work with join tables $p = array('participant_id' => $id); CRM_Event_BAO_ParticipantPayment::deleteParticipantPayment($p); // cleanup line items. $participantsId = array(); $participantsId = self::getAdditionalParticipantIds($id); $participantsId[] = $id; CRM_Price_BAO_LineItem::deleteLineItems($participantsId, 'civicrm_participant'); //delete note when participant deleted. $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_participant'); $noteId = key($note); if ($noteId) { CRM_Core_BAO_Note::del($noteId, FALSE); } $participant = new CRM_Event_DAO_Participant(); $participant->id = $id; $participant->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Participant', $participant->id, $participant); // delete the recently created Participant $participantRecent = array('id' => $id, 'type' => 'Participant'); CRM_Utils_Recent::del($participantRecent); return $participant; }
/** * Delete the record that are associated with this case * record are deleted from case * @param int $caseId id of the case to delete * * @return void * @access public * @static */ static function deleteCase($caseId, $moveToTrash = false) { //delete activities $activities = self::getCaseActivityDates($caseId); if ($activities) { require_once "CRM/Activity/BAO/Activity.php"; foreach ($activities as $value) { CRM_Activity_BAO_Activity::deleteActivity($value, $moveToTrash); } } if (!$moveToTrash) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); } require_once 'CRM/Case/DAO/Case.php'; $case =& new CRM_Case_DAO_Case(); $case->id = $caseId; if (!$moveToTrash) { $result = $case->delete(); $transaction->commit(); } else { $result = $case->is_deleted = 1; $case->save(); } if ($result) { // remove case from recent items. $caseRecent = array('id' => $caseId, 'type' => 'Case'); require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::del($caseRecent); return true; } return false; }
/** * Delete membership. * * @param int $membershipId * Membership id that needs to be deleted. * * @return int * Id of deleted Membership on success, false otherwise. */ public static function deleteMembership($membershipId) { // CRM-12147, retrieve membership data before we delete it for hooks $params = array('id' => $membershipId); $memValues = array(); $memberships = self::getValues($params, $memValues); $membership = $memberships[$membershipId]; CRM_Utils_Hook::pre('delete', 'Membership', $membershipId, $memValues); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); $params = array(); $deleteActivity = FALSE; $membershipActivities = array('Membership Signup', 'Membership Renewal', 'Change Membership Status', 'Change Membership Type', 'Membership Renewal Reminder'); foreach ($membershipActivities as $membershipActivity) { $activityId = array_search($membershipActivity, $activityTypes); if ($activityId) { $params['activity_type_id'][] = $activityId; $deleteActivity = TRUE; } } if ($deleteActivity) { $params['source_record_id'] = $membershipId; CRM_Activity_BAO_Activity::deleteActivity($params); } self::deleteMembershipPayment($membershipId); $results = $membership->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Membership', $membership->id, $membership); // delete the recently created Membership $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * Delete a contact and all its associated records * * @param int $id id of the contact to delete * * @return boolean true if contact deleted, false otherwise * @access public * @static */ function deleteContact($id) { require_once 'CRM/Core/BAO/EmailHistory.php'; require_once 'CRM/Core/BAO/Meeting.php'; require_once 'CRM/Core/BAO/Phonecall.php'; // make sure we have edit permission for this contact // before we delete if (!CRM_Contact_BAO_Contact::permissionedContact($id, CRM_CORE_PERMISSION_EDIT)) { return false; } require_once 'CRM/Utils/Hook.php'; $contact =& new CRM_Contact_DAO_Contact(); $contact->id = $id; if (!$contact->find(true)) { return false; } $contactType = $contact->contact_type; CRM_Utils_Hook::pre('delete', $contactType, $id); CRM_Core_DAO::transaction('BEGIN'); // do a top down deletion CRM_Mailing_Event_BAO_Subscribe::deleteContact($id); CRM_Contact_BAO_GroupContact::deleteContact($id); CRM_Contact_BAO_SubscriptionHistory::deleteContact($id); CRM_Contact_BAO_Relationship::deleteContact($id); CRM_Contribute_BAO_Contribution::deleteContact($id); CRM_Core_BAO_Note::deleteContact($id); CRM_Core_DAO::deleteEntityContact('CRM_Core_DAO_CustomValue', $id); CRM_Core_DAO::deleteEntityContact('CRM_Core_DAO_ActivityHistory', $id); require_once 'CRM/Core/BAO/UFMatch.php'; CRM_Core_BAO_UFMatch::deleteContact($id); // need to remove them from email, meeting and phonecall CRM_Core_BAO_EmailHistory::deleteContact($id); CRM_Core_BAO_Meeting::deleteContact($id); CRM_Core_BAO_Phonecall::deleteContact($id); // location shld be deleted after phonecall, since fields in phonecall are // fkeyed into location/phone. CRM_Core_BAO_Location::deleteContact($id); // fix household and org primary contact ids foreach ($GLOBALS['_CRM_CONTACT_BAO_CONTACT']['misc'] as $name) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $name) . ".php"; eval('$object =& new CRM_Contact_DAO_' . $name . '( );'); $object->primary_contact_id = $id; $object->find(); while ($object->fetch()) { // we need to set this to null explicitly $object->primary_contact_id = 'null'; $object->save(); } } require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_BAO_" . $contactType) . ".php"; eval('$object =& new CRM_Contact_BAO_' . $contactType . '( );'); $object->contact_id = $contact->id; $object->delete(); $contact->delete(); //delete the contact id from recently view CRM_Utils_Recent::del($id); CRM_Core_DAO::transaction('COMMIT'); CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact); return true; }