Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/Console/Commands/ArchiveOldTickets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Console\Commands;

use App\Model\helpdesk\Ticket\Ticket_Thread;
use App\Model\helpdesk\Ticket\Tickets;
use Carbon\Carbon;
use Illuminate\Console\Command;

class ArchiveOldTickets extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tickets:archive {--days=365}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Archive tickets older than a specified number of days';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$days = $this->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.');
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand Down