Ticket 370

This commit is contained in:
Jérémy Munsch 2021-09-28 14:53:43 +02:00
parent 477a09b07b
commit 97f77f1ae0
No known key found for this signature in database
GPG key ID: 55196BEE445F6049
4 changed files with 47 additions and 2 deletions

View file

@ -2,6 +2,7 @@
namespace App\Console;
use App\Jobs\AutoCloseOldTickets;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@ -23,6 +24,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->job(AutoCloseOldTickets::class)->dailyAt('08:00');
}
/**

View file

@ -22,15 +22,19 @@ class TicketStatusChanged
public $status;
/** @var string */
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Ticket $ticket, $status, User $user = null)
public function __construct(Ticket $ticket, $status, User $user = null, string $message = null)
{
$this->ticket = $ticket;
$this->status = $status;
$this->user = $user;
$this->message = $message;
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace App\Jobs;
use App\Enums\TicketStatus;
use App\Events\NotifySubscriptions;
use App\Events\TicketStatusChanged;
use App\Models\Ticket;
use Illuminate\Support\Carbon;
class AutoCloseOldTickets
{
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$message = 'En l\'abscence d\'activitée depuis 15 jours ce ticket est automatiquement clos et archivé.';
$tickets = Ticket::where('status', TicketStatus::production())
->orWhere('status', TicketStatus::processed())
->where('updated_at', '<', Carbon::now()->subDays(15))
->whereDoesntHave('messages', function ($q) {
$q->where('updated_at', '<', Carbon::now()->subDays(15));
})->get();
foreach ($tickets as $ticket) {
$oldStatus = $ticket->status;
$ticket->status = TicketStatus::archived();
$ticket->saveQuietly();
if (!$ticket->subscriptions->contains($ticket->user)) {
event(new TicketStatusChanged($ticket, $oldStatus, null, $message));
}
event(new NotifySubscriptions($ticket, $message));
}
}
}

View file

@ -17,7 +17,9 @@ class AddStatusMessages
{
$message = new Message();
$message->ticket_id = $event->ticket->id;
if ($event->user) {
if ($event->message) {
$message->message = $event->message;
} elseif ($event->user) {
// phpcs:ignore Generic.Files.LineLength.TooLong
$message->message = "<b>{$event->user->name}</b> a modifié le statut en <b>{$event->ticket->status->label}</b>";
} else {