mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-31 16:37:27 -08:00
fix duplicate emails being sent in unaccepted reminder command
This commit is contained in:
parent
52b051e940
commit
3f8916ea2e
|
@ -9,9 +9,8 @@ use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\CheckoutAssetNotification;
|
use App\Notifications\CheckoutAssetNotification;
|
||||||
use App\Notifications\CurrentInventory;
|
use App\Notifications\CurrentInventory;
|
||||||
use App\Notifications\UnacceptedAssetReminderNotification;
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
class SendAcceptanceReminder extends Command
|
class SendAcceptanceReminder extends Command
|
||||||
{
|
{
|
||||||
|
@ -69,39 +68,26 @@ class SendAcceptanceReminder extends Command
|
||||||
$no_mail_address = [];
|
$no_mail_address = [];
|
||||||
|
|
||||||
foreach($unacceptedAssetGroups as $unacceptedAssetGroup) {
|
foreach($unacceptedAssetGroups as $unacceptedAssetGroup) {
|
||||||
$item_count = $unacceptedAssetGroup->count();
|
|
||||||
foreach ($unacceptedAssetGroup as $unacceptedAsset) {
|
|
||||||
// if ($unacceptedAsset['acceptance']->assignedTo->email == ''){
|
|
||||||
// $no_mail_address[] = $unacceptedAsset['checkoutable']->assignedTo->present()->fullName;
|
|
||||||
// }
|
|
||||||
if ($unacceptedAsset['acceptance']->assignedTo) {
|
|
||||||
|
|
||||||
if (!$unacceptedAsset['acceptance']->assignedTo->locale) {
|
$locale = $unacceptedAssetGroup[0]['acceptance']->assignedTo?->locale;
|
||||||
Notification::locale(Setting::getSettings()->locale)->send(
|
$email = $unacceptedAssetGroup[0]['acceptance']->assignedTo?->email;
|
||||||
$unacceptedAsset['acceptance']->assignedTo,
|
$item_count = $unacceptedAssetGroup->count();
|
||||||
new UnacceptedAssetReminderMail($unacceptedAsset['assetItem'], $count)
|
|
||||||
);
|
if ($locale && $email) {
|
||||||
} else {
|
Mail::to($email)->send((new UnacceptedAssetReminderMail($unacceptedAssetGroup[0]['acceptance'], $item_count))->locale($locale));
|
||||||
Notification::send(
|
|
||||||
$unacceptedAsset['acceptance']->assignedTo,
|
} elseif ($email) {
|
||||||
new UnacceptedAssetReminderMail($unacceptedAsset, $item_count)
|
Mail::to($email)->send((new UnacceptedAssetReminderMail($unacceptedAssetGroup[0]['acceptance'], $item_count)));
|
||||||
);
|
|
||||||
}
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($no_mail_address)) {
|
if (!empty($no_mail_address)) {
|
||||||
foreach($no_mail_address as $user) {
|
foreach($no_mail_address as $user) {
|
||||||
return $user.' has no email.';
|
return $user.' has no email.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->info($count.' users notified.');
|
$this->info($count.' users notified.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class UnacceptedAssetReminderMail extends Mailable
|
||||||
public function __construct($checkout_info, $count)
|
public function __construct($checkout_info, $count)
|
||||||
{
|
{
|
||||||
$this->count = $count;
|
$this->count = $count;
|
||||||
$this->target = $checkout_info['acceptance']->assignedTo;
|
$this->target = $checkout_info['acceptance']?->assignedTo;
|
||||||
$this->acceptance = $checkout_info['acceptance'];
|
$this->acceptance = $checkout_info['acceptance'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class UnacceptedAssetReminderMail extends Mailable
|
||||||
markdown: 'notifications.markdown.asset-reminder',
|
markdown: 'notifications.markdown.asset-reminder',
|
||||||
with: [
|
with: [
|
||||||
'count' => $this->count,
|
'count' => $this->count,
|
||||||
'assigned_to' => $this->target->present()->fullName,
|
'assigned_to' => $this->target?->present()->fullName,
|
||||||
'link' => route('account.accept'),
|
'link' => route('account.accept'),
|
||||||
'accept_url' => $accept_url,
|
'accept_url' => $accept_url,
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue