From: Donald A. Lobo Date: Tue, 23 Apr 2013 15:49:01 +0000 (-0700) Subject: CRM-12274 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b319d00a5786393765887e353e3e706ad054ac4e;p=civicrm-core.git CRM-12274 ---------------------------------------- * CRM-12274: Merge activity tables into one unified table activity contact table http://issues.civicrm.org/jira/browse/CRM-12274 --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 99ffd5f6d7..8684be925e 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -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; } } } diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 78062b0ed4..4470dd3a93 100755 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -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: diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index a416639915..05feb1497b 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -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); } diff --git a/tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml b/tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml index 8c0c46adb3..9dd8912ce0 100644 --- a/tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml +++ b/tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml @@ -299,220 +299,274 @@ activity_type_id="1" status_id="2" /> - - - - - - - - - - - - - - - - - + - - + - - - - + - - + - - - - - - - - - - - - - - - - - - - + - - + - - - - + - - + - - diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index a5d8ecf0cc..8e5f28b190 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -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', diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index 70b5e397eb..41498f73b3 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -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)); diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index a0a3b3620d..b87b280760 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -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 diff --git a/tests/phpunit/api/v3/dataset/activity_target_1_emailed.xml b/tests/phpunit/api/v3/dataset/activity_target_1_emailed.xml index 455bb88bfd..03cc4b176f 100644 --- a/tests/phpunit/api/v3/dataset/activity_target_1_emailed.xml +++ b/tests/phpunit/api/v3/dataset/activity_target_1_emailed.xml @@ -1,14 +1,16 @@ - + - +
idactivity_id - target_contact_id + contact_id + record_type_id 1 1 17 + 3