fix: new ticket creation failed
This commit is contained in:
parent
c2b25c3503
commit
bd9b7cd32e
4 changed files with 88 additions and 28 deletions
34
app/Events/TicketCreated.php
Normal file
34
app/Events/TicketCreated.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\Ticket;
|
||||
use DragonCode\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class TicketCreated implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public readonly Site $siteReceivingTicket,
|
||||
public readonly Ticket $ticket,
|
||||
public readonly string $byUserName
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('default'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ use App\Http\Requests\Bo\StoreTicket;
|
|||
use App\Http\Requests\Bo\UpdateTicket;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Enums\Tickets\TicketStatusEnum;
|
||||
use App\Events\TicketCreated;
|
||||
use App\Http\Requests\Bo\CreateMessage;
|
||||
use App\Http\Requests\Bo\UpdateMessage;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
|
@ -33,14 +34,16 @@ use App\Http\Requests\Bo\ChangeTicketStatus;
|
|||
use App\Http\Requests\Bo\UpdateChangeOrderRequest;
|
||||
use App\Http\Requests\Bo\AssignTicketToUserRequest;
|
||||
use App\Http\Requests\Bo\UpdateTicketPriorityRequest;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class TicketController extends Controller
|
||||
{
|
||||
/**
|
||||
* TicketController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
public function __construct(
|
||||
public readonly Dispatcher $dispatcher
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->authorizeResource(Ticket::class, 'ticket');
|
||||
}
|
||||
|
|
@ -213,7 +216,7 @@ class TicketController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
$ticket->user()->associate(auth()->user());
|
||||
$ticket->user()->associate($user);
|
||||
$ticket->site()->associate($site);
|
||||
$ticket->saveOrFail();
|
||||
|
||||
|
|
@ -223,11 +226,11 @@ class TicketController extends Controller
|
|||
|
||||
$user->subscriptions()->toggle($ticket->id);
|
||||
|
||||
if (config('mail.MAIL_ADMIN')) {
|
||||
Mail::to(config('mail.MAIL_ADMIN'))->send(new NewTicket($ticket));
|
||||
} else {
|
||||
throw new \ErrorException('Missing MAIL_ADMIN in .env');
|
||||
}
|
||||
$this->dispatcher->dispatch(new TicketCreated(
|
||||
siteReceivingTicket: $site,
|
||||
ticket: $ticket,
|
||||
byUserName: $user->name
|
||||
));
|
||||
|
||||
return redirect()->route('bo.ticket.show', $ticket)
|
||||
->with('success', trans('Ticket enregistré !'));
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@
|
|||
namespace App\Listeners;
|
||||
|
||||
use App\Events\BrevoWebhookCallReceived;
|
||||
use App\Events\TicketCreated;
|
||||
use App\Mail\NewTicket;
|
||||
use App\Repositories\SiteRepository;
|
||||
use App\Services\AutomaticTicketCreator;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
|
@ -17,17 +19,12 @@ class CreateTicketAutomatically implements ShouldQueue
|
|||
{
|
||||
private const string SITE_NAME_WHERE_TO_CREATE_TICKET = 'Mailing en masse';
|
||||
|
||||
private readonly Email $mailAdmin;
|
||||
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly AutomaticTicketCreator $automaticTicketCreator,
|
||||
private readonly SiteRepository $siteRepository,
|
||||
) {
|
||||
$this->mailAdmin = new Email(
|
||||
Config::string('mail.MAIL_ADMIN')
|
||||
);
|
||||
}
|
||||
private readonly Dispatcher $dispatcher
|
||||
) {}
|
||||
|
||||
public function handle(BrevoWebhookCallReceived $event): void
|
||||
{
|
||||
|
|
@ -69,14 +66,10 @@ class CreateTicketAutomatically implements ShouldQueue
|
|||
$htmlRawContent,
|
||||
);
|
||||
|
||||
Mail::to($this->mailAdmin->value)
|
||||
->send(new NewTicket(
|
||||
ticketId: $ticket->id,
|
||||
siteName: $siteReceivingTickets->name,
|
||||
ticketTitle: $ticket->title,
|
||||
ticketType: $ticket->type,
|
||||
userName: $fromEmail->value,
|
||||
ticketDescription: $ticket->text,
|
||||
));
|
||||
$this->dispatcher->dispatch(new TicketCreated(
|
||||
siteReceivingTicket: $siteReceivingTickets,
|
||||
ticket: $ticket,
|
||||
byUserName: $fromEmail->value
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,21 +3,51 @@
|
|||
namespace App\Listeners;
|
||||
|
||||
use App\Events\NotifyAdmin;
|
||||
use App\Events\TicketCreated;
|
||||
use App\Mail\NewTicket;
|
||||
use App\Mail\TicketUpdate;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendNotificationMailToAdmin
|
||||
{
|
||||
private readonly Email $mailAdmin;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->mailAdmin = new Email(
|
||||
Config::string('mail.MAIL_ADMIN')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\NotifyAdmin $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(NotifyAdmin $event)
|
||||
public function handle(NotifyAdmin | TicketCreated $event)
|
||||
{
|
||||
$ticket = $event->ticket;
|
||||
Mail::to(config('mail.MAIL_ADMIN'))
|
||||
->send(new TicketUpdate($ticket, $event->corpsMaj));
|
||||
if ($event instanceof NotifyAdmin) {
|
||||
$ticket = $event->ticket;
|
||||
Mail::to($this->mailAdmin)
|
||||
->send(new TicketUpdate($ticket, $event->corpsMaj));
|
||||
}
|
||||
if ($event instanceof TicketCreated) {
|
||||
$ticket = $event->ticket;
|
||||
$siteReceivingTickets = $event->siteReceivingTicket;
|
||||
$userName = $event->byUserName;
|
||||
|
||||
Mail::to($this->mailAdmin->value)
|
||||
->send(new NewTicket(
|
||||
ticketId: $ticket->id,
|
||||
siteName: $siteReceivingTickets->name,
|
||||
ticketTitle: $ticket->title,
|
||||
ticketType: $ticket->type,
|
||||
userName: $userName,
|
||||
ticketDescription: $ticket->text,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue