Skip to content

Commit 2018407

Browse files
committed
Avoid error by pre-checking if user has email address
1 parent 54f065f commit 2018407

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

app/Listeners/CheckoutablesCheckedOutInBulkListener.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\Asset;
88
use App\Models\Location;
99
use App\Models\Setting;
10+
use App\Models\User;
1011
use Exception;
1112
use Illuminate\Support\Collection;
1213
use Illuminate\Support\Facades\Log;
@@ -25,11 +26,11 @@ public function subscribe($events)
2526

2627
public function handle(CheckoutablesCheckedOutInBulk $event): void
2728
{
28-
$shouldSendEmailToUser = $this->shouldSendCheckoutEmailToUser($event->assets);
29-
$shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress($event->assets);
30-
3129
$notifiableUser = $this->getNotifiableUser($event);
3230

31+
$shouldSendEmailToUser = $this->shouldSendCheckoutEmailToUser($notifiableUser, $event->assets);
32+
$shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress($event->assets);
33+
3334
if ($shouldSendEmailToUser && $notifiableUser) {
3435
try {
3536
Mail::to($notifiableUser)->send(new BulkAssetCheckoutMail(
@@ -65,8 +66,12 @@ public function handle(CheckoutablesCheckedOutInBulk $event): void
6566
}
6667
}
6768

68-
private function shouldSendCheckoutEmailToUser(Collection $assets): bool
69+
private function shouldSendCheckoutEmailToUser(?User $user, Collection $assets): bool
6970
{
71+
if (!$user->email) {
72+
return false;
73+
}
74+
7075
// @todo: how to handle assets having eula?
7176
7277
return $this->requiresAcceptance($assets);

0 commit comments

Comments
 (0)