option('limit'))); $ids = DB::table('documents')->whereNull('deleted_at')->where('status', '!=', 'deleted') ->where(function ($query): void { $query->whereIn('malware_scan_status', ['pending', 'inconclusive', 'failed']) ->orWhere(fn ($stale) => $stale->where('malware_scan_status', 'scanning')->where('updated_at', '<', now()->subMinutes(15))); })->orderBy('created_at')->limit($limit)->pluck('id'); $this->info(count($ids).' document(s) eligible for this batch.'); if (! $this->option('apply')) { $this->comment('Dry run only. Add --apply to dispatch scans.'); return self::SUCCESS; } foreach ($ids as $id) { if (DB::table('documents')->where('id', $id)->where('malware_scan_status', 'scanning')->exists()) { DB::table('documents')->where('id', $id)->update(['malware_scan_status' => 'pending', 'status' => 'quarantined', 'updated_at' => now()]); } ScanDocumentForMalware::dispatch((string) $id); } $this->info('Queued '.$ids->count().' scan(s). No editorial publication state was changed.'); return self::SUCCESS; } }