new deployer command
This commit is contained in:
@@ -29,6 +29,27 @@ final class AutomationRuleService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->applyRuleUpdates($rule, $ticket);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $ticket->fresh() ?? $ticket;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matches(AutomationRule $rule, Ticket $ticket, string $sender, string $mailbox): bool
|
||||||
|
{
|
||||||
|
return $this->containsWhenConfigured($sender, $rule->match_sender)
|
||||||
|
&& $this->containsWhenConfigured($ticket->subject, $rule->match_subject)
|
||||||
|
&& $this->containsWhenConfigured($mailbox, $rule->match_mailbox)
|
||||||
|
&& (! $rule->match_category_id || (int) $ticket->category_id === (int) $rule->match_category_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function containsWhenConfigured(string $value, ?string $match): bool
|
||||||
|
{
|
||||||
|
return ! $match || Str::contains(Str::lower($value), Str::lower($match));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function applyRuleUpdates(AutomationRule $rule, Ticket $ticket): void
|
||||||
|
{
|
||||||
$updates = array_filter([
|
$updates = array_filter([
|
||||||
'priority_id' => $rule->set_priority_id,
|
'priority_id' => $rule->set_priority_id,
|
||||||
'category_id' => $rule->set_category_id,
|
'category_id' => $rule->set_category_id,
|
||||||
@@ -41,26 +62,5 @@ final class AutomationRuleService
|
|||||||
if ($updates !== []) {
|
if ($updates !== []) {
|
||||||
$ticket->forceFill($updates + ['last_activity_at' => now()])->save();
|
$ticket->forceFill($updates + ['last_activity_at' => now()])->save();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return $ticket->fresh() ?? $ticket;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function matches(AutomationRule $rule, Ticket $ticket, string $sender, string $mailbox): bool
|
|
||||||
{
|
|
||||||
if ($rule->match_sender && ! Str::contains(Str::lower($sender), Str::lower($rule->match_sender))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($rule->match_subject && ! Str::contains(Str::lower($ticket->subject), Str::lower($rule->match_subject))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($rule->match_mailbox && ! Str::contains(Str::lower($mailbox), Str::lower($rule->match_mailbox))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($rule->match_category_id && (int) $ticket->category_id !== (int) $rule->match_category_id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user