M3 Integration fixes
This commit is contained in:
Regular → Executable
+10
-10
@@ -34,7 +34,7 @@ final class WorkflowNotificationService
|
||||
$recipient = $this->recipient($template->to_role, $ticket, $actor);
|
||||
|
||||
if ($recipient === null || blank($recipient->email ?? null)) {
|
||||
$this->log($template, $ticket, $event, null, 'skipped', 'No recipient email was available.');
|
||||
$this->log($template, $ticket, $event, ['recipient' => null, 'status' => 'skipped', 'error' => 'No recipient email was available.']);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -42,7 +42,6 @@ final class WorkflowNotificationService
|
||||
$trackingToken = Str::random(48);
|
||||
$subject = $this->renderText($template->subject, $ticket, $actor);
|
||||
$html = $this->wrapHtml($this->renderText($template->html_body, $ticket, $actor), $ticket, $trackingToken);
|
||||
$text = $this->renderText($template->text_body ?: strip_tags($template->html_body), $ticket, $actor);
|
||||
|
||||
try {
|
||||
Mail::html($html, function ($message) use ($recipient, $template, $subject): void {
|
||||
@@ -57,10 +56,10 @@ final class WorkflowNotificationService
|
||||
}
|
||||
});
|
||||
|
||||
$this->log($template, $ticket, $event, (string) $recipient->email, 'sent', null, $subject, $trackingToken);
|
||||
$this->log($template, $ticket, $event, ['recipient' => (string) $recipient->email, 'status' => 'sent', 'subject' => $subject, 'tracking_token' => $trackingToken]);
|
||||
} catch (Throwable $exception) {
|
||||
Log::warning('Helpdesk workflow email failed.', ['event' => $event, 'ticket_id' => $ticket->id, 'error' => $exception->getMessage()]);
|
||||
$this->log($template, $ticket, $event, (string) $recipient->email, 'failed', $exception->getMessage(), $subject);
|
||||
$this->log($template, $ticket, $event, ['recipient' => (string) $recipient->email, 'status' => 'failed', 'error' => $exception->getMessage(), 'subject' => $subject]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -158,17 +157,18 @@ final class WorkflowNotificationService
|
||||
return '<img src="' . e($url) . '" width="1" height="1" alt="" style="display:none" />';
|
||||
}
|
||||
|
||||
private function log(WorkflowTemplate $template, Ticket $ticket, string $event, ?string $recipient, string $status, ?string $error = null, ?string $subject = null, ?string $trackingToken = null): void
|
||||
/** @param array{recipient:?string,status:string,error?:?string,subject?:?string,tracking_token?:?string} $details */
|
||||
private function log(WorkflowTemplate $template, Ticket $ticket, string $event, array $details): void
|
||||
{
|
||||
WorkflowLog::query()->create([
|
||||
'template_id' => $template->id,
|
||||
'ticket_id' => $ticket->id,
|
||||
'event' => $event,
|
||||
'recipient' => $recipient,
|
||||
'subject' => $subject,
|
||||
'status' => $status,
|
||||
'tracking_token' => $trackingToken,
|
||||
'error' => $error,
|
||||
'recipient' => $details['recipient'],
|
||||
'subject' => $details['subject'] ?? null,
|
||||
'status' => $details['status'],
|
||||
'tracking_token' => $details['tracking_token'] ?? null,
|
||||
'error' => $details['error'] ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user