diff --git a/.gitignore b/.gitignore index ee8f533849..8aed658e1c 100755 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,7 @@ tests/_support/_generated/* *.cache .vagrant + +\.php_cs\.dist + +phpmd\.xml diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.php index d0d3ee1550..d10791200d 100644 --- a/app/Console/Commands/SendExpectedCheckinAlerts.php +++ b/app/Console/Commands/SendExpectedCheckinAlerts.php @@ -2,17 +2,15 @@ namespace App\Console\Commands; - use App\Models\Asset; use App\Models\Setting; -use Illuminate\Console\Command; -use App\Notifications\ExpectedCheckinNotification; use App\Notifications\ExpectedCheckinAdminNotification; +use App\Notifications\ExpectedCheckinNotification; use Carbon\Carbon; +use Illuminate\Console\Command; class SendExpectedCheckinAlerts extends Command { - /** * The console command name. * @@ -29,8 +27,6 @@ class SendExpectedCheckinAlerts extends Command /** * Create a new command instance. - * - * @return void */ public function __construct() { @@ -44,25 +40,25 @@ class SendExpectedCheckinAlerts extends Command */ public function handle() { - $settings = Setting::getSettings(); + $settings = Setting::getSettings(); $whenNotify = Carbon::now()->addDays(7); - $assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get(); + $assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get(); - $this->info($whenNotify.' is deadline'); - $this->info($assets->count().' assets'); + $this->info($whenNotify . ' is deadline'); + $this->info($assets->count() . ' assets'); foreach ($assets as $asset) { - if ($asset->assigned && $asset->checkedOutToUser()) { + if ($asset->assigned && $asset->checkedOutToUser()) { $asset->assigned->notify((new ExpectedCheckinNotification($asset))); } } - // Send a rollup to the admin, if settings dictate - $recipient = new \App\Models\Recipients\AlertRecipient(); - - if (($assets) && ($assets->count() > 0) && ($settings->alerts_enabled && $settings->alert_email != '')) { - $recipient->notify(new ExpectedCheckinAdminNotification($assets)); + if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) { + // Send a rollup to the admin, if settings dictate + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { + return new AlertRecipient($item); + }); + Notification::send($recipients, new ExpectedCheckinAdminNotification($assets)); } - } } diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index cdc62f8cc3..f78768ea5e 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -4,16 +4,14 @@ namespace App\Console\Commands; use App\Models\Asset; use App\Models\License; +use App\Models\Recipients\AlertRecipient; use App\Models\Setting; -use DB; -use App\Notifications\ExpiringLicenseNotification; use App\Notifications\ExpiringAssetsNotification; - +use App\Notifications\ExpiringLicenseNotification; use Illuminate\Console\Command; class SendExpirationAlerts extends Command { - /** * The console command name. * @@ -30,8 +28,6 @@ class SendExpirationAlerts extends Command /** * Create a new command instance. - * - * @return void */ public function __construct() { @@ -45,46 +41,35 @@ class SendExpirationAlerts extends Command */ public function handle() { - - $settings = Setting::getSettings(); + $settings = Setting::getSettings(); $threshold = $settings->alert_interval; + if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) { - // Expiring Assets - $assets = Asset::getExpiringWarrantee(Setting::getSettings()->alert_interval); - $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count'=>$assets->count(), 'threshold' => $threshold])); - - // Expiring licenses - $licenses = License::getExpiringLicenses($threshold); - - $this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count'=>$licenses->count(), 'threshold' => $threshold])); - - $recipient = new \App\Models\Recipients\AlertRecipient(); - - if ((Setting::getSettings()->alert_email!='') && ($settings->alerts_enabled==1)) { + // Send a rollup to the admin, if settings dictate + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { + return new AlertRecipient($item); + }); + // Expiring Assets + $assets = Asset::getExpiringWarrantee(Setting::getSettings()->alert_interval); if ($assets->count() > 0) { - // Send a rollup to the admin, if settings dictate - $recipient->notify(new ExpiringAssetsNotification($assets, $threshold)); + $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold])); + Notification::send($recipients, new ExpiringAssetsNotification($assets, $threshold)); } + // Expiring licenses + $licenses = License::getExpiringLicenses($threshold); if ($licenses->count() > 0) { - $recipient->notify(new ExpiringLicenseNotification($licenses, $threshold)); + $this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count' => $licenses->count(), 'threshold' => $threshold])); + Notification::send($recipients, new ExpiringLicenseNotification($licenses, $threshold)); } - - } else { - - if ($settings->alert_email=='') { + if ($settings->alert_email == '') { $this->error('Could not send email. No alert email configured in settings'); - } elseif ($settings->alerts_enabled!=1) { + } elseif (1 != $settings->alerts_enabled) { $this->info('Alerts are disabled in the settings. No mail will be sent'); } - } - - - - } } diff --git a/app/Console/Commands/SendInventoryAlerts.php b/app/Console/Commands/SendInventoryAlerts.php index 1f96fca9d1..93b04978b0 100644 --- a/app/Console/Commands/SendInventoryAlerts.php +++ b/app/Console/Commands/SendInventoryAlerts.php @@ -2,13 +2,12 @@ namespace App\Console\Commands; -use App\Models\Setting; -use DB; -use Mail; use App\Helpers\Helper; +use App\Models\Recipients\AlertRecipient; +use App\Models\Setting; use App\Notifications\InventoryAlert; - use Illuminate\Console\Command; +use Illuminate\Support\Facades\Notification; class SendInventoryAlerts extends Command { @@ -28,8 +27,6 @@ class SendInventoryAlerts extends Command /** * Create a new command instance. - * - * @return void */ public function __construct() { @@ -45,28 +42,24 @@ class SendInventoryAlerts extends Command { $settings = Setting::getSettings(); - if (($settings->alert_email!='') && ($settings->alerts_enabled==1)) { - + if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) { $items = Helper::checkLowInventory(); - // Send a rollup to the admin, if settings dictate - $recipient = new \App\Models\Recipients\AlertRecipient(); + if (($items) && (count($items) > 0)) { + $this->info(trans_choice('mail.low_inventory_alert', count($items))); + // Send a rollup to the admin, if settings dictate + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { + return new AlertRecipient($item); + }); - if (($items) && (count($items) > 0) && ($settings->alert_email!='')) { - - $this->info( trans_choice('mail.low_inventory_alert',count($items)) ); - - $recipient->notify(new InventoryAlert($items, $settings->alert_threshold)); + Notification::send($recipients, new InventoryAlert($items, $settings->alert_threshold)); } - } else { - if (Setting::getSettings()->alert_email=='') { + if ($settings->alert_email == '') { $this->error('Could not send email. No alert email configured in settings'); - } elseif (Setting::getSettings()->alerts_enabled!=1) { + } elseif (1 != $settings->alerts_enabled) { $this->info('Alerts are disabled in the settings. No mail will be sent'); } } - - } } diff --git a/app/Models/Recipients/AlertRecipient.php b/app/Models/Recipients/AlertRecipient.php index af9e3a012e..07557649c9 100644 --- a/app/Models/Recipients/AlertRecipient.php +++ b/app/Models/Recipients/AlertRecipient.php @@ -1,14 +1,11 @@ email = $settings->alert_email; + $this->email = trim($email); } - } diff --git a/app/Models/Recipients/Recipient.php b/app/Models/Recipients/Recipient.php index 888dd8e611..d04fd1f116 100644 --- a/app/Models/Recipients/Recipient.php +++ b/app/Models/Recipients/Recipient.php @@ -1,12 +1,12 @@ markdown('notifications.markdown.report-low-inventory', + $message = (new MailMessage)->markdown( + 'notifications.markdown.report-low-inventory', [ 'items' => $this->items, 'threshold' => $this->threshold, - ]) + ] + ) ->subject(trans('mail.Low_Inventory_Report')); return $message; - - } /**