Skip to content

Commit

Permalink
Issue: Template Variables in Ticket Filter
Browse files Browse the repository at this point in the history
This commit fixes an issue where you could not use template variables when using the 'Send an Email' filter action. All variables would just display as 'Array'.

We needed to pass the Ticket object to FA_SendEmail::apply however, we were running the filters before the Ticket object was created. To fix this, we can add the Ticket object to vars and run the filterTicketData function again after the Ticket is created and only apply the send email filter action if the Ticket object is found.
  • Loading branch information
aydreeihn committed Feb 3, 2020
1 parent 7578d5c commit ef517df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions include/class.filter_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,18 @@ class FA_SendEmail extends TriggerAction {
function apply(&$ticket, array $info) {
global $ost;

if (!$ticket['ticket'])
return false;

$config = $this->getConfiguration();
$info = array('subject' => $config['subject'],
'message' => $config['message']);
$info = $ost->replaceTemplateVariables(
$info, array('ticket' => $ticket)
$vars = array(
'url' => $ost->getConfig()->getBaseUrl(),
'ticket' => $ticket['ticket'],
);
$info = $ost->replaceTemplateVariables(array(
'subject' => $config['subject'],
'message' => $config['message'],
), $vars);

// Honor FROM address settings
if (!$config['from'] || !($mailer = Email::lookup($config['from'])))
Expand Down Expand Up @@ -549,7 +555,6 @@ function apply(&$ticket, array $info) {
$I = $replacer->replaceVars($info);
$mailer->send($recipient, $I['subject'], $I['message']);
}

}

static function getVarScope() {
Expand Down
3 changes: 3 additions & 0 deletions include/class.ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3851,6 +3851,9 @@ static function create($vars, &$errors, $origin, $autorespond=true,
return null;

/* -------------------- POST CREATE ------------------------ */
$vars['ticket'] = $ticket;
self::filterTicketData($origin, $vars,
array_merge(array($form), $topic_forms), $user);

// Save the (common) dynamic form
// Ensure we have a subject
Expand Down

0 comments on commit ef517df

Please sign in to comment.