48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Notifications\SecurityReportDangerNotification;
|
|
use App\Services\SecurityReport\SecurityReportScanner;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
final class RunSecurityReportScanJob implements ShouldQueue
|
|
{
|
|
use Dispatchable;
|
|
use InteractsWithQueue;
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
public function __construct(public ?int $userId = null)
|
|
{
|
|
}
|
|
|
|
public function handle(SecurityReportScanner $scanner): void
|
|
{
|
|
if (! (bool) config('security-report.enabled', true)) {
|
|
return;
|
|
}
|
|
|
|
$report = $scanner->scan('manual', $this->userId);
|
|
|
|
if (! $report->hasDangerFindings()) {
|
|
return;
|
|
}
|
|
|
|
$email = trim((string) config('security-report.notify_email', ''));
|
|
if ($email === '') {
|
|
return;
|
|
}
|
|
|
|
Notification::route('mail', $email)
|
|
->notify(new SecurityReportDangerNotification($report));
|
|
}
|
|
}
|