CRM-20578: Empty update of Activity assignee/target results into DB error
authorJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 15 May 2017 13:54:08 +0000 (19:24 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 15 May 2017 13:54:08 +0000 (19:24 +0530)
api/v3/Activity.php
tests/phpunit/api/v3/ActivityTest.php

index 0d6a85de41c48cc709624ddd98693131aa99573d..66d1544b7d5f297e8a4767523b4fc47b18e81c29 100644 (file)
@@ -571,7 +571,7 @@ function _civicrm_api3_activity_check_params(&$params) {
 SELECT  count(*)
   FROM  civicrm_contact
  WHERE  id IN (' . implode(', ', $contactIds) . ' )';
-    if (count($contactIds) != CRM_Core_DAO::singleValueQuery($sql)) {
+    if (!empty($contactIds) && count($contactIds) != CRM_Core_DAO::singleValueQuery($sql)) {
       throw new API_Exception('Invalid Contact Id');
     }
   }
index c9f3ae9f7802b3ed74bafdd51c5471a35629f648..c35fd143e8659d7c93c59b6943aae7a4efdccdfe 100644 (file)
@@ -1014,6 +1014,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
    */
   public function testActivityUpdate() {
     $result = $this->callAPISuccess('activity', 'create', $this->_params);
+    $this->_contactID2 = $this->individualCreate();
 
     $params = array(
       'id' => $result['id'],
@@ -1024,6 +1025,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
       'details' => 'Lets update Meeting',
       'status_id' => 1,
       'source_contact_id' => $this->_contactID,
+      'assignee_contact_id' => $this->_contactID2,
       'priority_id' => 1,
     );
 
@@ -1032,6 +1034,26 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
     $params['activity_date_time'] = '2009-10-11 12:34:56';
     // we also unset source_contact_id since it is stored in an aux table
     unset($params['source_contact_id']);
+    //Check if assignee created.
+    $assignee = $this->callAPISuccess('ActivityContact', 'get', array(
+      'activity_id' => $result['id'],
+      'return' => array("contact_id"),
+      'record_type_id' => "Activity Assignees",
+    ));
+    $this->assertNotEmpty($assignee['values']);
+
+    //clear assignee contacts.
+    $updateParams = array(
+      'id' => $result['id'],
+      'assignee_contact_id' => array(),
+    );
+    $activity = $this->callAPISuccess('activity', 'create', $updateParams);
+    $assignee = $this->callAPISuccess('ActivityContact', 'get', array(
+      'activity_id' => $activity['id'],
+      'return' => array("contact_id"),
+      'record_type_id' => "Activity Assignees",
+    ));
+    $this->assertEmpty($assignee['values']);
     $this->getAndCheck($params, $result['id'], 'activity');
   }