Repo rebuild
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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('users', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('users', 'helpdesk_agent')) {
|
||||
$table->boolean('helpdesk_agent')->default(false)->after('password');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('users', 'helpdesk_admin')) {
|
||||
$table->boolean('helpdesk_admin')->default(false)->after('helpdesk_agent');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('helpdesk_statuses', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name', 80);
|
||||
$table->string('slug', 100)->unique();
|
||||
$table->string('color', 30)->default('zinc');
|
||||
$table->unsignedSmallInteger('sort_order')->default(0);
|
||||
$table->boolean('is_closed')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_priorities', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name', 80);
|
||||
$table->string('slug', 100)->unique();
|
||||
$table->string('color', 30)->default('zinc');
|
||||
$table->unsignedSmallInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_categories', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->string('name', 120);
|
||||
$table->string('slug', 140);
|
||||
$table->string('color', 30)->default('blue');
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['company_id', 'slug']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_teams', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->string('name', 120);
|
||||
$table->string('slug', 140);
|
||||
$table->string('color', 30)->default('indigo');
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamp('archived_at')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['company_id', 'slug']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_projects', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
|
||||
$table->string('title', 160);
|
||||
$table->string('slug', 180);
|
||||
$table->string('color', 30)->default('blue');
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamp('archived_at')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['company_id', 'slug']);
|
||||
});
|
||||
}
|
||||
};
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('helpdesk_tickets', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('reference', 32)->unique();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->foreignId('agent_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->foreignId('status_id')->constrained('helpdesk_statuses')->restrictOnDelete();
|
||||
$table->foreignId('priority_id')->constrained('helpdesk_priorities')->restrictOnDelete();
|
||||
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
|
||||
$table->foreignId('project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
|
||||
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
|
||||
$table->string('subject', 200);
|
||||
$table->longText('body');
|
||||
$table->timestamp('due_at')->nullable();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->timestamp('last_activity_at')->nullable();
|
||||
$table->timestamp('archived_at')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['company_id', 'project_id']);
|
||||
$table->index(['team_id', 'status_id']);
|
||||
$table->index(['status_id', 'priority_id']);
|
||||
$table->index(['agent_id', 'completed_at']);
|
||||
$table->index(['user_id', 'created_at']);
|
||||
$table->index('last_activity_at');
|
||||
});
|
||||
}
|
||||
};
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('helpdesk_git_repositories', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->foreignId('project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
|
||||
$table->string('name', 160);
|
||||
$table->string('provider', 40)->default('git');
|
||||
$table->string('remote_url', 500);
|
||||
$table->string('default_branch', 120)->default('main');
|
||||
$table->string('webhook_secret', 120)->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['company_id', 'project_id']);
|
||||
$table->index(['provider', 'is_active']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_git_commits', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('repository_id')->constrained('helpdesk_git_repositories')->cascadeOnDelete();
|
||||
$table->foreignId('ticket_id')->nullable()->constrained('helpdesk_tickets')->nullOnDelete();
|
||||
$table->string('hash', 80);
|
||||
$table->string('short_hash', 16);
|
||||
$table->string('branch', 120)->nullable();
|
||||
$table->string('author_name', 160)->nullable();
|
||||
$table->string('author_email', 190)->nullable();
|
||||
$table->text('message');
|
||||
$table->string('url', 500)->nullable();
|
||||
$table->timestamp('committed_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['repository_id', 'hash']);
|
||||
$table->index(['ticket_id', 'committed_at']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_workflow_templates', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name', 160);
|
||||
$table->string('event', 80);
|
||||
$table->string('subject', 220);
|
||||
$table->longText('html_body');
|
||||
$table->longText('text_body')->nullable();
|
||||
$table->string('to_role', 40)->default('requester');
|
||||
$table->string('cc', 500)->nullable();
|
||||
$table->string('bcc', 500)->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['event', 'is_active']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_workflow_logs', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('template_id')->nullable()->constrained('helpdesk_workflow_templates')->nullOnDelete();
|
||||
$table->foreignId('ticket_id')->nullable()->constrained('helpdesk_tickets')->nullOnDelete();
|
||||
$table->string('event', 80);
|
||||
$table->string('recipient', 190)->nullable();
|
||||
$table->string('subject', 220)->nullable();
|
||||
$table->string('status', 40)->default('pending');
|
||||
$table->text('error')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['ticket_id', 'event']);
|
||||
$table->index(['status', 'created_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('helpdesk_comments', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('parent_id')->nullable()->constrained('helpdesk_comments')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->longText('body');
|
||||
$table->boolean('is_internal')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['ticket_id', 'parent_id', 'created_at']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_attachments', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('comment_id')->nullable()->constrained('helpdesk_comments')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('disk', 80);
|
||||
$table->string('path', 500);
|
||||
$table->string('original_name', 255);
|
||||
$table->string('mime_type', 160)->nullable();
|
||||
$table->unsignedBigInteger('size')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['ticket_id', 'comment_id', 'created_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('helpdesk_category_user', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('category_id')->constrained('helpdesk_categories')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
$table->unique(['category_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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
|
||||
{
|
||||
if (! Schema::hasTable('helpdesk_kanban_boards')) {
|
||||
Schema::create('helpdesk_kanban_boards', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('slug')->unique();
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_default')->default(false);
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['is_default', 'sort_order']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('helpdesk_kanban_boards');
|
||||
}
|
||||
};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('helpdesk_kanban_board_statuses')) {
|
||||
Schema::create('helpdesk_kanban_board_statuses', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('board_id')->constrained('helpdesk_kanban_boards')->cascadeOnDelete();
|
||||
$table->foreignId('status_id')->constrained('helpdesk_statuses')->cascadeOnDelete();
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['board_id', 'status_id']);
|
||||
$table->index(['board_id', 'sort_order']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('helpdesk_kanban_board_statuses');
|
||||
}
|
||||
};
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('helpdesk_products', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->string('name', 160);
|
||||
$table->string('slug', 180);
|
||||
$table->string('type', 60)->default('service');
|
||||
$table->string('version', 80)->nullable();
|
||||
$table->string('release_channel', 80)->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
$table->unique(['company_id', 'slug']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_sla_policies', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->foreignId('priority_id')->nullable()->constrained('helpdesk_priorities')->nullOnDelete();
|
||||
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
|
||||
$table->string('name', 160);
|
||||
$table->string('slug', 180);
|
||||
$table->unsignedInteger('first_response_minutes')->default(240);
|
||||
$table->unsignedInteger('resolution_minutes')->default(2880);
|
||||
$table->boolean('business_hours_only')->default(false);
|
||||
$table->boolean('is_default')->default(false);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
$table->unique(['company_id', 'slug']);
|
||||
$table->index(['priority_id', 'category_id', 'is_active']);
|
||||
});
|
||||
|
||||
Schema::table('helpdesk_tickets', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'sla_policy_id')) {
|
||||
$table->foreignId('sla_policy_id')->nullable()->after('team_id')->constrained('helpdesk_sla_policies')->nullOnDelete();
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'product_id')) {
|
||||
$table->foreignId('product_id')->nullable()->after('project_id')->constrained('helpdesk_products')->nullOnDelete();
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'first_response_at')) {
|
||||
$table->timestamp('first_response_at')->nullable()->after('due_at');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'sla_first_response_due_at')) {
|
||||
$table->timestamp('sla_first_response_due_at')->nullable()->after('first_response_at');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'sla_resolution_due_at')) {
|
||||
$table->timestamp('sla_resolution_due_at')->nullable()->after('sla_first_response_due_at');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'sla_first_response_breached_at')) {
|
||||
$table->timestamp('sla_first_response_breached_at')->nullable()->after('sla_resolution_due_at');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'sla_resolution_breached_at')) {
|
||||
$table->timestamp('sla_resolution_breached_at')->nullable()->after('sla_first_response_breached_at');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'public_replies_count')) {
|
||||
$table->unsignedInteger('public_replies_count')->default(0)->after('sla_resolution_breached_at');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_tickets', 'time_spent_minutes')) {
|
||||
$table->unsignedInteger('time_spent_minutes')->default(0)->after('public_replies_count');
|
||||
}
|
||||
|
||||
$table->index(['sla_policy_id', 'sla_resolution_due_at'], 'helpdesk_tickets_sla_policy_due_idx');
|
||||
$table->index(['product_id', 'completed_at'], 'helpdesk_tickets_product_closed_idx');
|
||||
});
|
||||
|
||||
Schema::table('helpdesk_workflow_logs', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_workflow_logs', 'tracking_token')) {
|
||||
$table->string('tracking_token', 64)->nullable()->unique()->after('status');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_workflow_logs', 'first_opened_at')) {
|
||||
$table->timestamp('first_opened_at')->nullable()->after('tracking_token');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_workflow_logs', 'last_opened_at')) {
|
||||
$table->timestamp('last_opened_at')->nullable()->after('first_opened_at');
|
||||
}
|
||||
if (! Schema::hasColumn('helpdesk_workflow_logs', 'opened_count')) {
|
||||
$table->unsignedInteger('opened_count')->default(0)->after('last_opened_at');
|
||||
}
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_canned_responses', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
|
||||
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
|
||||
$table->string('name', 160);
|
||||
$table->string('slug', 180);
|
||||
$table->string('visibility', 40)->default('agents');
|
||||
$table->string('subject', 220)->nullable();
|
||||
$table->longText('body');
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
$table->unique(['company_id', 'slug']);
|
||||
$table->index(['category_id', 'team_id', 'is_active']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_automation_rules', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->string('name', 160);
|
||||
$table->string('slug', 180);
|
||||
$table->string('match_sender', 190)->nullable();
|
||||
$table->string('match_subject', 220)->nullable();
|
||||
$table->string('match_mailbox', 190)->nullable();
|
||||
$table->foreignId('match_category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
|
||||
$table->foreignId('set_priority_id')->nullable()->constrained('helpdesk_priorities')->nullOnDelete();
|
||||
$table->foreignId('set_category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
|
||||
$table->foreignId('set_team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
|
||||
$table->foreignId('set_project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
|
||||
$table->foreignId('set_status_id')->nullable()->constrained('helpdesk_statuses')->nullOnDelete();
|
||||
$table->foreignId('set_agent_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
$table->unique(['company_id', 'slug']);
|
||||
$table->index(['is_active', 'sort_order']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_ticket_sla_events', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('sla_policy_id')->nullable()->constrained('helpdesk_sla_policies')->nullOnDelete();
|
||||
$table->string('event', 80);
|
||||
$table->timestamp('due_at')->nullable();
|
||||
$table->timestamp('occurred_at')->nullable();
|
||||
$table->boolean('breached')->default(false);
|
||||
$table->json('meta')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['ticket_id', 'event']);
|
||||
$table->index(['breached', 'due_at']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_ticket_ratings', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('agent_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
|
||||
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
|
||||
$table->unsignedTinyInteger('rating');
|
||||
$table->string('token', 80)->unique();
|
||||
$table->text('comment')->nullable();
|
||||
$table->timestamp('rated_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['agent_id', 'rating']);
|
||||
$table->index(['team_id', 'category_id']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_tags', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->string('name', 80);
|
||||
$table->string('slug', 100);
|
||||
$table->string('color', 30)->default('zinc');
|
||||
$table->timestamps();
|
||||
$table->unique(['company_id', 'slug']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_ticket_tag', static function (Blueprint $table): void {
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('tag_id')->constrained('helpdesk_tags')->cascadeOnDelete();
|
||||
$table->primary(['ticket_id', 'tag_id']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_checklist_templates', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
|
||||
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
|
||||
$table->foreignId('project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
|
||||
$table->string('name', 160);
|
||||
$table->string('slug', 180);
|
||||
$table->json('items');
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
$table->unique(['company_id', 'slug']);
|
||||
$table->index(['category_id', 'project_id', 'is_active']);
|
||||
});
|
||||
|
||||
Schema::create('helpdesk_checklist_items', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('template_id')->nullable()->constrained('helpdesk_checklist_templates')->nullOnDelete();
|
||||
$table->string('title', 220);
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_completed')->default(false);
|
||||
$table->foreignId('completed_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
$table->index(['ticket_id', 'is_completed']);
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Add auditable Git webhook ingestion support.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (Schema::hasTable('helpdesk_git_webhook_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('helpdesk_git_webhook_logs', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('repository_id')->constrained('helpdesk_git_repositories')->cascadeOnDelete();
|
||||
$table->string('provider', 40);
|
||||
$table->string('delivery_id', 190)->nullable();
|
||||
$table->string('event', 120)->nullable();
|
||||
$table->string('status', 40)->default('accepted');
|
||||
$table->string('message', 500)->nullable();
|
||||
$table->unsignedInteger('commit_count')->default(0);
|
||||
$table->unsignedInteger('linked_count')->default(0);
|
||||
$table->unsignedInteger('ignored_count')->default(0);
|
||||
$table->json('payload')->nullable();
|
||||
$table->timestamp('received_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['repository_id', 'status', 'received_at']);
|
||||
$table->index(['provider', 'event']);
|
||||
});
|
||||
}
|
||||
};
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
foreach ([
|
||||
'helpdesk_statuses',
|
||||
'helpdesk_priorities',
|
||||
'helpdesk_categories',
|
||||
'helpdesk_projects',
|
||||
'helpdesk_teams',
|
||||
] as $table) {
|
||||
if (! Schema::hasColumn($table, 'is_default')) {
|
||||
Schema::table($table, function (Blueprint $table): void {
|
||||
$table->boolean('is_default')->default(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
foreach ([
|
||||
'helpdesk_statuses',
|
||||
'helpdesk_priorities',
|
||||
'helpdesk_categories',
|
||||
'helpdesk_projects',
|
||||
'helpdesk_teams',
|
||||
] as $tableName) {
|
||||
if (Schema::hasColumn($tableName, 'is_default')) {
|
||||
Schema::table($tableName, function (Blueprint $table): void {
|
||||
$table->dropColumn('is_default');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
if (! Schema::hasColumn('companies', 'is_default_helpdesk_company')) {
|
||||
Schema::table('companies', function (Blueprint $table): void {
|
||||
$table->boolean('is_default_helpdesk_company')
|
||||
->default(false)
|
||||
->after('is_system_company');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasColumn('companies', 'is_default_helpdesk_company')) {
|
||||
Schema::table('companies', function (Blueprint $table): void {
|
||||
$table->dropColumn('is_default_helpdesk_company');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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
|
||||
{
|
||||
foreach ([
|
||||
'helpdesk_statuses',
|
||||
'helpdesk_priorities',
|
||||
'helpdesk_categories',
|
||||
'helpdesk_projects',
|
||||
'helpdesk_teams',
|
||||
] as $tableName) {
|
||||
if (Schema::hasTable($tableName) && ! Schema::hasColumn($tableName, 'is_default')) {
|
||||
Schema::table($tableName, static function (Blueprint $table): void {
|
||||
$table->boolean('is_default')->default(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
foreach ([
|
||||
'helpdesk_statuses',
|
||||
'helpdesk_priorities',
|
||||
'helpdesk_categories',
|
||||
'helpdesk_projects',
|
||||
'helpdesk_teams',
|
||||
] as $tableName) {
|
||||
if (Schema::hasTable($tableName) && Schema::hasColumn($tableName, 'is_default')) {
|
||||
Schema::table($tableName, static function (Blueprint $table): void {
|
||||
$table->dropColumn('is_default');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Add single-board ticket assignment and board ownership.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (Schema::hasTable('helpdesk_kanban_boards') && ! Schema::hasColumn('helpdesk_kanban_boards', 'owner_id')) {
|
||||
Schema::table('helpdesk_kanban_boards', static function (Blueprint $table): void {
|
||||
$table->foreignId('owner_id')
|
||||
->nullable()
|
||||
->after('description')
|
||||
->constrained('users')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->index('owner_id');
|
||||
});
|
||||
}
|
||||
|
||||
if (Schema::hasTable('helpdesk_tickets') && ! Schema::hasColumn('helpdesk_tickets', 'board_id')) {
|
||||
Schema::table('helpdesk_tickets', static function (Blueprint $table): void {
|
||||
$table->foreignId('board_id')
|
||||
->nullable()
|
||||
->after('status_id')
|
||||
->constrained('helpdesk_kanban_boards')
|
||||
->nullOnDelete();
|
||||
|
||||
$table->index(['board_id', 'status_id']);
|
||||
});
|
||||
}
|
||||
|
||||
if (Schema::hasTable('helpdesk_tickets') && Schema::hasTable('helpdesk_kanban_boards') && Schema::hasColumn('helpdesk_tickets', 'board_id')) {
|
||||
$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) {
|
||||
DB::table('helpdesk_tickets')
|
||||
->whereNull('board_id')
|
||||
->update(['board_id' => $defaultBoardId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasTable('helpdesk_tickets') && Schema::hasColumn('helpdesk_tickets', 'board_id')) {
|
||||
Schema::table('helpdesk_tickets', static function (Blueprint $table): void {
|
||||
$table->dropForeign(['board_id']);
|
||||
$table->dropIndex(['board_id', 'status_id']);
|
||||
$table->dropColumn('board_id');
|
||||
});
|
||||
}
|
||||
|
||||
if (Schema::hasTable('helpdesk_kanban_boards') && Schema::hasColumn('helpdesk_kanban_boards', 'owner_id')) {
|
||||
Schema::table('helpdesk_kanban_boards', static function (Blueprint $table): void {
|
||||
$table->dropForeign(['owner_id']);
|
||||
$table->dropIndex(['owner_id']);
|
||||
$table->dropColumn('owner_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
+60
@@ -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.
|
||||
}
|
||||
};
|
||||
+65
@@ -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.
|
||||
}
|
||||
};
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Helpdesk\Models\Comment;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'guid')) {
|
||||
$table->uuid('guid')->nullable()->after('id');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'unid')) {
|
||||
$table->string('unid', 64)->nullable()->after('guid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'replica_id')) {
|
||||
$table->string('replica_id', 64)->nullable()->after('unid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'parent_unid')) {
|
||||
$table->string('parent_unid', 64)->nullable()->after('parent_id');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'root_unid')) {
|
||||
$table->string('root_unid', 64)->nullable()->after('parent_unid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'originator_id')) {
|
||||
$table->string('originator_id', 96)->nullable()->after('root_unid');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'sync_sequence')) {
|
||||
$table->unsignedBigInteger('sync_sequence')->default(1)->after('originator_id');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'sync_hash')) {
|
||||
$table->string('sync_hash', 128)->nullable()->after('sync_sequence');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'source_system')) {
|
||||
$table->string('source_system', 80)->default('wms-helpdesk')->after('sync_hash');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'source_record_id')) {
|
||||
$table->string('source_record_id', 120)->nullable()->after('source_system');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'body_text')) {
|
||||
$table->text('body_text')->nullable()->after('body');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'replicated_at')) {
|
||||
$table->timestamp('replicated_at')->nullable()->after('updated_at');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'synced_at')) {
|
||||
$table->timestamp('synced_at')->nullable()->after('replicated_at');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'tombstoned_at')) {
|
||||
$table->timestamp('tombstoned_at')->nullable()->after('synced_at');
|
||||
}
|
||||
});
|
||||
|
||||
Comment::query()->orderBy('id')->chunkById(100, static function ($comments): void {
|
||||
foreach ($comments as $comment) {
|
||||
$guid = $comment->guid ?: (string) Str::uuid();
|
||||
$unid = $comment->unid ?: strtoupper(hash('sha256', $guid . '|' . $comment->ticket_id . '|' . $comment->id));
|
||||
$parent = $comment->parent_id ? Comment::query()->find($comment->parent_id) : null;
|
||||
$parentUnid = $parent?->unid;
|
||||
$rootUnid = $parent?->root_unid ?: $parentUnid ?: $unid;
|
||||
|
||||
DB::table('helpdesk_comments')
|
||||
->where('id', $comment->id)
|
||||
->update([
|
||||
'guid' => $guid,
|
||||
'unid' => $unid,
|
||||
'parent_unid' => $parentUnid,
|
||||
'root_unid' => $rootUnid,
|
||||
'originator_id' => $comment->originator_id ?: $unid . ':1',
|
||||
'sync_sequence' => $comment->sync_sequence ?: 1,
|
||||
'sync_hash' => hash('sha256', (string) $comment->body),
|
||||
'body_text' => trim(strip_tags((string) $comment->body)),
|
||||
'source_system' => $comment->source_system ?: 'wms-helpdesk',
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
$table->unique('guid', 'helpdesk_comments_guid_unique');
|
||||
$table->unique('unid', 'helpdesk_comments_unid_unique');
|
||||
$table->index(['ticket_id', 'root_unid', 'parent_unid'], 'helpdesk_comments_lotus_thread_index');
|
||||
$table->index(['ticket_id', 'is_internal', 'created_at'], 'helpdesk_comments_visibility_index');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
$table->dropUnique('helpdesk_comments_guid_unique');
|
||||
$table->dropUnique('helpdesk_comments_unid_unique');
|
||||
$table->dropIndex('helpdesk_comments_lotus_thread_index');
|
||||
$table->dropIndex('helpdesk_comments_visibility_index');
|
||||
|
||||
$table->dropColumn([
|
||||
'guid',
|
||||
'unid',
|
||||
'replica_id',
|
||||
'parent_unid',
|
||||
'root_unid',
|
||||
'originator_id',
|
||||
'sync_sequence',
|
||||
'sync_hash',
|
||||
'source_system',
|
||||
'source_record_id',
|
||||
'body_text',
|
||||
'replicated_at',
|
||||
'synced_at',
|
||||
'tombstoned_at',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'subject')) {
|
||||
$table->string('subject', 180)->nullable()->after('user_id');
|
||||
}
|
||||
});
|
||||
|
||||
DB::table('helpdesk_comments')
|
||||
->whereNull('subject')
|
||||
->orWhere('subject', '')
|
||||
->orderBy('id')
|
||||
->select(['id', 'parent_id', 'body', 'body_text', 'is_internal'])
|
||||
->chunkById(100, static function ($comments): void {
|
||||
foreach ($comments as $comment) {
|
||||
$plain = trim(preg_replace('/\s+/', ' ', strip_tags((string) ($comment->body_text ?: $comment->body))) ?: '');
|
||||
$subject = (bool) $comment->is_internal
|
||||
? 'Internal note'
|
||||
: ((int) ($comment->parent_id ?? 0) > 0 ? 'RE: ' : '') . Str::limit($plain !== '' ? $plain : 'Response', 120, '');
|
||||
|
||||
DB::table('helpdesk_comments')
|
||||
->where('id', $comment->id)
|
||||
->update(['subject' => $subject]);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
$table->index(['ticket_id', 'subject'], 'helpdesk_comments_ticket_subject_index');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
if (Schema::hasColumn('helpdesk_comments', 'subject')) {
|
||||
$table->dropIndex('helpdesk_comments_ticket_subject_index');
|
||||
$table->dropColumn('subject');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'tombstoned_at')) {
|
||||
$table->timestamp('tombstoned_at')->nullable()->after('synced_at');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'deleted_by')) {
|
||||
$table->foreignId('deleted_by')->nullable()->after('tombstoned_at')->constrained('users')->nullOnDelete();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_comments', 'delete_reason')) {
|
||||
$table->string('delete_reason', 255)->nullable()->after('deleted_by');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
|
||||
if (Schema::hasColumn('helpdesk_comments', 'deleted_by')) {
|
||||
$table->dropConstrainedForeignId('deleted_by');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('helpdesk_comments', 'delete_reason')) {
|
||||
$table->dropColumn('delete_reason');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Add persistent timer fields to the existing helpdesk time log table.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
foreach (['helpdesk_time_logs', 'time_logs'] as $tableName) {
|
||||
if (! Schema::hasTable($tableName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Schema::table($tableName, function (Blueprint $table) use ($tableName): void {
|
||||
if (! Schema::hasColumn($tableName, 'started_at')) {
|
||||
$table->timestamp('started_at')->nullable()->after('logged_at');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn($tableName, 'ended_at')) {
|
||||
$table->timestamp('ended_at')->nullable()->after('started_at');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn($tableName, 'duration_seconds')) {
|
||||
$table->unsignedInteger('duration_seconds')->default(0)->after('minutes');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove persistent timer fields from the existing helpdesk time log table.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
foreach (['helpdesk_time_logs', 'time_logs'] as $tableName) {
|
||||
if (! Schema::hasTable($tableName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Schema::table($tableName, function (Blueprint $table) use ($tableName): void {
|
||||
foreach (['duration_seconds', 'ended_at', 'started_at'] as $column) {
|
||||
if (Schema::hasColumn($tableName, $column)) {
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
if (Schema::hasTable('helpdesk_ticket_time_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('helpdesk_ticket_time_logs', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->timestamp('started_at');
|
||||
$table->timestamp('ended_at')->nullable();
|
||||
$table->unsignedInteger('duration_seconds')->default(0);
|
||||
$table->unsignedInteger('minutes')->default(0);
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['ticket_id', 'user_id', 'ended_at'], 'helpdesk_timer_active_idx');
|
||||
$table->index(['ticket_id', 'started_at'], 'helpdesk_timer_ticket_started_idx');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('helpdesk_ticket_time_logs');
|
||||
}
|
||||
};
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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
|
||||
{
|
||||
if (Schema::hasTable('helpdesk_time_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('helpdesk_time_logs', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->unsignedInteger('minutes');
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamp('logged_at')->useCurrent();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['ticket_id', 'logged_at']);
|
||||
$table->index(['user_id', 'logged_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('helpdesk_time_logs');
|
||||
}
|
||||
};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Add the logged_at timestamp used by ticket time history and timer-created entries.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('helpdesk_ticket_time_logs', 'logged_at')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
|
||||
$table->timestamp('logged_at')->nullable()->after('ended_at')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the logged_at timestamp if this migration is rolled back.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_ticket_time_logs', 'logged_at')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
|
||||
$table->dropIndex(['logged_at']);
|
||||
$table->dropColumn('logged_at');
|
||||
});
|
||||
}
|
||||
};
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Add seconds precision to helpdesk ticket timer logs.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_ticket_time_logs', 'seconds')) {
|
||||
$table->unsignedInteger('seconds')->default(0)->after('minutes');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove seconds precision from helpdesk ticket timer logs.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
|
||||
if (Schema::hasColumn('helpdesk_ticket_time_logs', 'seconds')) {
|
||||
$table->dropColumn('seconds');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?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
|
||||
{
|
||||
/**
|
||||
* Normalise legacy Flux/Tailwind colour names to the approved WMS palette.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
foreach ($this->lookupTables() as $table) {
|
||||
if (! Schema::hasTable($table) || ! Schema::hasColumn($table, 'color')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->colourMap() as $legacy => $approved) {
|
||||
DB::table($table)->where('color', $legacy)->update(['color' => $approved]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The migration is intentionally one-way because approved colours are the new baseline.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// No-op: do not reintroduce legacy colour aliases.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function lookupTables(): array
|
||||
{
|
||||
return [
|
||||
'helpdesk_statuses',
|
||||
'helpdesk_priorities',
|
||||
'helpdesk_categories',
|
||||
'helpdesk_teams',
|
||||
'helpdesk_projects',
|
||||
'helpdesk_tags',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function colourMap(): array
|
||||
{
|
||||
return [
|
||||
'emerald' => 'green',
|
||||
'lime' => 'green',
|
||||
'rose' => 'red',
|
||||
'yellow' => 'amber',
|
||||
'orange' => 'amber',
|
||||
'sky' => 'blue',
|
||||
'cyan' => 'blue',
|
||||
'violet' => 'purple',
|
||||
'slate' => 'gray',
|
||||
'zinc' => 'gray',
|
||||
];
|
||||
}
|
||||
};
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Add optional attachment metadata used by previews, source viewing and audit trails.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('helpdesk_attachments', static function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('helpdesk_attachments', 'extension')) {
|
||||
$table->string('extension', 32)->nullable()->after('original_name')->index();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_attachments', 'category')) {
|
||||
$table->string('category', 32)->nullable()->after('extension')->index();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_attachments', 'checksum_sha256')) {
|
||||
$table->string('checksum_sha256', 64)->nullable()->after('size')->index();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_attachments', 'download_count')) {
|
||||
$table->unsignedInteger('download_count')->default(0)->after('checksum_sha256');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_attachments', 'last_downloaded_at')) {
|
||||
$table->timestamp('last_downloaded_at')->nullable()->after('download_count');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_attachments', 'deleted_at')) {
|
||||
$table->timestamp('deleted_at')->nullable()->after('last_downloaded_at')->index();
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('helpdesk_attachments', 'deleted_by')) {
|
||||
$table->foreignId('deleted_by')->nullable()->after('deleted_at')->constrained('users')->nullOnDelete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove attachment experience metadata.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('helpdesk_attachments', static function (Blueprint $table): void {
|
||||
if (Schema::hasColumn('helpdesk_attachments', 'deleted_by')) {
|
||||
$table->dropConstrainedForeignId('deleted_by');
|
||||
}
|
||||
|
||||
foreach (['deleted_at', 'last_downloaded_at', 'download_count', 'checksum_sha256', 'category', 'extension'] as $column) {
|
||||
if (Schema::hasColumn('helpdesk_attachments', $column)) {
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Helpdesk\Models\CannedResponse;
|
||||
use Modules\Helpdesk\Models\Category;
|
||||
use Modules\Helpdesk\Models\ChecklistTemplate;
|
||||
use Modules\Helpdesk\Models\KanbanBoard;
|
||||
use Modules\Helpdesk\Models\Priority;
|
||||
use Modules\Helpdesk\Models\Product;
|
||||
use Modules\Helpdesk\Models\Project;
|
||||
use Modules\Helpdesk\Models\SlaPolicy;
|
||||
use Modules\Helpdesk\Models\Status;
|
||||
use Modules\Helpdesk\Models\Tag;
|
||||
use Modules\Helpdesk\Models\Team;
|
||||
use Modules\Helpdesk\Models\WorkflowTemplate;
|
||||
|
||||
final class HelpdeskDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the Helpdesk module lookup data and default workflow templates.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedStatuses();
|
||||
$this->seedPriorities();
|
||||
$this->seedCategories();
|
||||
$this->seedTeamsAndProjects();
|
||||
$this->seedKanbanBoards();
|
||||
$this->seedWorkflowTemplates();
|
||||
$this->seedRedmineInspiredDefaults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed ticket workflow statuses.
|
||||
*/
|
||||
private function seedStatuses(): void
|
||||
{
|
||||
|
||||
Status::query()->where('is_default', true)->update(['is_default' => false]);
|
||||
|
||||
foreach ([
|
||||
['name' => 'New', 'slug' => 'new', 'color' => 'blue', 'sort_order' => 5, 'is_closed' => false, 'is_default' => true],
|
||||
['name' => 'Open', 'slug' => 'open', 'color' => 'green', 'sort_order' => 10, 'is_closed' => false, 'is_default' => false],
|
||||
['name' => 'In Progress', 'slug' => 'in-progress', 'color' => 'indigo', 'sort_order' => 20, 'is_closed' => false, 'is_default' => false],
|
||||
['name' => 'Waiting Customer', 'slug' => 'waiting-customer', 'color' => 'amber', 'sort_order' => 30, 'is_closed' => false, 'is_default' => false],
|
||||
['name' => 'Waiting Third Party', 'slug' => 'waiting-third-party', 'color' => 'purple', 'sort_order' => 40, 'is_closed' => false, 'is_default' => false],
|
||||
['name' => 'Resolved', 'slug' => 'resolved', 'color' => 'green', 'sort_order' => 80, 'is_closed' => true, 'is_default' => false],
|
||||
['name' => 'Closed', 'slug' => 'closed', 'color' => 'gray', 'sort_order' => 90, 'is_closed' => true, 'is_default' => false],
|
||||
['name' => 'Cancelled', 'slug' => 'cancelled', 'color' => 'red', 'sort_order' => 100, 'is_closed' => true, 'is_default' => false],
|
||||
] as $row) {
|
||||
Status::query()->updateOrCreate(['slug' => $row['slug']], $row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed ticket priorities.
|
||||
*/
|
||||
private function seedPriorities(): void
|
||||
{
|
||||
|
||||
Priority::query()->where('is_default', true)->update(['is_default' => false]);
|
||||
foreach ([
|
||||
['name' => 'Low', 'slug' => 'low', 'color' => 'gray', 'sort_order' => 10, 'is_default' => false],
|
||||
['name' => 'Normal', 'slug' => 'normal', 'color' => 'blue', 'sort_order' => 20, 'is_default' => true],
|
||||
['name' => 'High', 'slug' => 'high', 'color' => 'amber', 'sort_order' => 30, 'is_default' => false],
|
||||
['name' => 'Urgent', 'slug' => 'urgent', 'color' => 'red', 'sort_order' => 40, 'is_default' => false],
|
||||
['name' => 'Critical', 'slug' => 'critical', 'color' => 'red', 'sort_order' => 50, 'is_default' => false],
|
||||
] as $row) {
|
||||
Priority::query()->updateOrCreate(['slug' => $row['slug']], $row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed ticket categories.
|
||||
*/
|
||||
private function seedCategories(): void
|
||||
{
|
||||
Category::query()
|
||||
->whereNull('company_id')
|
||||
->where('is_default', true)
|
||||
->update(['is_default' => false]);
|
||||
foreach ([
|
||||
['name' => 'Development', 'color' => 'indigo', 'description' => 'Software changes, enhancements and development work.', 'is_default' => true],
|
||||
['name' => 'Systems Deployment', 'color' => 'blue', 'description' => 'Deployment, release, infrastructure and environment requests.', 'is_default' => false],
|
||||
['name' => 'Concepts', 'color' => 'purple', 'description' => 'Ideas, concepts, design discussion and future improvements.', 'is_default' => false],
|
||||
['name' => 'Bug', 'color' => 'red', 'description' => 'Defects, regressions and incorrect behaviour.', 'is_default' => false],
|
||||
] as $row) {
|
||||
Category::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => Str::slug($row['name'])],
|
||||
$row + ['company_id' => null, 'slug' => Str::slug($row['name'])],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed the default support team and a default project.
|
||||
*/
|
||||
private function seedTeamsAndProjects(): void
|
||||
{
|
||||
|
||||
Team::query()
|
||||
->whereNull('company_id')
|
||||
->where('is_default', true)
|
||||
->update(['is_default' => false]);
|
||||
|
||||
Project::query()
|
||||
->whereNull('company_id')
|
||||
->where('is_default', true)
|
||||
->update(['is_default' => false]);
|
||||
|
||||
$team = Team::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => 'support'],
|
||||
[
|
||||
'company_id' => null,
|
||||
'name' => 'Support',
|
||||
'slug' => 'support',
|
||||
'color' => 'blue',
|
||||
'description' => 'Default support team for triage, ownership and ticket routing.',
|
||||
'is_default' => true,
|
||||
],
|
||||
);
|
||||
|
||||
Project::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => 'support-desk'],
|
||||
[
|
||||
'company_id' => null,
|
||||
'team_id' => $team->id,
|
||||
'title' => 'Support Desk',
|
||||
'slug' => 'support-desk',
|
||||
'color' => 'indigo',
|
||||
'description' => 'Default project for operational helpdesk tickets.',
|
||||
'is_default' => true,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed the default configurable Kanban board.
|
||||
*/
|
||||
private function seedKanbanBoards(): void
|
||||
{
|
||||
KanbanBoard::query()->where('is_default', true)->update(['is_default' => false]);
|
||||
|
||||
$board = KanbanBoard::query()->updateOrCreate(
|
||||
['slug' => 'standard-support'],
|
||||
[
|
||||
'name' => 'Standard Support',
|
||||
'slug' => 'standard-support',
|
||||
'description' => 'Default Helpdesk workflow board covering new work through closure.',
|
||||
'is_default' => true,
|
||||
'sort_order' => 1,
|
||||
],
|
||||
);
|
||||
|
||||
$statuses = Status::query()
|
||||
->whereIn('slug', ['new', 'open', 'in-progress', 'stalled', 'on-hold', 'closed'])
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
$sync = [];
|
||||
|
||||
foreach ($statuses as $index => $status) {
|
||||
$sync[$status->id] = ['sort_order' => ($index + 1) * 10];
|
||||
}
|
||||
|
||||
$board->statuses()->syncWithoutDetaching($sync);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed default professional workflow email templates.
|
||||
*/
|
||||
private function seedWorkflowTemplates(): void
|
||||
{
|
||||
foreach ([
|
||||
['name' => 'Ticket raised requester notice', 'event' => 'ticket.created', 'subject' => 'Ticket {{ ticket.reference }} has been raised', 'html_body' => '<p>Hello {{ requester.name }},</p><p>Your ticket <strong>{{ ticket.reference }}</strong> has been raised successfully.</p><p><strong>Subject:</strong> {{ ticket.subject }}</p><p><strong>Priority:</strong> {{ ticket.priority }}</p>', 'to_role' => 'requester'],
|
||||
['name' => 'Ticket updated requester notice', 'event' => 'ticket.updated', 'subject' => 'Ticket {{ ticket.reference }} has been updated', 'html_body' => '<p>Hello {{ requester.name }},</p><p>Your ticket <strong>{{ ticket.reference }}</strong> has been updated.</p><p><strong>Status:</strong> {{ ticket.status }}</p><p><strong>Priority:</strong> {{ ticket.priority }}</p>', 'to_role' => 'requester'],
|
||||
['name' => 'Ticket response requester notice', 'event' => 'ticket.commented', 'subject' => 'New response on ticket {{ ticket.reference }}', 'html_body' => '<p>Hello {{ requester.name }},</p><p>A new response has been added to <strong>{{ ticket.reference }}</strong>.</p><p><strong>Subject:</strong> {{ ticket.subject }}</p>', 'to_role' => 'requester'],
|
||||
['name' => 'Ticket closed requester notice', 'event' => 'ticket.closed', 'subject' => 'Ticket {{ ticket.reference }} has been closed', 'html_body' => '<p>Hello {{ requester.name }},</p><p>Your ticket <strong>{{ ticket.reference }}</strong> has been closed.</p><p>Thank you for using the support desk.</p>', 'to_role' => 'requester'],
|
||||
] as $template) {
|
||||
WorkflowTemplate::query()->updateOrCreate(
|
||||
['name' => $template['name'], 'event' => $template['event']],
|
||||
$template + ['text_body' => null, 'cc' => null, 'bcc' => null, 'is_active' => true],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed RedmineUP-inspired professional helpdesk defaults.
|
||||
*/
|
||||
private function seedRedmineInspiredDefaults(): void
|
||||
{
|
||||
$medium = Priority::query()->where('slug', 'medium')->first();
|
||||
$bug = Category::query()->where('slug', 'bug')->first();
|
||||
|
||||
SlaPolicy::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => 'standard-support-sla'],
|
||||
[
|
||||
'company_id' => null,
|
||||
'priority_id' => $medium?->id,
|
||||
'category_id' => null,
|
||||
'name' => 'Standard Support SLA',
|
||||
'slug' => 'standard-support-sla',
|
||||
'first_response_minutes' => 240,
|
||||
'resolution_minutes' => 2880,
|
||||
'business_hours_only' => false,
|
||||
'is_default' => true,
|
||||
'is_active' => true,
|
||||
],
|
||||
);
|
||||
|
||||
CannedResponse::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => 'professional-acknowledgement'],
|
||||
[
|
||||
'company_id' => null,
|
||||
'category_id' => null,
|
||||
'team_id' => null,
|
||||
'name' => 'Professional acknowledgement',
|
||||
'slug' => 'professional-acknowledgement',
|
||||
'visibility' => 'agents',
|
||||
'subject' => null,
|
||||
'body' => '<p>Hello {{ requester.name }},</p><p>Thank you for the update on {{ ticket.reference }}. I am reviewing this now and will come back with the next action shortly.</p><p>Regards,<br>{{ agent.name }}</p>',
|
||||
'is_active' => true,
|
||||
'sort_order' => 10,
|
||||
],
|
||||
);
|
||||
|
||||
ChecklistTemplate::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => 'bug-triage-checklist'],
|
||||
[
|
||||
'company_id' => null,
|
||||
'category_id' => $bug?->id,
|
||||
'project_id' => null,
|
||||
'name' => 'Bug triage checklist',
|
||||
'slug' => 'bug-triage-checklist',
|
||||
'items' => ['Confirm reproduction steps', 'Check recent deployment/build', 'Identify affected tenant/company', 'Record fix or workaround'],
|
||||
'is_active' => true,
|
||||
],
|
||||
);
|
||||
|
||||
foreach ([
|
||||
['name' => 'Escalated', 'slug' => 'escalated', 'color' => 'red'],
|
||||
['name' => 'Waiting on customer', 'slug' => 'waiting-on-customer', 'color' => 'amber'],
|
||||
] as $tag) {
|
||||
Tag::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => $tag['slug']],
|
||||
$tag + ['company_id' => null],
|
||||
);
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('helpdesk_tags', 'is_default')) {
|
||||
Tag::query()
|
||||
->whereNull('company_id')
|
||||
->where('is_default', true)
|
||||
->update(['is_default' => false]);
|
||||
}
|
||||
|
||||
Product::query()->updateOrCreate(
|
||||
['company_id' => null, 'slug' => 'wms-platform'],
|
||||
[
|
||||
'company_id' => null,
|
||||
'name' => 'WMS Platform',
|
||||
'slug' => 'wms-platform',
|
||||
'type' => 'service',
|
||||
'version' => null,
|
||||
'release_channel' => 'core',
|
||||
'description' => 'Default service record for WMS platform support tickets.',
|
||||
'is_active' => true,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Database\factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
|
||||
/**
|
||||
* @extends Factory<Ticket>
|
||||
*/
|
||||
final class TicketFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The model name for the factory.
|
||||
*
|
||||
* @var class-string<Ticket>
|
||||
*/
|
||||
protected $model = Ticket::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$company = Company::query()->create([
|
||||
'name' => 'Helpdesk Factory Company ' . Str::random(8),
|
||||
'slug' => 'helpdesk-factory-company-' . Str::lower(Str::random(8)),
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
'billing_email' => 'helpdesk-factory-' . Str::lower(Str::random(8)) . '@example.test',
|
||||
'is_system_company' => false,
|
||||
]);
|
||||
$user = User::factory()->create([
|
||||
'company_id' => $company->getKey(),
|
||||
]);
|
||||
|
||||
return $this->ticketPayload($company, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a ticket payload using only columns that exist in the current schema.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function ticketPayload(Company $company, User $user): array
|
||||
{
|
||||
$ticket = new Ticket;
|
||||
$table = $ticket->getTable();
|
||||
|
||||
$data = [];
|
||||
|
||||
$put = static function (string $column, mixed $value) use (&$data, $table): void {
|
||||
if (Schema::hasColumn($table, $column)) {
|
||||
$data[$column] = $value;
|
||||
}
|
||||
};
|
||||
|
||||
$put('company_id', $company->getKey());
|
||||
$put('user_id', $user->getKey());
|
||||
$put('owner_id', $user->getKey());
|
||||
$put('created_by_id', $user->getKey());
|
||||
$put('assigned_to_id', $user->getKey());
|
||||
$put('agent_id', $user->getKey());
|
||||
|
||||
$put('reference', 'HD-' . now()->format('Y') . '-' . str_pad((string) $this->faker->unique()->numberBetween(1, 9999), 4, '0', STR_PAD_LEFT));
|
||||
$put('subject', 'Factory helpdesk ticket');
|
||||
$put('title', 'Factory helpdesk ticket');
|
||||
$put('body', '<p>Factory helpdesk ticket body.</p>');
|
||||
$put('details', '<p>Factory helpdesk ticket body.</p>');
|
||||
$put('description', '<p>Factory helpdesk ticket body.</p>');
|
||||
$put('search_text', 'factory helpdesk ticket body');
|
||||
$put('last_activity_at', now());
|
||||
|
||||
$statusId = $this->lookupId(
|
||||
'Modules\\Helpdesk\\Models\\TicketStatus',
|
||||
['name' => 'Open'],
|
||||
['slug' => 'open', 'color' => 'blue', 'is_closed' => false, 'sort_order' => 10],
|
||||
);
|
||||
|
||||
$priorityId = $this->lookupId(
|
||||
'Modules\\Helpdesk\\Models\\TicketPriority',
|
||||
['name' => 'Normal'],
|
||||
['slug' => 'normal', 'color' => 'blue', 'sort_order' => 20],
|
||||
);
|
||||
|
||||
$categoryId = $this->lookupId(
|
||||
'Modules\\Helpdesk\\Models\\TicketCategory',
|
||||
['name' => 'General'],
|
||||
['slug' => 'general', 'color' => 'blue', 'sort_order' => 10],
|
||||
);
|
||||
|
||||
$teamId = $this->lookupId(
|
||||
'Modules\\Helpdesk\\Models\\HelpdeskTeam',
|
||||
['name' => 'Support'],
|
||||
['slug' => 'support', 'color' => 'blue', 'sort_order' => 10],
|
||||
);
|
||||
|
||||
$projectId = $this->lookupId(
|
||||
'Modules\\Helpdesk\\Models\\HelpdeskProject',
|
||||
['name' => 'General'],
|
||||
['slug' => 'general', 'color' => 'blue', 'sort_order' => 10],
|
||||
);
|
||||
|
||||
$put('status_id', $statusId);
|
||||
$put('ticket_status_id', $statusId);
|
||||
$put('priority_id', $priorityId);
|
||||
$put('ticket_priority_id', $priorityId);
|
||||
$put('category_id', $categoryId);
|
||||
$put('ticket_category_id', $categoryId);
|
||||
$put('team_id', $teamId);
|
||||
$put('helpdesk_team_id', $teamId);
|
||||
$put('project_id', $projectId);
|
||||
$put('helpdesk_project_id', $projectId);
|
||||
|
||||
$unid = strtoupper(str_replace('-', '', (string) Str::uuid()));
|
||||
$put('guid', (string) Str::uuid());
|
||||
$put('uuid', (string) Str::uuid());
|
||||
$put('unid', $unid);
|
||||
$put('root_unid', $unid);
|
||||
$put('sync_sequence', 1);
|
||||
$put('source_system', 'phpunit');
|
||||
|
||||
return array_filter($data, static fn (mixed $value): bool => $value !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve or create a lookup row when the model exists.
|
||||
*/
|
||||
private function lookupId(string $class, array $identity, array $attributes): ?int
|
||||
{
|
||||
if (! class_exists($class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var class-string<Model> $class */
|
||||
$model = new $class;
|
||||
|
||||
if (! Schema::hasTable($model->getTable())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$payload = array_merge($identity, $attributes);
|
||||
|
||||
foreach (['slug', 'color', 'sort_order', 'is_closed'] as $column) {
|
||||
if (array_key_exists($column, $payload) && ! Schema::hasColumn($model->getTable(), $column)) {
|
||||
unset($payload[$column]);
|
||||
}
|
||||
}
|
||||
|
||||
$row = $class::query()->firstOrCreate($identity, $payload);
|
||||
|
||||
return (int) $row->getKey();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user