diff --git a/Modules/Helpdesk/Database/Migrations/2026_06_22_000001_add_timer_fields_to_helpdesk_time_logs_table.php b/Modules/Helpdesk/Database/Migrations/2026_06_22_000001_add_timer_fields_to_helpdesk_time_logs_table.php new file mode 100644 index 00000000..41a2423a --- /dev/null +++ b/Modules/Helpdesk/Database/Migrations/2026_06_22_000001_add_timer_fields_to_helpdesk_time_logs_table.php @@ -0,0 +1,54 @@ +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); + } + } + }); + } + } +}; diff --git a/Modules/Helpdesk/Database/Migrations/2026_06_22_000001_create_helpdesk_ticket_time_logs_table.php b/Modules/Helpdesk/Database/Migrations/2026_06_22_000001_create_helpdesk_ticket_time_logs_table.php new file mode 100644 index 00000000..050dcf6f --- /dev/null +++ b/Modules/Helpdesk/Database/Migrations/2026_06_22_000001_create_helpdesk_ticket_time_logs_table.php @@ -0,0 +1,41 @@ +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'); + } +}; diff --git a/Modules/Helpdesk/Database/Migrations/2026_06_22_124500_add_logged_at_to_helpdesk_ticket_time_logs_table.php b/Modules/Helpdesk/Database/Migrations/2026_06_22_124500_add_logged_at_to_helpdesk_ticket_time_logs_table.php new file mode 100644 index 00000000..75a6cb0c --- /dev/null +++ b/Modules/Helpdesk/Database/Migrations/2026_06_22_124500_add_logged_at_to_helpdesk_ticket_time_logs_table.php @@ -0,0 +1,45 @@ +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'); + }); + } +}; diff --git a/Modules/Helpdesk/Feature/TicketTimerFilesTest.php b/Modules/Helpdesk/Feature/TicketTimerFilesTest.php new file mode 100644 index 00000000..3a386079 --- /dev/null +++ b/Modules/Helpdesk/Feature/TicketTimerFilesTest.php @@ -0,0 +1,49 @@ +assertStringStartsWith('