Skip to content

Commit

Permalink
Merge pull request #11316 from totten/master-flex-token
Browse files Browse the repository at this point in the history
CRM-21472 - Allow FlexMailer to take over token validation
  • Loading branch information
eileenmcnaughton authored Nov 28, 2017
2 parents 1f54552 + dfbda5e commit 4103cb7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
15 changes: 14 additions & 1 deletion CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,12 @@ public function &getDataFunc($token) {
}

/**
*
* Prepares the text and html templates
* for generating the emails and returns a copy of the
* prepared templates
*
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer/TokenProcessor.
*/
private function getPreparedTemplates() {
if (!$this->preparedTemplates) {
Expand Down Expand Up @@ -1166,6 +1168,8 @@ public function getVerpAndUrlsAndHeaders($job_id, $event_queue_id, $hash, $email
/**
* Compose a message.
*
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer/TokenProcessor.
* @param int $job_id
* ID of the Job associated with this message.
* @param int $event_queue_id
Expand Down Expand Up @@ -1434,6 +1438,8 @@ public function compose(
*
* Get mailing object and replaces subscribeInvite, domain and mailing tokens.
*
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer/TokenProcessor.
* @param CRM_Mailing_BAO_Mailing $mailing
*/
public static function tokenReplace(&$mailing) {
Expand All @@ -1457,6 +1463,9 @@ public static function tokenReplace(&$mailing) {
/**
* Get data to resolve tokens.
*
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer/TokenProcessor.
*
* @param array $token_a
* @param bool $html
* Whether to encode the token result for use in HTML email
Expand Down Expand Up @@ -1808,6 +1817,8 @@ public static function create(&$params, $ids = array()) {
}

/**
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer.
* @param CRM_Mailing_DAO_Mailing $mailing
* The mailing which may or may not be sendable.
* @return array
Expand Down Expand Up @@ -2672,6 +2683,8 @@ public static function delJob($id) {
}

/**
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer/TokenProcessor.
* @return array
*/
public function getReturnProperties() {
Expand Down
5 changes: 5 additions & 0 deletions CRM/Mailing/BAO/MailingJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,13 @@ public function queue($testParams = NULL) {
/**
* Send the mailing.
*
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer.
* @param object $mailer
* A Mail object to send the messages.
*
* @param array $testParams
* @return bool
*/
public function deliver(&$mailer, $testParams = NULL) {
if (\Civi::settings()->get('experimentalFlexMailerEngine')) {
Expand Down Expand Up @@ -583,6 +586,8 @@ public function deliver(&$mailer, $testParams = NULL) {
}

/**
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer.
* @param array $fields
* List of intended recipients.
* Each recipient is an array with keys 'hash', 'contact_id', 'email', etc.
Expand Down
4 changes: 3 additions & 1 deletion CRM/Mailing/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public function getAngularModules() {
));
$enabledLanguages = CRM_Core_I18n::languages(TRUE);
$isMultiLingual = (count($enabledLanguages) > 1);
// FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
$requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS, array()) : CRM_Utils_Token::getRequiredTokens();
CRM_Core_Resources::singleton()
->addSetting(array(
'crmMailing' => array(
Expand All @@ -143,7 +145,7 @@ public function getAngularModules() {
'emailAdd' => $emailAdd['values'],
'mailTokens' => $mailTokens['values'],
'contactid' => $contactID,
'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
'requiredTokens' => $requiredTokens,
'enableReplyTo' => (int) Civi::settings()->get('replyTo'),
'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'),
'fromAddress' => $fromAddress['values'],
Expand Down
5 changes: 4 additions & 1 deletion CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class CRM_Utils_Token {


/**
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer.
* @return array
*/
public static function getRequiredTokens() {
Expand Down Expand Up @@ -118,7 +120,8 @@ public static function getRequiredTokens() {
* else an array of the missing tokens
*/
public static function requiredTokens(&$str) {
$requiredTokens = self::getRequiredTokens();
// FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
$requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS, array()) : CRM_Utils_Token::getRequiredTokens();

$missing = array();
foreach ($requiredTokens as $token => $value) {
Expand Down
4 changes: 3 additions & 1 deletion api/v3/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ function civicrm_api3_mailing_create($params) {
if (!$timestampCheck) {
throw new API_Exception("Mailing has not been saved, Content maybe out of date, please refresh the page and try again");
}
$safeParams['_evil_bao_validator_'] = 'CRM_Mailing_BAO_Mailing::checkSendable';

// FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
$safeParams['_evil_bao_validator_'] = \CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_SENDABLE', 'CRM_Mailing_BAO_Mailing::checkSendable');
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $safeParams);
return _civicrm_api3_mailing_get_formatResult($result);
}
Expand Down

0 comments on commit 4103cb7

Please sign in to comment.