From 2517d0799dbc8dabeb45b7390632e65aa316bd61 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Tue, 23 Apr 2013 14:25:01 -0700 Subject: [PATCH] CRM-12274 ---------------------------------------- * 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 | 8 +- CRM/Activity/BAO/ActivityContact.php | 11 +- .../phpunit/CRM/Activity/BAO/ActivityTest.php | 7 +- .../BAO/activities_for_dashboard_count.xml | 126 +++++++++++++----- 4 files changed, 109 insertions(+), 43 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 8684be925e..14581f6365 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -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') { diff --git a/CRM/Activity/BAO/ActivityContact.php b/CRM/Activity/BAO/ActivityContact.php index a82d8e1ce5..e223579d8e 100644 --- a/CRM/Activity/BAO/ActivityContact.php +++ b/CRM/Activity/BAO/ActivityContact.php @@ -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'), diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index a19fd531c9..a71106feaf 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -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.' 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 9dd8912ce0..d76f419e53 100644 --- a/tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml +++ b/tests/phpunit/CRM/Activity/BAO/activities_for_dashboard_count.xml @@ -171,138 +171,198 @@ first_name="Test" last_name="Contact 17" /> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + +