From 2bf9621122847d53a0d091e2f8c2f48a21ae8549 Mon Sep 17 00:00:00 2001 From: yashodha Date: Wed, 24 Apr 2013 05:18:54 +0530 Subject: [PATCH] CRM-12410 --- CRM/Activity/BAO/Activity.php | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index cd776cefb6..8f28f0b969 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2164,40 +2164,28 @@ AND cl.modified_id = c.id if (!$contactId) { return $result; } + $activityContacts = CRM_Core_PseudoConstant::activityContacts('name'); + $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $transaction = new CRM_Core_Transaction(); // delete activity if there is no record in // civicrm_activity_contact // pointing to any other contact record. - // FIXME: this will be an awful query, figure out what function does - // and clean up - $activity = new CRM_Activity_DAO_Activity(); - $activity->source_contact_id = $contactId; - $activity->find(); - - while ($activity->fetch()) { - $noOther = TRUE; - - $sql = " -SELECT count(*) -FROM civicrm_activity_contact -WHERE activity_id = %1 -AND contact_id <> %2 -"; - $params = array( - 1 => array($activity->id, 'Integer'), - 2 => array($contactId, 'Integer') - ); + $activityContact = new CRM_Activity_DAO_ActivityContact(); + $activityContact->contact_id = $contactId; + $activityContact->record_type_id = $sourceID; + $activityContact->find(); + while ($activityContact->fetch()) { // finally delete activity. if (CRM_Core_DAO::singleValueQuery($sql)) { - $activityParams = array('id' => $activity->id); + $activityParams = array('id' => $activityContact->activity_id); $result = self::deleteActivity($activityParams); } } - $activity->free(); + $activityContact->free(); $transaction->commit(); return $result; -- 2.25.1