Skip to content

Commit

Permalink
Post Create Filters
Browse files Browse the repository at this point in the history
This commit controls when we run certain types of filters. If we are sending out an email, we want those filter actions to run after the ticket is created in case template variables are used. All other types of filter actions can run before the ticket is created.
  • Loading branch information
aydreeihn committed Feb 19, 2020
1 parent ef517df commit 9a58b01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 9 additions & 3 deletions include/class.filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,14 @@ function getActions() {
* If the matches() method returns TRUE, send the initial ticket to this
* method to apply the filter actions defined
*/
function apply(&$ticket, $vars) {
function apply(&$ticket, $vars, $postCreate=false) {
foreach ($this->getActions() as $a) {
//control when certain actions should be applied
//if action is send email and postCreate == false, skip
//if action is not send email and postCreate == true, skip
if ((($a->type == 'email') ? !$postCreate : $postCreate))
continue;

$a->setFilter($this);
$a->apply($ticket, $vars);
}
Expand Down Expand Up @@ -759,9 +765,9 @@ function getMatchingFilterList() {
* should be rejected, the first filter that matches and has reject
* ticket set is returned.
*/
function apply(&$ticket) {
function apply(&$ticket, $postCreate=false) {
foreach ($this->getMatchingFilterList() as $filter) {
$filter->apply($ticket, $this->vars);
$filter->apply($ticket, $this->vars, $postCreate);
if ($filter->stopOnMatch()) break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions include/class.ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3454,7 +3454,7 @@ function getUserStats($user) {
return db_fetch_array(db_query($sql));
}

protected function filterTicketData($origin, $vars, $forms, $user=false) {
protected function filterTicketData($origin, $vars, $forms, $user=false, $postCreate=false) {
global $cfg;

// Unset all the filter data field data in case things change
Expand Down Expand Up @@ -3512,7 +3512,7 @@ protected function filterTicketData($origin, $vars, $forms, $user=false) {

// Init ticket filters...
$ticket_filter = new TicketFilter($origin, $vars);
$ticket_filter->apply($vars);
$ticket_filter->apply($vars, $postCreate);
}
catch (FilterDataChanged $ex) {
// Don't pass user recursively, assume the user has changed
Expand Down Expand Up @@ -3650,7 +3650,7 @@ static function create($vars, &$errors, $origin, $autorespond=true,

try {
$vars = self::filterTicketData($origin, $vars,
array_merge(array($form), $topic_forms), $user);
array_merge(array($form), $topic_forms), $user, false);
}
catch (RejectedException $ex) {
return $reject_ticket(
Expand Down Expand Up @@ -3853,7 +3853,7 @@ static function create($vars, &$errors, $origin, $autorespond=true,
/* -------------------- POST CREATE ------------------------ */
$vars['ticket'] = $ticket;
self::filterTicketData($origin, $vars,
array_merge(array($form), $topic_forms), $user);
array_merge(array($form), $topic_forms), $user, true);

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

0 comments on commit 9a58b01

Please sign in to comment.