From 225de8725f9b400ad7790984da9a9ec3825009eb Mon Sep 17 00:00:00 2001 From: Roardom Date: Mon, 17 Feb 2025 08:22:54 +0000 Subject: [PATCH] fix: migrate ticket read statuses to booleans They were previously nullable tiny ints, but they are only used as booleans. There are no other cases where tiny ints are used as booleans and are missing the `(1)` display width. --- .../Controllers/TicketAssigneeController.php | 2 +- app/Http/Controllers/TicketController.php | 4 +-- app/Http/Livewire/Comment.php | 2 ++ app/Models/Ticket.php | 8 +++-- ...e_read_column_tickets_table_to_boolean.php | 32 +++++++++++++++++++ .../views/livewire/ticket-search.blade.php | 4 +-- 6 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2025_02_17_074140_update_read_column_tickets_table_to_boolean.php diff --git a/app/Http/Controllers/TicketAssigneeController.php b/app/Http/Controllers/TicketAssigneeController.php index 3aa4938545..d6e9c5a5be 100644 --- a/app/Http/Controllers/TicketAssigneeController.php +++ b/app/Http/Controllers/TicketAssigneeController.php @@ -28,7 +28,7 @@ final public function store(StoreTicketAssigneeRequest $request, Ticket $ticket) $ticket->update([ 'staff_id' => $request->staff_id, - 'staff_read' => 0, + 'staff_read' => false, ]); return to_route('tickets.show', ['ticket' => $ticket]) diff --git a/app/Http/Controllers/TicketController.php b/app/Http/Controllers/TicketController.php index ce514cf5be..401832591a 100644 --- a/app/Http/Controllers/TicketController.php +++ b/app/Http/Controllers/TicketController.php @@ -66,11 +66,11 @@ final public function show(Request $request, Ticket $ticket): \Illuminate\Contra abort_unless($request->user()->group->is_modo || $request->user()->id === $ticket->user_id, 403); if ($request->user()->id === $ticket->user_id) { - $ticket->user_read = 1; + $ticket->user_read = true; } if ($request->user()->id === $ticket->staff_id) { - $ticket->staff_read = 1; + $ticket->staff_read = true; } $ticket->save(); diff --git a/app/Http/Livewire/Comment.php b/app/Http/Livewire/Comment.php index 7294fe81fa..e0325fbb3e 100644 --- a/app/Http/Livewire/Comment.php +++ b/app/Http/Livewire/Comment.php @@ -157,10 +157,12 @@ final public function postReply(): void if ($this->user->id !== $ticket->staff_id && $ticket->staff_id !== null) { User::find($ticket->staff_id)->notify(new NewComment($this->model, $reply)); + $this->model->update(['staff_read' => false]); } if ($this->user->id !== $ticket->user_id) { User::find($ticket->user_id)->notify(new NewComment($this->model, $reply)); + $this->model->update(['user_read' => false]); } if (!\in_array($this->comment->user_id, [$ticket->staff_id, $ticket->user_id, $this->user->id])) { diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index b31a5a823a..aa78d22ff3 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -29,8 +29,8 @@ * @property int $category_id * @property int $priority_id * @property int|null $staff_id - * @property int|null $user_read - * @property int|null $staff_read + * @property bool $user_read + * @property bool $staff_read * @property string $subject * @property string $body * @property \Illuminate\Support\Carbon|null $closed_at @@ -51,11 +51,13 @@ class Ticket extends Model /** * Get the attributes that should be cast. * - * @return array{closed_at: 'datetime', reminded_at: 'datetime'} + * @return array{user_read: 'bool', staff_read: 'bool', closed_at: 'datetime', reminded_at: 'datetime'} */ protected function casts(): array { return [ + 'user_read' => 'bool', + 'staff_read' => 'bool', 'closed_at' => 'datetime', 'reminded_at' => 'datetime', ]; diff --git a/database/migrations/2025_02_17_074140_update_read_column_tickets_table_to_boolean.php b/database/migrations/2025_02_17_074140_update_read_column_tickets_table_to_boolean.php new file mode 100644 index 0000000000..ec92df681b --- /dev/null +++ b/database/migrations/2025_02_17_074140_update_read_column_tickets_table_to_boolean.php @@ -0,0 +1,32 @@ + + * @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 + */ + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class () extends Migration { + /** + * Run the migrations. + */ + public function up(): void + { + Schema::table('tickets', function (Blueprint $table): void { + $table->boolean('user_read')->default(false)->change(); + $table->boolean('staff_read')->default(false)->change(); + }); + } +}; diff --git a/resources/views/livewire/ticket-search.blade.php b/resources/views/livewire/ticket-search.blade.php index 85043ecfad..f618aa6e67 100644 --- a/resources/views/livewire/ticket-search.blade.php +++ b/resources/views/livewire/ticket-search.blade.php @@ -116,9 +116,9 @@ class="panel__tab panel__tab--full-width" {{ $ticket->subject }} @if ((auth()->user()->group->is_modo && - (($ticket->staff_id === auth()->id() && $ticket->staff_read === 0) || + (($ticket->staff_id === auth()->id() && $ticket->staff_read === false) || ($ticket->staff_id === null && $ticket->closed_at === null))) || - ($ticket->user_id === auth()->id() && $ticket->user_read === 0)) + ($ticket->user_id === auth()->id() && $ticket->user_read === false))