Merge branch 'trunk'
This commit is contained in:
commit
7c13f3f4f2
4 changed files with 55 additions and 7 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Console;
|
||||
|
||||
use App\Jobs\AutoCloseOldTickets;
|
||||
use App\Jobs\WarnBeforeAutoCloseTicket;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ class Kernel extends ConsoleKernel
|
|||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->job(AutoCloseOldTickets::class)->dailyAt('08:00');
|
||||
$schedule->job(WarnBeforeAutoCloseTicket::class)->dailyAt('08:05');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ class AutoCloseOldTickets
|
|||
*/
|
||||
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));
|
||||
$limitDays = 15;
|
||||
$message = 'En l\'absence d\'activitée depuis 15 jours ce ticket est automatiquement clos et archivé.';
|
||||
$tickets = Ticket::where(function ($q) {
|
||||
$q->where('status', TicketStatus::production())
|
||||
->orWhere('status', TicketStatus::processed());
|
||||
})->whereDate('updated_at', '<=', Carbon::now()->subDays($limitDays))
|
||||
->whereDoesntHave('messages', function ($q) use ($limitDays) {
|
||||
$q->whereDate('updated_at', '>', Carbon::now()->subDays($limitDays));
|
||||
})->get();
|
||||
foreach ($tickets as $ticket) {
|
||||
$oldStatus = $ticket->status;
|
||||
|
|
|
|||
44
app/Jobs/WarnBeforeAutoCloseTicket.php
Normal file
44
app/Jobs/WarnBeforeAutoCloseTicket.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Enums\TicketStatus;
|
||||
use App\Events\NotifySubscriptions;
|
||||
use App\Events\NotifyTicketCreator;
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class WarnBeforeAutoCloseTicket
|
||||
{
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$warningDays = 7;
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
$messageToAll = "En l'absence d'activitée, ou de réponse de la part du requérant ce ticket sera automatiquement clos et archivé dans $warningDays jours.";
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
$messageToUser = 'En l\'absence d\'activitée, ou de réponse de votre part ce ticket sera automatiquement clos et archivé dans %s jours.';
|
||||
$tickets = Ticket::where(function ($q) {
|
||||
$q->where('status', TicketStatus::production())
|
||||
->orWhere('status', TicketStatus::processed());
|
||||
})->whereDate('updated_at', '<=', Carbon::now()->subDays($warningDays))
|
||||
->whereDoesntHave('messages', function ($q) use ($warningDays) {
|
||||
$q->whereDate('updated_at', '>', Carbon::now()->subDays($warningDays));
|
||||
})->get();
|
||||
foreach ($tickets as $ticket) {
|
||||
$date = $ticket->messages->sortByDesc('updated_at')->first()->updated_at ?? $ticket->updated_at;
|
||||
$limitDate = $date->addDays($warningDays);
|
||||
if (intval(Carbon::now()->diff($limitDate)->format('%a')) >= $warningDays) {
|
||||
event(new NotifySubscriptions($ticket, $messageToAll, collect($ticket->user)));
|
||||
}
|
||||
event(new NotifyTicketCreator($ticket, sprintf(
|
||||
$messageToUser,
|
||||
intval($date->diff(Carbon::now()->subDays($warningDays))->format('%a') + 1)
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ class TicketUpdate extends Mailable
|
|||
{
|
||||
$ticket = $this->ticket;
|
||||
$corpsMaj = Utils::plainToHtml($this->corpsMaj);
|
||||
return $this->subject("[SupportWeb] Le ticket n°" . $ticket->id . " à été mis à jour")
|
||||
return $this->subject("[SupportWeb][{$ticket->site->name}] Ticket n°$ticket->id")
|
||||
->view('emails.ticket-update', compact('ticket', 'corpsMaj'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue