A free open source IT asset/license management system
Fixed RB-22063 - skip alerts if alert_interval is set to null
snipe55ef4f50e07f
diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.phpindex db84784977..b81cadcdc4 100644--- a/app/Console/Commands/SendExpirationAlerts.php+++ b/app/Console/Commands/SendExpirationAlerts.php@@ -45,6 +45,14 @@ class SendExpirationAlerts extends Command{$settings = Setting::getSettings();$alert_interval = $settings->alert_interval;++ if ($alert_interval === null || (int) $alert_interval <= 0) {+ $this->info('No alert interval configured in settings. No alerts will be sent.');++ return;+ }++ $alert_interval = (int) $alert_interval;if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) {diff --git a/tests/Feature/Console/Commands/SendExpirationAlertsTest.php b/tests/Feature/Console/Commands/SendExpirationAlertsTest.phpindex 5ea8f46347..717ec62a06 100644--- a/tests/Feature/Console/Commands/SendExpirationAlertsTest.php+++ b/tests/Feature/Console/Commands/SendExpirationAlertsTest.php@@ -12,6 +12,48 @@ use Tests\TestCase;class SendExpirationAlertsTest extends TestCase{+ public function test_command_suppresses_alerts_when_alert_interval_is_null(): void+ {++ $this->settings->set([+ 'alerts_enabled' => 1,+ 'alert_email' => '[email protected]',+ 'alert_interval' => null,+ ]);++ $asset = Asset::factory()->create(['archived' => 0]);+ $asset->asset_eol_date = Carbon::now()->addDays(10);+ $asset->save();++ Mail::fake();++ $this->artisan('snipeit:expiring-alerts')+ ->expectsOutput('No alert interval configured in settings. No alerts will be sent.')+ ->assertExitCode(0);++ Mail::assertNothingSent();+ }++ public function test_command_suppresses_alerts_when_alert_interval_is_zero(): void+ {+ // Zero reads as "disabled" the same as null. The schema allows+ // either shape in practice (null from a cleared input, 0 from+ // a numeric field zeroed out).+ $this->settings->set([+ 'alerts_enabled' => 1,+ 'alert_email' => '[email protected]',+ 'alert_interval' => 0,+ ]);++ Mail::fake();++ $this->artisan('snipeit:expiring-alerts')+ ->expectsOutput('No alert interval configured in settings. No alerts will be sent.')+ ->assertExitCode(0);++ Mail::assertNothingSent();+ }+public function test_survives_transport_exception_and_logs_warning(): void{$this->settings->set([