diff --git a/app/Console/Commands/ArchiveOldTickets.php b/app/Console/Commands/ArchiveOldTickets.php new file mode 100644 index 0000000000..3cd66a4a62 --- /dev/null +++ b/app/Console/Commands/ArchiveOldTickets.php @@ -0,0 +1,59 @@ +option('days'); + $this->info("Archiving tickets older than $days days..."); + $date = Carbon::now()->subDays($days); + $tickets = Tickets::where('updated_at', '<', $date)->where('status', '!=', 5)->get(); + + if ($tickets->isEmpty()) { + $this->info('No tickets to archive.'); + + return; + } + + foreach ($tickets as $ticket) { + $ticket->status = 5; // Assuming 5 is the status for "Archived" + $ticket->save(); + + $thread = new Ticket_Thread(); + $thread->ticket_id = $ticket->id; + $thread->user_id = 1; // System user + $thread->is_internal = 1; + $thread->body = 'Ticket has been archived by the system.'; + $thread->save(); + + $this->info("Archived ticket #{$ticket->id}"); + } + $this->info('Done.'); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 631ce1c76f..b79cd8c0e1 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -25,6 +25,7 @@ class Kernel extends ConsoleKernel \App\Console\Commands\InstallDB::class, \App\Console\Commands\SetupTestEnv::class, \App\Console\Commands\SecureFaveoAPPKey::class, + \App\Console\Commands\ArchiveOldTickets::class, SyncFaveoToLatestVersion::class, ];