CRM-12274
authorDonald A. Lobo <lobo@civicrm.org>
Tue, 23 Apr 2013 21:25:01 +0000 (14:25 -0700)
committerDonald A. Lobo <lobo@civicrm.org>
Tue, 23 Apr 2013 21:25:01 +0000 (14:25 -0700)
----------------------------------------
* CRM-12274: Merge activity tables into one unified table activity contact table
  http://issues.civicrm.org/jira/browse/CRM-12274

CRM/Activity/BAO/Activity.php
CRM/Activity/BAO/ActivityContact.php
tests/phpunit/CRM/Activity/BAO/ActivityTest.php
tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml

index 8684be925eea27260cabe5bc629e6156cc33a041..14581f6365a431f86fb863ca351178befb7c9dc8 100644 (file)
@@ -96,6 +96,8 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
       $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
 
+      $defaults['source_contact'] = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $sourceID);
+
       // TODO: at some stage we'll have to deal
       // TODO: with multiple values for assignees and targets, but
       // TODO: for now, let's just fetch first row
@@ -122,6 +124,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       }
 
       $sourceContactId = self::getActivityContact($activity->id, $sourceID);
+      $activity->source_contact_id = $sourceContactId;
 
       if ($sourceContactId &&
         !CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
@@ -658,7 +661,8 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
    */
   static function &getActivities($input) {
     //step 1: Get the basic activity data
-    $bulkActivityTypeID = CRM_Core_OptionGroup::getValue('activity_type',
+    $bulkActivityTypeID = CRM_Core_OptionGroup::getValue(
+      'activity_type',
       'Bulk Email',
       'name'
     );
@@ -987,7 +991,7 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
       "civicrm_option_group.name = 'activity_type'",
       "civicrm_activity.is_deleted = 0",
       "civicrm_activity.is_current_revision =  1",
-      "civicrm_activity.is_test = 0",
+      "civicrm_activity.is_test= 0",
     );
 
     if ($input['context'] != 'activity') {
index a82d8e1ce5638a1366ae2559d459f56bcd85dc3a..e223579d8ef8a9ca993ae64e0f88a923bdd540aa 100644 (file)
@@ -59,7 +59,10 @@ class CRM_Activity_BAO_ActivityContact extends CRM_Activity_DAO_ActivityContact
     $activityContact = new CRM_Activity_DAO_ActivityContact();
 
     $activityContact->copyValues($params);
-    return $activityContact->save();
+    if (!$activityContact->find(TRUE)) {
+      return $activityContact->save();
+    }
+    return $activityContact;
   }
 
   /**
@@ -104,7 +107,7 @@ AND        contact_a.is_deleted = 0
   }
 
   /**
-   * function to retrieve id of target contact by activity_id 
+   * function to retrieve id of target contact by activity_id
    *
    * @param int    $id  ID of the activity
    *
@@ -124,8 +127,8 @@ AND        contact_a.is_deleted = 0
 FROM       civicrm_activity_contact
 INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
 WHERE      activity_id = %1
-AND        record_type_id = %2 
-AND        civicrm_contact.is_deleted = 0 
+AND        record_type_id = %2
+AND        civicrm_contact.is_deleted = 0
 ";
     $params = array(
       1 => array($activityID, 'Integer'),
index a19fd531c9dde17a16d311e7abb9409412ae8a97..a71106feaf63bad5925d8dfe5008dc7a93aa6bd2 100644 (file)
@@ -131,11 +131,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
     $activity = CRM_Activity_BAO_Activity::retrieve($params, $defaults);
 
     $this->assertEquals($activity->subject, 'Scheduling Meeting', 'Verify activity subject is correct.');
-    $this->assertEquals($activity->source_contact_id, $contactId, 'Verify source contact id is correct.');
     $this->assertEquals($activity->activity_type_id, 2, 'Verify activity type id is correct.');
+    $this->assertEquals($activity->source_contact_id, $contactId, 'Verify source contact id is correct.');
 
     $this->assertEquals($defaults['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.');
-    $this->assertEquals($defaults['source_contact_id'], $contactId, 'Verify source contact id is correct.');
     $this->assertEquals($defaults['activity_type_id'], 2, 'Verify activity type id is correct.');
 
     $this->assertEquals($defaults['target_contact'][0], $targetContactId, 'Verify target contact id is correct.');
@@ -222,7 +221,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
       'Database check for created activity target.'
     );
 
-    CRM_Activity_BAO_Activity::deleteActivityTarget($activityId);
+    CRM_Activity_BAO_Activity::deleteActivityContact($activityId, 3);
 
     $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $targetContactId, 'id',
       'contact_id', 'Database check for deleted activity target.'
@@ -263,7 +262,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
       'Database check for created activity assignment.'
     );
 
-    CRM_Activity_BAO_Activity::deleteActivityAssignment($activityId);
+    CRM_Activity_BAO_Activity::deleteActivityContact($activityId, 1);
 
     $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $assigneeContactId, 'id',
       'contact_id', 'Database check for deleted activity assignment.'
index 9dd8912ce06228f37919968b096f8152e6eb9ce6..d76f419e53e75ece58bb30b0263fb8f9c6ec50b6 100644 (file)
         first_name="Test"
         last_name="Contact 17"
     />
-    <!--  Assignee Contact: 2,3 Target Contact: 4,5  -->
+    <!--  Source Contact: 1, Assignee Contact: 2,3 Target Contact: 4,5  -->
     <civicrm_activity
         id="1"
-        source_contact_id="1"
         subject="subject 1"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 4,5 Target: 6,7  -->
+    <!-- Source Contact: 2, Assignee Contact: 4,5 Target: 6,7  -->
     <civicrm_activity
         id="2"
-        source_contact_id="2"
         subject="subject 2"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 6,7  Target Contact: 8,9 -->
+    <!--  Source Contact: 3, Assignee Contact: 6,7  Target Contact: 8,9 -->
     <civicrm_activity
         id="3"
-        source_contact_id="3"
         subject="subject 3"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 8, 9  Target Contact: 10,11 -->
+    <!--  Source Contact: 4, Assignee Contact: 8, 9  Target Contact: 10,11 -->
     <civicrm_activity
         id="4"
-        source_contact_id="4"
         subject="subject 4"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 10, 11 Target Contact: 12, 13 -->
+    <!--  Source Contact: 5, Assignee Contact: 10, 11 Target Contact: 12, 13 -->
     <civicrm_activity
         id="5"
-        source_contact_id="5"
         subject="subject 5"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 12, 13 Target Contact: 14, 15  -->
+    <!-- Source Contact: 6, Assignee Contact: 12, 13 Target Contact: 14, 15  -->
     <civicrm_activity
         id="6"
-        source_contact_id="6"
         subject="subject 6"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 14, 15 Target Contact: 16, 1 -->
+    <!-- Source Contact: 7, Assignee Contact: 14, 15 Target Contact: 16, 1 -->
     <civicrm_activity
         id="7"
-        source_contact_id="7"
         subject="subject 7"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 16, 1 Target Contact: 2, 3  -->
+    <!-- Source Contact: 8, Assignee Contact: 16, 1 Target Contact: 2, 3  -->
     <civicrm_activity
         id="8"
-        source_contact_id="8"
         subject="subject 8"
         activity_type_id="2"
         status_id="1"
     />
-    <!--  Assignee Contact: 2, 3 Target Contact: 4, 5  -->
+    <!-- Source Contact: 9, Assignee Contact: 2, 3 Target Contact: 4, 5  -->
     <civicrm_activity
         id="9"
-        source_contact_id="9"
         subject="subject 9"
         activity_type_id="1"
         status_id="2"
     />
-    <!--  Assignee Contact: 4, 5 Target Contact: 6,7  -->
+    <!-- Source Contact: 10, Assignee Contact: 4, 5 Target Contact: 6,7  -->
     <civicrm_activity
         id="10"
-        source_contact_id="10"
         subject="subject 10"
         activity_type_id="1"
         status_id="2"
     />
-    <!--  Assignee Contact: 6, 7  Target Contact: 8, 9 -->
+    <!-- Source Contact: 11, Assignee Contact: 6, 7  Target Contact: 8, 9 -->
     <civicrm_activity
         id="11"
-        source_contact_id="11"
         subject="subject 11"
         activity_type_id="1"
         status_id="2"
     />
-    <!-- Assignee Contact: 8, 9 Target Contact: 10, 11  -->
+    <!-- Source Contact: 12, Assignee Contact: 8, 9 Target Contact: 10, 11  -->
     <civicrm_activity
         id="12"
-        source_contact_id="12"
         subject="subject 12"
         activity_type_id="1"
         status_id="2"
     />
-    <!--  Assignee Contact: 10, 11 Target Contact: none  -->
+    <!-- Source Contact: 13, Assignee Contact: 10, 11 Target Contact: none  -->
     <civicrm_activity
         id="13"
-        source_contact_id="13"
         subject="subject 13"
         activity_type_id="1"
         status_id="2"
     />
-    <!--  Assignee Contact: none Target Contact: 12, 13    -->
+    <!-- Source Contact: 14, Assignee Contact: none Target Contact: 12, 13    -->
     <civicrm_activity
         id="14"
-        source_contact_id="14"
         subject="subject 14"
         activity_type_id="1"
         status_id="2"
     />
-    <!--  Assignee Contact: 13 Target Contact: 14  -->
+    <!-- Source Contact: 15, Assignee Contact: 13 Target Contact: 14  -->
     <civicrm_activity
         id="15"
-        source_contact_id="15"
         subject="subject 15"
         activity_type_id="1"
         status_id="2"
     />
-    <!--  Assignee Contact: none Target Contact: none  -->
+    <!-- Source Contact: 16, Assignee Contact: none Target Contact: none  -->
     <civicrm_activity
         id="16"
-        source_contact_id="16"
         subject="subject 16"
         activity_type_id="1"
         status_id="2"
     />
+    <!-- Source Contacts -->
     <civicrm_activity_contact
         activity_id="1"
+        contact_id="1"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="2"
         contact_id="2"
-        record_type_id="1"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="3"
+        contact_id="3"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="4"
+        contact_id="4"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="5"
+        contact_id="5"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="6"
+        contact_id="6"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="7"
+        contact_id="7"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="8"
+        contact_id="8"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="9"
+        contact_id="9"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="10"
+        contact_id="10"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="11"
+        contact_id="11"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="12"
+        contact_id="12"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="13"
+        contact_id="13"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="14"
+        contact_id="14"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="15"
+        contact_id="15"
+        record_type_id="2"
+    />
+    <civicrm_activity_contact
+        activity_id="16"
+        contact_id="16"
+        record_type_id="2"
     />
     <civicrm_activity_contact
         activity_id="1"