Core UI updates for helpdesk

This commit is contained in:
Mark Gregory
2026-06-16 09:35:24 +01:00
parent dc86970b20
commit 6c5e2af806
7 changed files with 366 additions and 36 deletions
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Ensure existing tickets have one concrete Kanban board assignment.
*/
public function up(): void
{
if (! Schema::hasTable('helpdesk_tickets') || ! Schema::hasColumn('helpdesk_tickets', 'board_id')) {
return;
}
if (! Schema::hasTable('helpdesk_kanban_boards')) {
return;
}
$defaultBoardId = DB::table('helpdesk_kanban_boards')
->where('is_default', true)
->orderBy('sort_order')
->value('id') ?: DB::table('helpdesk_kanban_boards')->orderBy('sort_order')->value('id');
if ($defaultBoardId === null) {
return;
}
DB::table('helpdesk_tickets')
->whereNull('board_id')
->update([
'board_id' => $defaultBoardId,
'updated_at' => now(),
]);
DB::table('helpdesk_tickets')
->whereNotNull('board_id')
->whereNotExists(function ($query): void {
$query->selectRaw('1')
->from('helpdesk_kanban_boards')
->whereColumn('helpdesk_kanban_boards.id', 'helpdesk_tickets.board_id');
})
->update([
'board_id' => $defaultBoardId,
'updated_at' => now(),
]);
}
/**
* This data repair is intentionally not reversed.
*/
public function down(): void
{
// No-op: do not remove repaired board ownership from existing tickets.
}
};
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Backfill status columns for every Kanban board that currently has no columns.
*/
public function up(): void
{
if (! Schema::hasTable('helpdesk_kanban_boards')
|| ! Schema::hasTable('helpdesk_kanban_board_statuses')
|| ! Schema::hasTable('helpdesk_statuses')) {
return;
}
$statuses = DB::table('helpdesk_statuses')
->orderBy('sort_order')
->orderBy('name')
->get(['id']);
if ($statuses->isEmpty()) {
return;
}
$boards = DB::table('helpdesk_kanban_boards')
->orderBy('sort_order')
->orderBy('name')
->get(['id']);
foreach ($boards as $board) {
$hasColumns = DB::table('helpdesk_kanban_board_statuses')
->where('board_id', $board->id)
->exists();
if ($hasColumns) {
continue;
}
foreach ($statuses as $index => $status) {
DB::table('helpdesk_kanban_board_statuses')->updateOrInsert(
['board_id' => $board->id, 'status_id' => $status->id],
[
'sort_order' => ($index + 1) * 10,
'created_at' => now(),
'updated_at' => now(),
]
);
}
}
}
/**
* The migration only repairs missing board columns and is intentionally not destructive.
*/
public function down(): void
{
// No-op. Do not remove configured board columns.
}
};