Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove guts of civicrm Mailing.preview #29171

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,7 @@ public function compose(
* @param CRM_Mailing_BAO_Mailing $mailing
*/
public static function tokenReplace(&$mailing) {
CRM_Core_Error::deprecatedWarning('function no longer called, use flexmailer');
$domain = CRM_Core_BAO_Domain::getDomain();

foreach (['text', 'html'] as $type) {
Expand Down Expand Up @@ -2475,7 +2476,7 @@ public static function delJob($id) {
*/
public function getReturnProperties() {
$tokens = &$this->getTokens();

CRM_Core_Error::deprecatedWarning('function no longer called - use flexmailer');
$properties = [];
if (isset($tokens['html']) &&
isset($tokens['html']['contact'])
Expand Down
1 change: 1 addition & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ public static function getAnonymousTokenDetails($contactIDs = [0],
$className = NULL,
$jobID = NULL) {
$details = [0 => []];
CRM_Core_Error::deprecatedFunctionWarning('function no longer used - see flexmailer');
// also call a hook and get token details
CRM_Utils_Hook::tokenValues($details[0],
$contactIDs,
Expand Down
52 changes: 1 addition & 51 deletions api/v3/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,60 +501,10 @@ function civicrm_api3_mailing_event_open($params) {
* @param array $params
* Array per getfields metadata.
*
* @return array
* @throws \CRM_Core_Exception
*/
function civicrm_api3_mailing_preview($params) {
$fromEmail = NULL;
if (!empty($params['from_email'])) {
$fromEmail = $params['from_email'];
}

$mailing = new CRM_Mailing_BAO_Mailing();
$mailingID = $params['id'] ?? NULL;
if ($mailingID) {
$mailing->id = $mailingID;
$mailing->find(TRUE);
}
else {
$mailing->copyValues($params);
}

$session = CRM_Core_Session::singleton();

CRM_Mailing_BAO_Mailing::tokenReplace($mailing);

// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);

$returnProperties = $mailing->getReturnProperties();
$contactID = $params['contact_id'] ?? NULL;
if (!$contactID) {
// If we still don't have a userID in a session because we are annon then set contactID to be 0
$contactID = empty($session->get('userID')) ? 0 : $session->get('userID');
}
$mailingParams = ['contact_id' => $contactID];

if (!$contactID) {
$details = CRM_Utils_Token::getAnonymousTokenDetails($mailingParams, $returnProperties, empty($mailing->sms_provider_id), TRUE, NULL, $mailing->getFlattenedTokens());
$details = $details[0][0] ?? NULL;
}
else {
[$details] = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, empty($mailing->sms_provider_id), TRUE, NULL, $mailing->getFlattenedTokens());
$details = $details[$contactID];
}

$mime = $mailing->compose(NULL, NULL, NULL, $contactID, $fromEmail, $fromEmail,
TRUE, $details, $attachments
);

return civicrm_api3_create_success([
'id' => $mailingID,
'contact_id' => $contactID,
'subject' => CRM_Utils_Array::value('Subject', $mime->headers(), ''),
'body_html' => $mime->getHTMLBody(),
'body_text' => $mime->getTXTBody(),
]);
throw new CRM_Core_Exception('This is never called because flexmailer intercepts it');
}

/**
Expand Down
6 changes: 0 additions & 6 deletions ext/flexmailer/src/API/MailingPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use Civi\FlexMailer\FlexMailer;
use Civi\FlexMailer\FlexMailerTask;
use Civi\FlexMailer\Listener\Abdicator;

class MailingPreview {

Expand Down Expand Up @@ -33,11 +32,6 @@ public static function preview($apiRequest) {
$mailing->copyValues($params);
}

if (!Abdicator::isFlexmailPreferred($mailing) && empty($mailing->sms_provider_id)) {
require_once 'api/v3/Mailing.php';
return civicrm_api3_mailing_preview($params);
}

$contactID = \CRM_Utils_Array::value('contact_id', $params,
\CRM_Core_Session::singleton()->get('userID'));

Expand Down