Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
AddExistentUserJob | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getActiveLicense | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handle | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace App\Jobs\Emails; |
4 | |
5 | use App\Http\Models\Admin\Company; |
6 | use App\Http\Models\Parameter; |
7 | use App\Mail\AdminCenterAddExistingUser; |
8 | use App\Services\Email\EmailService; |
9 | use Illuminate\Bus\Queueable; |
10 | use Illuminate\Contracts\Queue\ShouldQueue; |
11 | use Illuminate\Foundation\Bus\Dispatchable; |
12 | use Illuminate\Queue\InteractsWithQueue; |
13 | use Illuminate\Queue\SerializesModels; |
14 | use Illuminate\Support\Facades\Log; |
15 | |
16 | class AddExistentUserJob implements ShouldQueue |
17 | { |
18 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
19 | |
20 | public $tries = 3; |
21 | public $retryAfter = 60; |
22 | |
23 | /** |
24 | * Create a new job instance. |
25 | */ |
26 | public function __construct( |
27 | private readonly string $email, |
28 | private readonly string $adminEmail, |
29 | private readonly Company $company, |
30 | private readonly EmailService $emailService |
31 | ) { |
32 | // |
33 | } |
34 | |
35 | private function getActiveLicense($company) |
36 | { |
37 | return $company->licenses->first() ?? $company->licenses()->latest()->first(); |
38 | } |
39 | |
40 | /** |
41 | * Execute the job. |
42 | */ |
43 | public function handle(): void |
44 | { |
45 | try { |
46 | $companyLicense = $this->getActiveLicense($this->company); |
47 | |
48 | $bcc = null; |
49 | |
50 | if ($companyLicense->business_pro_enterprise_plus !== null && in_array('yes_community', $companyLicense->business_pro_enterprise_plus)) { |
51 | $parameters = Parameter::where('name', 'bcc_email_community_coach')->first(); |
52 | |
53 | $bcc = $parameters->value ?? 'heysupport@vengreso.com'; |
54 | } |
55 | |
56 | $this->emailService->send( |
57 | $this->email, |
58 | new AdminCenterAddExistingUser( |
59 | admin_email: $this->adminEmail, |
60 | email: $this->email, |
61 | company: $this->company->name, |
62 | ), |
63 | 'add_existing_user', |
64 | true, |
65 | $bcc |
66 | ); |
67 | } catch (\Exception $e) { |
68 | Log::error('Error sending email: ' . $e->getMessage()); |
69 | } |
70 | } |
71 | } |