maintainPdfs($delete_pdf_days); $this->maintainBackups($delete_backup_days); } private function maintainPdfs(int $delete_pdf_days) { if($delete_pdf_days == 0) return; Invoice::with('invitations') ->whereBetween('created_at', [now()->subYear(), now()->subDays($delete_pdf_days)]) ->withTrashed() ->cursor() ->each(function ($invoice){ nlog("deleting invoice {$invoice->number}"); $invoice->service()->deletePdf(); }); Quote::with('invitations') ->whereBetween('created_at', [now()->subYear(), now()->subDays($delete_pdf_days)]) ->withTrashed() ->cursor() ->each(function ($quote){ nlog("deleting quote {$quote->number}"); $quote->service()->deletePdf(); }); Credit::with('invitations') ->whereBetween('created_at', [now()->subYear(), now()->subDays($delete_pdf_days)]) ->withTrashed() ->cursor() ->each(function ($credit){ nlog("deleting credit {$credit->number}"); $credit->service()->deletePdf(); }); } private function maintainBackups(int $delete_backup_days) { if($delete_backup_days == 0) return; Backup::where('created_at', '<', now()->subDays($delete_backup_days)) ->cursor() ->each(function ($backup){ nlog("deleting {$backup->filename}"); if($backup->filename) Storage::disk(config('filesystems.default'))->delete($backup->filename); $backup->delete(); }); } }