From: yashodha Date: Tue, 23 Apr 2013 23:48:54 +0000 (+0530) Subject: CRM-12410 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2bf9621122847d53a0d091e2f8c2f48a21ae8549;p=civicrm-core.git CRM-12410 --- 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;