gestione gare pubbliche
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

100 righe
2.6 KiB

<?php
namespace App\Console\Commands\Export;
use Carbon\Carbon;
use App\Models\Main\Tenant;
use Illuminate\Console\Command;
$path = dirname(base_path());
include_once "{$path}/config.php";
class CheckTenantExportRequestsCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'export:check-tenant-export-requests';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check if there have been any tenant export requests';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
global $config;
$tenants = Tenant::where('esportazione', 'completa')
->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;
}
}