From d19632b1c725aa553245c16d24cbcffaed62cde2 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Thu, 30 Mar 2017 11:23:55 +0530 Subject: [PATCH] CRM-20361 --- CRM/Core/BAO/ActionSchedule.php | 19 +++++++++---------- .../CRM/Core/BAO/ActionScheduleTest.php | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index d8b45f6833..b3194882e3 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -310,6 +310,11 @@ FROM civicrm_action_schedule cas if ($actionSchedule->mode == 'Email' or $actionSchedule->mode == 'User_Preference') { CRM_Utils_Array::extend($errors, self::sendReminderEmail($tokenRow, $actionSchedule, $dao->contactID)); } + // insert activity log record if needed + if ($actionSchedule->record_activity && empty($errors)) { + $caseID = empty($dao->case_id) ? NULL : $dao->case_id; + CRM_Core_BAO_ActionSchedule::createMailingActivity($tokenRow, $mapping, $dao->contactID, $dao->entityID, $caseID); + } } } catch (\Civi\Token\TokenException $e) { @@ -324,12 +329,6 @@ FROM civicrm_action_schedule cas 'action_date_time' => $now, ); CRM_Core_BAO_ActionLog::create($logParams); - - // insert activity log record if needed - if ($actionSchedule->record_activity && empty($errors)) { - $caseID = empty($dao->case_id) ? NULL : $dao->case_id; - CRM_Core_BAO_ActionSchedule::createMailingActivity($actionSchedule, $mapping, $dao->contactID, $dao->entityID, $caseID); - } } $dao->free(); @@ -455,14 +454,14 @@ FROM civicrm_action_schedule cas * WISHLIST: Instead of saving $actionSchedule->body_html, call this immediately after * sending the message and pass in the fully rendered text of the message. * - * @param CRM_Core_DAO_ActionSchedule $actionSchedule + * @param object $tokenRow * @param Civi\ActionSchedule\Mapping $mapping * @param int $contactID * @param int $entityID * @param int|NULL $caseID * @throws CRM_Core_Exception */ - protected static function createMailingActivity($actionSchedule, $mapping, $contactID, $entityID, $caseID) { + protected static function createMailingActivity($tokenRow, $mapping, $contactID, $entityID, $caseID) { $session = CRM_Core_Session::singleton(); if ($mapping->getEntity() == 'civicrm_membership') { @@ -475,8 +474,8 @@ FROM civicrm_action_schedule cas } $activityParams = array( - 'subject' => $actionSchedule->title, - 'details' => $actionSchedule->body_html, + 'subject' => $tokenRow->render('subject'), + 'details' => $tokenRow->render('body_html'), 'source_contact_id' => $session->get('userID') ? $session->get('userID') : $contactID, 'target_contact_id' => $contactID, 'activity_date_time' => CRM_Utils_Time::getTime('YmdHis'), diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index 043b5846f5..d5217fb001 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -109,8 +109,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'title' => 'One Day Phone Call Notice', 'limit_to' => '1', 'absolute_date' => NULL, - 'body_html' => '

1-Day (non-repeating)

', - 'body_text' => '1-Day (non-repeating)', + 'body_html' => '

1-Day (non-repeating) (for {activity.subject})

', + 'body_text' => '1-Day (non-repeating) (for {activity.subject})', 'end_action' => NULL, 'end_date' => NULL, 'end_frequency_interval' => NULL, @@ -125,7 +125,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'recipient' => '2', 'recipient_listing' => NULL, 'recipient_manual' => NULL, - 'record_activity' => NULL, + 'record_activity' => 1, 'repetition_frequency_interval' => NULL, 'repetition_frequency_unit' => NULL, 'start_action_condition' => 'before', @@ -804,6 +804,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { $activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phonecall']); $this->assertTrue(is_numeric($activity->id)); $contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']); + $activity->subject = "Test subject for Phonecall"; $activity->save(); $source['contact_id'] = $contact['id']; @@ -831,6 +832,14 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'recipients' => array(), ), )); + $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); + $activityDAO = new CRM_Activity_DAO_Activity(); + $activityDAO->source_record_id = $activity->id; + $activityDAO->activity_type_id = array_search('Reminder Sent', $activityTypes); + $activityDAO->find(); + while ($activityDAO->fetch()) { + $this->assertContains($activity->subject, $activityDAO->details); + } } public function testActivityDateTimeMatchRepeatableSchedule() { -- 2.25.1