Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SendFollowUpDigest | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| buildMail | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
30 | |||
| logLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Jobs\Email; |
| 4 | |
| 5 | use SendGrid\Mail\Mail; |
| 6 | |
| 7 | /** |
| 8 | * FIRE-1147: per-user async wrapper for the follow-up digest email. |
| 9 | * Replaces the inline SendGrid send inside the per-user loop in |
| 10 | * Notifications::send_follow_up_notification (Notifications.php:205-…). |
| 11 | * |
| 12 | * Dispatched once per user from the cron; jobs fan out across the worker |
| 13 | * pool so a 50-user digest run drops from ~50s serial to ~max(per-user time). |
| 14 | * |
| 15 | * The controller still does all the per-user DB work (TblNotifications + |
| 16 | * TblNotificationLogs creation) BEFORE dispatch — see FIRE-1092 pattern. |
| 17 | * This job just delivers the email. |
| 18 | */ |
| 19 | class SendFollowUpDigest extends AbstractSendgridJob |
| 20 | { |
| 21 | public function __construct( |
| 22 | public readonly string $toEmail, |
| 23 | public readonly string $subject, |
| 24 | public readonly string $html, |
| 25 | /** Optional CC addresses (per-company TblCcBccNotifications recipients). */ |
| 26 | public readonly array $cc = [], |
| 27 | public readonly ?int $userId = null, |
| 28 | ) {} |
| 29 | |
| 30 | protected function buildMail(): ?Mail |
| 31 | { |
| 32 | if ($this->toEmail === '') { |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | $email = new Mail; |
| 37 | $email->setFrom('fire@fire.es', 'Fire Service Titan'); |
| 38 | $email->setSubject($this->subject); |
| 39 | $email->addTo($this->toEmail); |
| 40 | $email->addContent('text/html', $this->html); |
| 41 | |
| 42 | foreach ($this->cc as $address) { |
| 43 | if ($address && $address !== $this->toEmail) { |
| 44 | $email->addCc($address); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Two inline images: the FST logo + the sendfollowups graphic |
| 49 | // (referenced via cid: in the html body). |
| 50 | $email->addAttachment( |
| 51 | file_get_contents(public_path('fireservicetitan.png')), |
| 52 | 'image/png', |
| 53 | 'fireservicetitan.png', |
| 54 | 'inline', |
| 55 | 'fireservicetitan' |
| 56 | ); |
| 57 | $email->addAttachment( |
| 58 | file_get_contents(public_path('sendfollowups.png')), |
| 59 | 'image/png', |
| 60 | 'sendfollowups.png', |
| 61 | 'inline', |
| 62 | 'sendfollowups' |
| 63 | ); |
| 64 | |
| 65 | return $email; |
| 66 | } |
| 67 | |
| 68 | protected function logLabel(): string |
| 69 | { |
| 70 | return 'Notifications::send_follow_up_notification'; |
| 71 | } |
| 72 | } |