major updates

This commit is contained in:
Mark Gregory
2026-06-17 11:26:08 +01:00
parent 3b1fc48a3d
commit c4646d2f5c
10 changed files with 256 additions and 51 deletions
+11 -5
View File
@@ -102,9 +102,9 @@ final class TicketService
*
* @param array<int, UploadedFile> $files
*/
public function comment(Ticket $ticket, User $user, string $body, bool $internal = false, array $files = [], ?int $parentId = null): Comment
public function comment(Ticket $ticket, User $user, string $body, bool $internal = false, array $files = [], ?int $parentId = null, ?string $subject = null): Comment
{
return DB::transaction(function () use ($ticket, $user, $body, $internal, $files, $parentId): Comment {
return DB::transaction(function () use ($ticket, $user, $body, $internal, $files, $parentId, $subject): Comment {
$parent = $parentId === null
? null
: Comment::query()
@@ -117,8 +117,7 @@ final class TicketService
$rootUnid = $parent?->root_unid ?: $parentUnid ?: $unid;
$plainTextBody = trim(preg_replace('/\s+/', ' ', strip_tags($body)) ?: '');
/** @var Comment $comment */
$comment = $ticket->comments()->create([
$payload = [
'parent_id' => $parentId,
'user_id' => $user->id,
'body' => $body,
@@ -132,7 +131,14 @@ final class TicketService
'sync_sequence' => 1,
'sync_hash' => hash('sha256', $body),
'source_system' => 'wms-helpdesk',
]);
];
if (Schema::hasColumn('helpdesk_comments', 'subject')) {
$payload['subject'] = trim((string) ($subject ?: ($parentId === null ? 'Response' : 'RE: Response')));
}
/** @var Comment $comment */
$comment = $ticket->comments()->create($payload);
$ticket->forceFill(['last_activity_at' => now()])->save();
if (! $internal) {