diff --git a/.env.example b/.env.example index 7dc51e1..8f09ece 100644 --- a/.env.example +++ b/.env.example @@ -32,6 +32,7 @@ MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" +MAIL_LIST_SERVICEWEB=informatique.internet@ldc.fr AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= diff --git a/app/Enums/TicketStatus.php b/app/Enums/TicketStatus.php index 534da07..b0fe989 100644 --- a/app/Enums/TicketStatus.php +++ b/app/Enums/TicketStatus.php @@ -6,6 +6,10 @@ use Kwaadpepper\Enum\BaseEnum; /** * @method static self new() + * @method static self estimateTodo() + * @method static self estimateValidated() + * @method static self toPlan() + * @method static self planned() * @method static self inprogress() * @method static self waiting() * @method static self processed() @@ -19,12 +23,16 @@ class TicketStatus extends BaseEnum { return [ 'new' => 1, - 'inprogress' => 2, - 'waiting' => 3, - 'processed' => 4, - 'recette' => 5, - 'production' => 6, - 'archived' => 9, + 'estimateTodo' => 2, + 'estimateValidated' => 3, + 'toPlan' => 4, + 'planned' => 5, + 'inprogress' => 7, + 'waiting' => 9, + 'processed' => 10, + 'recette' => 12, + 'production' => 13, + 'archived' => 15, ]; } @@ -32,6 +40,10 @@ class TicketStatus extends BaseEnum { return [ 'new' => trans('Nouveau'), + 'estimateTodo' => trans('Devis à faire'), + 'estimateValidated' => trans('Devis validé'), + 'toPlan' => trans('À planifier'), + 'planned' => trans('Planifié'), 'inprogress' => trans('En cours'), 'waiting' => trans('En attente'), 'processed' => trans('Traité'), diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7e40d73..5892cad 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,9 +3,13 @@ namespace App\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Support\Facades\Mail; +use RuntimeException; +use Throwable; class Handler extends ExceptionHandler { + /** * A list of the exception types that are not reported. * @@ -25,6 +29,45 @@ class Handler extends ExceptionHandler 'password_confirmation', ]; + /** + * Report or log an exception. + * + * @param \Throwable $exception + * @return void + * + * @throws \Exception + */ + public function report(Throwable $e) + { + if (get_class($e) == RedirectTo::class) { + abort(redirect($e->url)); + } + try { + if (config('app.debug') === false) { + if ($this->shouldntReport($e)) { + return; + } + Mail::send([ + 'html' => 'emails.exception', + 'text' => 'emails.exception-plain' + ], [ + 'exception' => $e, + 'appName' => config('app.name') + ], function ($m) { + $m->to( + config('mail.contactsList.serviceweb'), + sprintf('%s Exception Handler', config('app.name')) + )->subject('Need help !, an error occured in your application, please check Logs ASAP'); + }); + } + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch + } catch (RuntimeException $e) { + // do nothing, mail send error, let laravel only handle this + } finally { + parent::report($e); + } + } + /** * Register the exception handling callbacks for the application. * diff --git a/app/Mail/NewTicket.php b/app/Mail/NewTicket.php index 00934ff..6e17361 100644 --- a/app/Mail/NewTicket.php +++ b/app/Mail/NewTicket.php @@ -31,6 +31,6 @@ class NewTicket extends Mailable public function build() { $ticket = $this->ticket; - return $this->subject("[SupportWeb] Nouveau ticket n°" . $ticket->id)->view('mails.new-ticket', compact('ticket')); + return $this->subject("[SupportWeb] Nouveau ticket n°" . $ticket->id)->view('emails.new-ticket', compact('ticket')); } } diff --git a/app/Mail/TicketMention.php b/app/Mail/TicketMention.php index a38f6fa..9eb0b25 100644 --- a/app/Mail/TicketMention.php +++ b/app/Mail/TicketMention.php @@ -40,6 +40,6 @@ class TicketMention extends Mailable $ticket = $this->ticket; $corpsMaj = Utils::plainToHtml($this->corpsMaj); return $this->subject("[SupportWeb] Vous avez été mentionné sur le ticket n° $ticket->id") - ->view('mails.ticket-mention', compact('ticket', 'corpsMaj')); + ->view('emails.ticket-mention', compact('ticket', 'corpsMaj')); } } diff --git a/app/Mail/TicketUpdate.php b/app/Mail/TicketUpdate.php index 72fd314..13b89a7 100644 --- a/app/Mail/TicketUpdate.php +++ b/app/Mail/TicketUpdate.php @@ -40,6 +40,6 @@ class TicketUpdate extends Mailable { $ticket = $this->ticket; $corpsMaj = Utils::plainToHtml($this->corpsMaj); - return $this->subject("[SupportWeb] Le ticket n°" . $ticket->id . " à été mis à jour")->view('mails.ticket-update', compact('ticket', 'corpsMaj')); + return $this->subject("[SupportWeb] Le ticket n°" . $ticket->id . " à été mis à jour")->view('emails.ticket-update', compact('ticket', 'corpsMaj')); } } diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index 45c8282..e68fa87 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -30,6 +30,12 @@ class Ticket extends Model protected static function booted() { + static::creating(function (Ticket $ticket) { + // If evolution force the ticket status on estimateTodo + if ($ticket->type->equals(TicketType::evolution())) { + $ticket->status = TicketStatus::estimateTodo(); + } + }); static::updating(function (Ticket $ticket) { $oldStatus = Ticket::where('id', $ticket->id)->first()->status; if (!$ticket->status->equals($oldStatus)) { diff --git a/config/mail.php b/config/mail.php index 6649a64..8df1fc5 100644 --- a/config/mail.php +++ b/config/mail.php @@ -91,6 +91,10 @@ return [ 'name' => env('MAIL_FROM_NAME', 'Example'), ], + 'contactsList' => [ + 'serviceweb' => env('MAIL_LIST_SERVICEWEB', 'informatique.internet@ldc.fr') + ], + /* |-------------------------------------------------------------------------- | Markdown Mail Settings diff --git a/database/migrations/2021_04_21_132140_update_tickets_status_with_enum_status3.php b/database/migrations/2021_04_21_132140_update_tickets_status_with_enum_status3.php new file mode 100644 index 0000000..c0e75b7 --- /dev/null +++ b/database/migrations/2021_04_21_132140_update_tickets_status_with_enum_status3.php @@ -0,0 +1,53 @@ +get() as $ticket) { + $ticket->status = TicketStatus::inprogress(); + $ticket->save(); + } + foreach (Ticket::where('status', 3)->get() as $ticket) { + $ticket->status = TicketStatus::waiting(); + $ticket->save(); + } + foreach (Ticket::where('status', 4)->get() as $ticket) { + $ticket->status = TicketStatus::processed(); + $ticket->save(); + } + foreach (Ticket::where('status', 5)->get() as $ticket) { + $ticket->status = TicketStatus::recette(); + $ticket->save(); + } + foreach (Ticket::where('status', 6)->get() as $ticket) { + $ticket->status = TicketStatus::production(); + $ticket->save(); + } + foreach (Ticket::where('status', 9)->get() as $ticket) { + $ticket->status = TicketStatus::archived(); + $ticket->save(); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/views/emails/exception-plain.blade.php b/resources/views/emails/exception-plain.blade.php new file mode 100644 index 0000000..0360447 --- /dev/null +++ b/resources/views/emails/exception-plain.blade.php @@ -0,0 +1,10 @@ +{{ $appName }} Exception Handler + +Une erreur est survenue sur le site {{ $appName }} +{{ $exception->getMessage() }} +date : {{ date('Y-m-d H:i:s') }} +code : {{$exception->getCode() }} +file : {{$exception->getFile() }} +line : {{$exception->getLine() }} + +Veuillez vérifier les logs pour en voir la trace. diff --git a/resources/views/emails/exception.blade.php b/resources/views/emails/exception.blade.php new file mode 100644 index 0000000..80a46d6 --- /dev/null +++ b/resources/views/emails/exception.blade.php @@ -0,0 +1,16 @@ + + + + {{ $appName }} Exception Handler + + + +

Une erreur est survenue sur le site {{ $appName }}

+

{{ $exception->getMessage() }}

+

date : {{ date('Y-m-d H:i:s') }}

+

code : {{$exception->getCode() }}

+

file : {{$exception->getFile() }}

+

line : {{$exception->getLine() }}

+

Veuillez vérifier les logs pour en voir la trace.

+ + diff --git a/resources/views/mails/new-ticket.blade.php b/resources/views/emails/new-ticket.blade.php similarity index 100% rename from resources/views/mails/new-ticket.blade.php rename to resources/views/emails/new-ticket.blade.php diff --git a/resources/views/mails/ticket-mention.blade.php b/resources/views/emails/ticket-mention.blade.php similarity index 100% rename from resources/views/mails/ticket-mention.blade.php rename to resources/views/emails/ticket-mention.blade.php diff --git a/resources/views/mails/ticket-update.blade.php b/resources/views/emails/ticket-update.blade.php similarity index 100% rename from resources/views/mails/ticket-update.blade.php rename to resources/views/emails/ticket-update.blade.php