whereRaw('DATE_ADD(data_richiesta_esportazione, INTERVAL giorni_durata_esportazione DAY) < ?', [Carbon::now()->format('Y-m-d H:i:s')]); if($tenants->count() > 0) { foreach($tenants->cursor() as $tenant) { $zipFile = "{$config["mediaFolder"]}/{$tenant->codice}/esportazione.zip"; if(file_exists($zipFile)) { $this->error("Deleting tenant zip archive #{$tenant->codice}"); unlink($zipFile); } } } $tenants = Tenant::where(function($query) { $query->whereNotNull('data_richiesta_esportazione') ->orWhere('data_richiesta_esportazione', '<>', ''); })->where(function($query) { $query->where('esportazione', 'richiesta') ->orWhere('esportazione', 'in_corso'); }); if($tenants->count() > 0) { foreach($tenants->cursor() as $tenant) { // Se l'esportazione è in corso, if($tenant->esportazione == 'in_corso' // è stata richiesta da meno di due giorni && $tenant->data_richiesta_esportazione->gt(Carbon::now()->subDays(2)) // e non esiste ancora il file di esportazione && ! file_exists("{$config["mediaFolder"]}/{$tenant->codice}/esportazione.zip")) { continue; } $tenant->esportazione = 'in_corso'; $tenant->save(); $this->info("Processing tentant #{$tenant->codice}"); $this->call('export:tenant-data', ['-T' => $tenant->codice]); } } else { $this->error("No scheduled tenant exports found."); } return 0; } }