Skip to content

Commit

Permalink
Merge pull request #10168 from GinkgoFJG/CRM-20435
Browse files Browse the repository at this point in the history
CRM-20435: Replace SQL-based activityContact creation with DAO-based approach.
  • Loading branch information
eileenmcnaughton authored Apr 23, 2017
2 parents d969ad8 + a857867 commit 0710631
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,16 @@ public static function create(&$params) {
self::deleteActivityContact($activityId, $assigneeID);
}

$values = array();
foreach ($params['assignee_contact_id'] as $acID) {
if ($acID) {
$values[] = "( $activityId, $acID, $assigneeID )";
$assigneeParams = array(
'activity_id' => $activityId,
'contact_id' => $acID,
'record_type_id' => $assigneeID,
);
CRM_Activity_BAO_ActivityContact::create($assigneeParams);
}
}
while (!empty($values)) {
$input = array_splice($values, 0, CRM_Core_DAO::BULK_INSERT_COUNT);
$str = implode(',', $input);
$sql = "INSERT IGNORE INTO civicrm_activity_contact ( activity_id, contact_id, record_type_id ) VALUES $str;";
CRM_Core_DAO::executeQuery($sql);
}
}
else {
$assignmentParams['contact_id'] = $params['assignee_contact_id'];
Expand Down Expand Up @@ -429,19 +427,16 @@ public static function create(&$params) {
self::deleteActivityContact($activityId, $targetID);
}

$values = array();
foreach ($params['target_contact_id'] as $tid) {
if ($tid) {
$values[] = "( $activityId, $tid, $targetID )";
$targetContactParams = array(
'activity_id' => $activityId,
'contact_id' => $tid,
'record_type_id' => $targetID,
);
CRM_Activity_BAO_ActivityContact::create($targetContactParams);
}
}

while (!empty($values)) {
$input = array_splice($values, 0, CRM_Core_DAO::BULK_INSERT_COUNT);
$str = implode(',', $input);
$sql = "INSERT IGNORE INTO civicrm_activity_contact ( activity_id, contact_id, record_type_id ) VALUES $str;";
CRM_Core_DAO::executeQuery($sql);
}
}
else {
$targetParams['contact_id'] = $params['target_contact_id'];
Expand Down

0 comments on commit 0710631

Please sign in to comment.