56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Mail\ProfileConvertedByAdminMail;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class SendProfileConvertedByAdminMail implements ShouldQueue
|
|
{
|
|
use Dispatchable;
|
|
use InteractsWithQueue;
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
protected $profile;
|
|
protected $convertedTo;
|
|
protected $manager;
|
|
|
|
public function __construct($profile, string $convertedTo, $manager = null)
|
|
{
|
|
$this->profile = $profile;
|
|
$this->convertedTo = $convertedTo;
|
|
$this->manager = $manager;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
if (!$this->profile->email) {
|
|
Log::warning('SendProfileConvertedByAdminMail: Profile has no email address', [
|
|
'profile_id' => $this->profile->id,
|
|
'profile_type' => get_class($this->profile),
|
|
]);
|
|
return;
|
|
}
|
|
|
|
Log::info('SendProfileConvertedByAdminMail: Sending email', [
|
|
'profile_id' => $this->profile->id,
|
|
'profile_type' => get_class($this->profile),
|
|
'converted_to' => $this->convertedTo,
|
|
'manager_id' => $this->manager?->id,
|
|
]);
|
|
|
|
Mail::to($this->profile->email)->send(
|
|
new ProfileConvertedByAdminMail($this->profile, $this->convertedTo, $this->manager)
|
|
);
|
|
|
|
Log::info('SendProfileConvertedByAdminMail: Email sent successfully');
|
|
}
|
|
}
|