*/
public static function createEmailActivity($sourceContactID, $subject, $html, $text, $additionalDetails, $campaignID, $attachments, $caseID) {
$activityTypeID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Email');
-
+ CRM_Core_Error::deprecatedFunctionWarning('none');
// CRM-6265: save both text and HTML parts in details (if present)
if ($html and $text) {
$details = "-ALTERNATIVE ITEM 0-\n{$html}{$additionalDetails}\n-ALTERNATIVE ITEM 1-\n{$text}{$additionalDetails}\n-ALTERNATIVE END-\n";
$campaignId = NULL,
$caseId = NULL
) {
- // @todo add noisy deprecation.
- // This function is no longer called from core.
- // I just left off the noisy deprecation for now as there
- // are already a lot of other noisy deprecation points in 5.43.
- // get the contact details of logged in contact, which we set as from email
+ CRM_Core_Error::deprecatedFunctionWarning('none');
if ($userID == NULL) {
$userID = CRM_Core_Session::getLoggedInContactID();
}
}
$tokenSubject = $subject;
- $tokenText = in_array($values['preferred_mail_format'], ['Both', 'Text'], TRUE) ? $text : '';
- $tokenHtml = in_array($values['preferred_mail_format'], ['Both', 'HTML'], TRUE) ? $html : '';
$renderedTemplate = CRM_Core_BAO_MessageTemplate::renderTemplate([
'messageTemplate' => [
- 'msg_text' => $tokenText,
- 'msg_html' => $tokenHtml,
+ 'msg_text' => $text,
+ 'msg_html' => $html,
'msg_subject' => $tokenSubject,
],
'tokenContext' => $tokenContext,
$cc = NULL,
$bcc = NULL
) {
+ CRM_Core_Error::deprecatedFunctionWarning('none');
[$toDisplayName, $toEmail, $toDoNotEmail] = CRM_Contact_BAO_Contact::getContactDetails($toID);
if ($emailAddress) {
$toEmail = trim($emailAddress);
}
}
- /**
- * Test that smarty is rendered, if enabled.
- *
- * @throws \CRM_Core_Exception
- * @throws \CiviCRM_API3_Exception
- */
- public function testSmartyEnabled(): void {
- putenv('CIVICRM_MAIL_SMARTY=1');
- $this->createLoggedInUser();
- $contactID = $this->individualCreate(['last_name' => 'Red']);
- CRM_Activity_BAO_Activity::sendEmail(
- [
- $contactID => [
- 'preferred_mail_format' => 'Both',
- 'contact_id' => $contactID,
- 'email' => 'a@example.com',
- ],
- ],
- '{contact.first_name} {$contact.first_name}',
- '{contact.first_name} {$contact.first_name}',
- '{contact.first_name} {$contact.first_name}',
- NULL,
- NULL,
- 'mail@example.com',
- NULL,
- NULL,
- NULL,
- [$contactID]
- );
- $activity = $this->callAPISuccessGetValue('Activity', ['return' => 'details']);
- putenv('CIVICRM_MAIL_SMARTY=0');
- }
-
- /**
- * Same as testSendEmailWillReplaceTokensUniquelyForEachContact but with
- * 3 recipients and an attachment.
- *
- * @throws \CRM_Core_Exception
- * @throws \CiviCRM_API3_Exception
- */
- public function testSendEmailWillReplaceTokensUniquelyForEachContact3(): void {
- $contactId1 = $this->individualCreate(['last_name' => 'Red']);
- $contactId2 = $this->individualCreate(['last_name' => 'Pink']);
- $contactId3 = $this->individualCreate(['last_name' => 'Ochre']);
-
- // create a logged in USER since the code references it for sendEmail user.
- $loggedInUser = $this->createLoggedInUser();
- $contact = $this->callAPISuccess('Contact', 'get', ['sequential' => 1, 'id' => ['IN' => [$contactId1, $contactId2, $contactId3]]]);
-
- // Add contact tokens in subject, html , text.
- $subject = __FUNCTION__ . ' subject' . '{contact.display_name}';
- $html = __FUNCTION__ . ' html' . '{contact.display_name}';
- // Check the smarty doesn't mess stuff up.
- $text = ' text' . '{contact.display_name} {$contact.first_name}';
-
- $filepath = Civi::paths()->getPath('[civicrm.files]/custom');
- $fileName = 'test_email_create.txt';
- $fileUri = "{$filepath}/{$fileName}";
- // Create a file.
- CRM_Utils_File::createFakeFile($filepath, 'aaaaaa', $fileName);
- $attachments = [
- 'attachFile_1' =>
- [
- 'uri' => $fileUri,
- 'type' => 'text/plain',
- 'location' => $fileUri,
- ],
- ];
-
- CRM_Activity_BAO_Activity::sendEmail(
- $contact['values'],
- $subject,
- $text,
- $html,
- $contact['values'][0]['email'],
- $loggedInUser,
- __FUNCTION__ . '@example.com',
- $attachments,
- NULL,
- NULL,
- array_column($contact['values'], 'id'),
- NULL,
- NULL,
- $this->getCampaignID()
- );
- $result = $this->callAPISuccess('Activity', 'get', ['campaign_id' => $this->getCampaignID()]);
- // An activity created for each of the two contacts
- $this->assertEquals(3, $result['count']);
- $id = 0;
- foreach ($result['values'] as $activity) {
- $htmlValue = str_replace('{contact.display_name}', $contact['values'][$id]['display_name'], $html);
- $textValue = str_replace('{contact.display_name}', $contact['values'][$id]['display_name'], $text);
- $subjectValue = str_replace('{contact.display_name}', $contact['values'][$id]['display_name'], $subject);
- $details = "-ALTERNATIVE ITEM 0-
-$htmlValue
--ALTERNATIVE ITEM 1-
-$textValue
--ALTERNATIVE END-
-";
- $this->assertEquals($activity['details'], $details, 'Activity details does not match.');
- $this->assertEquals($activity['subject'], $subjectValue, 'Activity subject does not match.');
- $id++;
- }
-
- unlink($fileUri);
- }
-
- /**
- * Checks that attachments are not duplicated for activities.
- */
- public function testSendEmailDoesNotDuplicateAttachmentFileIdsForActivitiesCreated() {
- $contactId1 = $this->individualCreate(['last_name' => 'Red']);
- $contactId2 = $this->individualCreate(['last_name' => 'Pink']);
-
- // create a logged in USER since the code references it for sendEmail user.
- $this->createLoggedInUser();
- $session = CRM_Core_Session::singleton();
- $loggedInUser = $session->get('userID');
- $contact = $this->callAPISuccess('Contact', 'get', ['sequential' => 1, 'id' => ['IN' => [$contactId1, $contactId2]]]);
-
- // Create a campaign.
- $result = $this->callAPISuccess('Campaign', 'create', [
- 'version' => $this->_apiversion,
- 'title' => __FUNCTION__ . ' campaign',
- ]);
- $campaign_id = $result['id'];
-
- $subject = __FUNCTION__ . ' subject';
- $html = __FUNCTION__ . ' html';
- $text = __FUNCTION__ . ' text';
- $userID = $loggedInUser;
-
- $filepath = Civi::paths()->getPath('[civicrm.files]/custom');
- $fileName = "test_email_create.txt";
- $fileUri = "{$filepath}/{$fileName}";
- // Create a file.
- CRM_Utils_File::createFakeFile($filepath, 'Bananas do not bend themselves without a little help.', $fileName);
- $attachments = [
- 'attachFile_1' =>
- [
- 'uri' => $fileUri,
- 'type' => 'text/plain',
- 'location' => $fileUri,
- ],
- ];
-
- CRM_Activity_BAO_Activity::sendEmail(
- $contact['values'],
- $subject,
- $text,
- $html,
- $contact['values'][0]['email'],
- $userID,
- $from = __FUNCTION__ . '@example.com',
- $attachments,
- $cc = NULL,
- $bcc = NULL,
- $contactIds = array_column($contact['values'], 'id'),
- $additionalDetails = NULL,
- NULL,
- $campaign_id
- );
- $result = $this->callAPISuccess('activity', 'get', ['campaign_id' => $campaign_id]);
- // An activity created for each of the two contacts, i.e two activities.
- $this->assertEquals(2, $result['count']);
- $activityIds = array_column($result['values'], 'id');
- $result = $this->callAPISuccess('Activity', 'get', [
- 'return' => ['file_id'],
- 'id' => ['IN' => $activityIds],
- 'sequential' => 1,
- ]);
-
- // Verify that the that both activities are linked to the same File Id.
- $this->assertEquals($result['values'][0]['file_id'], $result['values'][1]['file_id']);
- }
-
/**
* Adds a case with one activity.
*
];
}
- /**
- * Test the returned activity ids when there are multiple "To" recipients.
- * Similar to testSendEmailWillReplaceTokensUniquelyForEachContact but we're
- * checking the activity ids returned from sendEmail.
- */
- public function testSendEmailWithMultipleToRecipients(): void {
- $contactId1 = $this->individualCreate(['first_name' => 'Aaaa', 'last_name' => 'Bbbb']);
- $contactId2 = $this->individualCreate(['first_name' => 'Cccc', 'last_name' => 'Dddd']);
-
- // create a logged in USER since the code references it for sendEmail user.
- $loggedInUser = $this->createLoggedInUser();
- $contacts = $this->callAPISuccess('Contact', 'get', [
- 'sequential' => 1,
- 'id' => ['IN' => [$contactId1, $contactId2]],
- ]);
-
- [$sent, $activityIds] = CRM_Activity_BAO_Activity::sendEmail(
- $contacts['values'],
- 'a subject',
- 'here is some text',
- '<p>here is some html</p>',
- $contacts['values'][0]['email'],
- $loggedInUser,
- $from = __FUNCTION__ . '@example.com',
- $attachments = NULL,
- $cc = NULL,
- $bcc = NULL,
- array_column($contacts['values'], 'id')
- );
-
- // Get all activities for these contacts
- $result = $this->callAPISuccess('activity', 'get', [
- 'sequential' => 1,
- 'return' => ['target_contact_id'],
- 'target_contact_id' => ['IN' => [$contactId1, $contactId2]],
- ]);
-
- // There should be one activity created for each of the two contacts
- $this->assertEquals(2, $result['count']);
-
- // Activity ids returned from sendEmail should match the ones returned from api call.
- $this->assertEquals($activityIds, array_column($result['values'], 'id'));
-
- // Is it the right contacts?
- $this->assertEquals(
- [0 => [0 => $contactId1], 1 => [0 => $contactId2]],
- array_column($result['values'], 'target_contact_id')
- );
- $this->assertEquals(
- [0 => [$contactId1 => 'Bbbb, Aaaa'], 1 => [$contactId2 => 'Dddd, Cccc']],
- array_column($result['values'], 'target_contact_sort_name')
- );
- }
-
/**
* @param $activityId
*