CRM-12274
authorDonald A. Lobo <lobo@civicrm.org>
Tue, 23 Apr 2013 15:49:01 +0000 (08:49 -0700)
committerDonald A. Lobo <lobo@civicrm.org>
Tue, 23 Apr 2013 15:49:01 +0000 (08:49 -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/Core/BAO/ActionSchedule.php
tests/phpunit/CRM/Activity/BAO/ActivityTest.php
tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml
tests/phpunit/CRM/Member/Form/MembershipTest.php
tests/phpunit/api/v3/ActivityTest.php
tests/phpunit/api/v3/CaseTest.php
tests/phpunit/api/v3/dataset/activity_target_1_emailed.xml

index 99ffd5f6d77250e7480a91aa150b59add0e5ba8a..8684be925eea27260cabe5bc629e6156cc33a041 100644 (file)
@@ -120,7 +120,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       else {
         $defaults['target_contact_value'] = ts('(recipients)');
       }
-      
+
       $sourceContactId = self::getActivityContact($activity->id, $sourceID);
 
       if ($sourceContactId &&
@@ -391,7 +391,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
         }
       }
       else {
-        $assignmentParams['assignee_contact_id'] = $params['assignee_contact_id'];
+        $assignmentParams['contact_id'] = $params['assignee_contact_id'];
         $assignmentParams['record_type_id'] = $assigneeID;
         if (CRM_Utils_Array::value('id', $params)) {
           $assignment = new CRM_Activity_BAO_ActivityAssignment();
@@ -399,7 +399,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
           $assignment->record_type_id = $assigneeID;
           $assignment->find(TRUE);
 
-          if ($assignment->assignee_contact_id != $params['assignee_contact_id']) {
+          if ($assignment->contact_id != $params['assignee_contact_id']) {
             $assignmentParams['id'] = $assignment->id;
             $resultAssignment = CRM_Activity_BAO_ActivityContact::create($assignmentParams);
           }
@@ -447,7 +447,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
         }
       }
       else {
-        $targetParams['target_contact_id'] = $params['target_contact_id'];
+        $targetParams['contact_id'] = $params['target_contact_id'];
         $targetParams['record_type_id'] = $targetID;
         if (CRM_Utils_Array::value('id', $params)) {
           $target = new CRM_Activity_BAO_ActivityContact();
@@ -455,7 +455,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
           $target->record_type_id = $targetID;
           $target->find(TRUE);
 
-          if ($target->target_contact_id != $params['target_contact_id']) {
+          if ($target->contact_id != $params['target_contact_id']) {
             $targetParams['id'] = $target->id;
             $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
           }
@@ -765,7 +765,7 @@ FROM       civicrm_activity_contact ac
 INNER JOIN {$activityTempTable} ON ( ac.activity_id = {$activityTempTable}.activity_id {$notbulkActivityClause} )
 INNER JOIN civicrm_contact c ON c.id = ac.contact_id
 WHERE      c.is_deleted = 0
-          
+
 ";
     CRM_Core_DAO::executeQuery($query);
 
@@ -798,7 +798,7 @@ INNER JOIN {$activityContactTempTable} on {$activityTempTable}.activity_id = {$a
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
 
     while ($dao->fetch()) {
       $activityID = $dao->activity_id;
@@ -1494,7 +1494,7 @@ INNER JOIN civicrm_contact contact ON ac.contact_id = contact.id
 
     $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
 
     // add activity target record for every sms that is send
     $activityTargetParams = array(
@@ -1574,7 +1574,7 @@ INNER JOIN civicrm_contact contact ON ac.contact_id = contact.id
     $activityTargetParams = array(
       'activity_id' => $activityID,
       'contact_id' => $toID,
-      'record_type_id' => $targetID 
+      'record_type_id' => $targetID
     );
     CRM_Activity_BAO_ActivityContact::create($activityTargetParams);
     return TRUE;
@@ -1653,7 +1653,7 @@ INNER JOIN civicrm_contact contact ON ac.contact_id = contact.id
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
 
     // First look for activities where contactId is one of the targets
     $query = "
@@ -2547,7 +2547,7 @@ INNER JOIN  civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n
       $activityContact->record_type_id = $recordTypeID;
     }
     if ($activityContact->find(TRUE)) {
-      return $activityContact->$column;  
+      return $activityContact->$column;
     }
   }
 }
index 78062b0ed48272c191330f475af6b3522b0fce3a..4470dd3a93db7d035d61e41f3ab767a228cbf186 100755 (executable)
@@ -705,8 +705,8 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
           $activityParams = array(
             'subject' => $actionSchedule->title,
             'details' => $actionSchedule->body_html,
-            'source_contact_id' => $session->get('userID') ?
-            $session->get('userID') : $dao->contact_id,
+            'source_contact_id' =>
+            $session->get('userID') ? $session->get('userID') : $dao->contact_id,
             'target_contact_id' => $dao->contact_id,
             'activity_date_time' => date('YmdHis'),
             'status_id' => $activityStatusID,
@@ -755,14 +755,14 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
         $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
         $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
         $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
         switch (CRM_Utils_Array::value($actionSchedule->recipient, $recipientOptions)) {
           case 'Activity Assignees':
             $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$assigneeID}";
             break;
 
           case 'Activity Source':
-            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$sourceID}";  
+            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$sourceID}";
             break;
 
           default:
@@ -847,7 +847,7 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
         $where[] = "e.is_override IS NULL OR e.is_override = 0";
         $dateField = str_replace('membership_', 'e.', $actionSchedule->start_action_date);
         $notINClause = self::permissionedRelationships($contactField);
-        
+
         $memershipStatus = CRM_Member_PseudoConstant::membershipStatus(NULL, "is_current_member = 1", 'id');
         $mStatus = implode (',', $memershipStatus);
         $where[] = "e.status_id IN ({$mStatus})";
@@ -909,7 +909,7 @@ INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_sche
 {$joinClause}
 LEFT JOIN {$reminderJoinClause}
 {$whereClause} AND {$dateClause} {$notINClause}";
-      
+
       CRM_Core_DAO::executeQuery($query, array(1 => array($actionSchedule->id, 'Integer')));
 
       // if repeat is turned ON:
index a416639915a48ce2ff5ff16ccb51d85617ce7376..05feb1497b460213e761b90c3e1c418f53f71402 100644 (file)
@@ -16,7 +16,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
 
   function tearDown() {
     // truncate a few tables
-    $tablesToTruncate = array('civicrm_contact', 'civicrm_activity', 'civicrm_activity_target', 'civicrm_activity_assignment');
+    $tablesToTruncate = array('civicrm_contact', 'civicrm_activity', 'civicrm_activity_contact');
     $this->quickCleanup($tablesToTruncate);
   }
 
index 8c0c46adb353662b339cc73a3063fdcd8caa5b90..9dd8912ce06228f37919968b096f8152e6eb9ce6 100644 (file)
         activity_type_id="1"
         status_id="2"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="1"
-        assignee_contact_id="2"
+        contact_id="2"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="1"
-        assignee_contact_id="3"
+        contact_id="3"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="2"
-        assignee_contact_id="4"
+        contact_id="4"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="2"
-        assignee_contact_id="5"
+        contact_id="5"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="3"
-        assignee_contact_id="6"
+        contact_id="6"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="3"
-        assignee_contact_id="7"
+        contact_id="7"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="4"
-        assignee_contact_id="8"
+        contact_id="8"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="4"
-        assignee_contact_id="9"
+        contact_id="9"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="5"
-        assignee_contact_id="10"
+        contact_id="10"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="5"
-        assignee_contact_id="11"
+        contact_id="11"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="6"
-        assignee_contact_id="12"
+        contact_id="12"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="6"
-        assignee_contact_id="13"
+        contact_id="13"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="7"
-        assignee_contact_id="14"
+        contact_id="14"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="7"
-        assignee_contact_id="15"
+        contact_id="15"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="8"
-        assignee_contact_id="16"
+        contact_id="16"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="8"
-        assignee_contact_id="1"
-    /> 
-    <civicrm_activity_assignment
+        contact_id="1"
+        record_type_id="1"
+    />
+    <civicrm_activity_contact
         activity_id="9"
-        assignee_contact_id="2"
+        contact_id="2"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="9"
-        assignee_contact_id="3"
-    />       
-    <civicrm_activity_assignment
+        contact_id="3"
+        record_type_id="1"
+    />
+    <civicrm_activity_contact
         activity_id="10"
-        assignee_contact_id="4"
+        contact_id="4"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="10"
-        assignee_contact_id="5"
+        contact_id="5"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="11"
-        assignee_contact_id="6"
+        contact_id="6"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="11"
-        assignee_contact_id="7"
-    /> 
-    <civicrm_activity_assignment
+        contact_id="7"
+        record_type_id="1"
+    />
+    <civicrm_activity_contact
         activity_id="12"
-        assignee_contact_id="8"
+        contact_id="8"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="12"
-        assignee_contact_id="9"
-    />       
-    <civicrm_activity_assignment
+        contact_id="9"
+        record_type_id="1"
+    />
+    <civicrm_activity_contact
         activity_id="13"
-        assignee_contact_id="10"
+        contact_id="10"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="13"
-        assignee_contact_id="11"
+        contact_id="11"
+        record_type_id="1"
     />
-    <civicrm_activity_assignment
+    <civicrm_activity_contact
         activity_id="15"
-        assignee_contact_id="13"
+        contact_id="13"
+        record_type_id="1"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="1"
-        target_contact_id="4"
+        contact_id="4"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="1"
-        target_contact_id="5"
+        contact_id="5"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="2"
-        target_contact_id="6"
+        contact_id="6"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="2"
-        target_contact_id="7"
+        contact_id="7"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="3"
-        target_contact_id="8"
+        contact_id="8"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="3"
-        target_contact_id="9"
+        contact_id="9"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="4"
-        target_contact_id="10"
+        contact_id="10"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="4"
-        target_contact_id="11"
+        contact_id="11"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="5"
-        target_contact_id="12"
+        contact_id="12"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="5"
-        target_contact_id="13"
+        contact_id="13"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="6"
-        target_contact_id="14"
+        contact_id="14"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="6"
-        target_contact_id="15"
+        contact_id="15"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="7"
-        target_contact_id="16"
+        contact_id="16"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="7"
-        target_contact_id="1"
+        contact_id="1"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="8"
-        target_contact_id="2"
+        contact_id="2"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="8"
-        target_contact_id="3"
-    /> 
-    <civicrm_activity_target
+        contact_id="3"
+        record_type_id="3"
+    />
+    <civicrm_activity_contact
         activity_id="9"
-        target_contact_id="4"
+        contact_id="4"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="9"
-        target_contact_id="5"
-    />       
-    <civicrm_activity_target
+        contact_id="5"
+        record_type_id="3"
+    />
+    <civicrm_activity_contact
         activity_id="10"
-        target_contact_id="6"
+        contact_id="6"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="10"
-        target_contact_id="7"
+        contact_id="7"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="11"
-        target_contact_id="8"
+        contact_id="8"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="11"
-        target_contact_id="9"
-    /> 
-    <civicrm_activity_target
+        contact_id="9"
+        record_type_id="3"
+    />
+    <civicrm_activity_contact
         activity_id="12"
-        target_contact_id="10"
+        contact_id="10"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="12"
-        target_contact_id="11"
-    />       
-    <civicrm_activity_target
+        contact_id="11"
+        record_type_id="3"
+    />
+    <civicrm_activity_contact
         activity_id="14"
-        target_contact_id="12"
+        contact_id="12"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="14"
-        target_contact_id="13"
+        contact_id="13"
+        record_type_id="3"
     />
-    <civicrm_activity_target
+    <civicrm_activity_contact
         activity_id="15"
-        target_contact_id="14"
+        contact_id="14"
+        record_type_id="3"
     />
 </dataset>
index a5d8ecf0cc162015545edd191aa6d53de4664ce8..8e5f28b190626ca63536978f6a20680c9db95a2b 100644 (file)
@@ -151,8 +151,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
         'civicrm_contribution_page',
         'civicrm_contribution_widget',
         'civicrm_activity',
-        'civicrm_activity_assignment',
-        'civicrm_activity_target',
+        'civicrm_activity_contact',
         'civicrm_case_activity',
         'civicrm_pledge',
         'civicrm_price_field',
index 70b5e397eba37f3e9bfdcb4d39db29fd6f78a945..41498f73b312e045f124d05f40a8080ce009249f 100644 (file)
@@ -122,8 +122,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
     $tablesToTruncate = array(
       'civicrm_contact',
       'civicrm_activity',
-      'civicrm_activity_target',
-      'civicrm_activity_assignment',
+      'civicrm_activity_contact',
     );
     $this->quickCleanup($tablesToTruncate, TRUE);
     civicrm_api('option_value', 'delete', array('version' => 3, 'id' => $this->test_activity_type_id));
index a0a3b3620d0592553fcc25c159710f581c134e4f..b87b28076021b0a7967b882afb4ede0258590485 100644 (file)
@@ -103,8 +103,7 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'civicrm_case',
       'civicrm_case_contact',
       'civicrm_case_activity',
-      'civicrm_activity_target',
-      'civicrm_activity_assignment',
+      'civicrm_activity_contact',
       'civicrm_relationship',
       'civicrm_relationship_type',
     );
@@ -238,8 +237,7 @@ class api_v3_CaseTest extends CiviUnitTestCase {
       'civicrm_case',
       'civicrm_case_contact',
       'civicrm_case_activity',
-      'civicrm_activity_target',
-      'civicrm_activity_assignment',
+      'civicrm_activity_contact',
       'civicrm_relationship',
       'civicrm_relationship_type',
     );
@@ -413,11 +411,12 @@ class api_v3_CaseTest extends CiviUnitTestCase {
     $this->assertEquals($dao->find(), 1, 'case_activity table not populated correctly in line ' . __LINE__);
     $dao->free();
 
-    require_once 'CRM/Activity/DAO/ActivityTarget.php';
-    $dao = new CRM_Activity_DAO_ActivityTarget();
+    require_once 'CRM/Activity/DAO/ActivityContact.php';
+    $dao = new CRM_Activity_DAO_ActivityContact();
     $dao->activity_id = $this->_caseActivityId;
-    $dao->target_contact_id = $this->_params['contact_id'];
-    $this->assertEquals($dao->find(), 1, 'activity_target table not populated correctly in line ' . __LINE__);
+    $dao->contact_id = $this->_params['contact_id'];
+    $dao->record_type_id = 3;
+    $this->assertEquals($dao->find(), 1, 'activity_contact table not populated correctly in line ' . __LINE__);
     $dao->free();
 
     // TODO: There's more things we could check
index 455bb88bfdb815a23c1660cdaa1637b31f2ced01..03cc4b176f83759caeb02b7466e66023053aa3ef 100644 (file)
@@ -1,14 +1,16 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<!--  $Id: activity_target_1_emailed.xml 23352 2009-08-19 21:52:45Z walt $  -->
+<!--  $Id: activity_contact_1_emailed.xml 23352 2009-08-19 21:52:45Z walt $  -->
 <dataset>
-  <table name="civicrm_activity_target">
+  <table name="civicrm_activity_contact">
     <column>id</column>
     <column>activity_id</column>
-    <column>target_contact_id</column>
+    <column>contact_id</column>
+    <column>record_type_id</column>
     <row>
       <value>1</value>                      <!--  id  -->
       <value>1</value>                      <!--  activity_id  -->
       <value>17</value>                      <!--  target_contact_id  -->
+      <value>3</value>                      <!--  record_type_id  -->
     </row>
   </table>
 </dataset>