From ccc4ed596addbd7df18a4f556825a23f749365e8 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Thu, 20 Nov 2025 17:04:08 +0100 Subject: [PATCH] fix: reorder tickets priority when one is archived --- app/Models/Ticket.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index 7286312..b96617b 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -63,8 +63,8 @@ class Ticket extends Model protected static function booted() { static::creating(function (Ticket $ticket) { - // If bug force the ticket status on new. All the others are estimateTodo. self::setOrder($ticket); + // If bug force the ticket status on new. All the others are estimateTodo. if ($ticket->type->equals(TicketTypeEnum::bug)) { $ticket->status = TicketStatusEnum::new; } else { @@ -108,9 +108,18 @@ class Ticket extends Model */ private static function setOrder(self $model, bool $isArchived = false): void { - $model->order = \intval( - self::query()->where('status', $isArchived ? '=' : '!=', TicketStatusEnum::archived)->max('order') - ) + 1; + $maxOrder = \intval(self::query()->where('status', '!=', TicketStatusEnum::archived)->max('order')); + if ($isArchived) { + $request = Ticket::query() + ->where('site_id', $model->site_id) + ->whereNot('status', TicketStatusEnum::archived) + ->whereNot('id', $model->id) + ->whereBetween('order', [$model->order, $maxOrder]); + $request->decrement('order', 1); + $model->order = 0; + return; + } + $model->order = $maxOrder + 1; }