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.
99 righe
3.9 KiB
99 righe
3.9 KiB
<?php |
|
|
|
namespace App\Console\Commands\Utilities; |
|
|
|
use App\Models\Main\Tenant; |
|
use Illuminate\Console\Command; |
|
use Illuminate\Support\Facades\DB; |
|
use App\Models\Tenant\Contratti\ContrattiSottoscritti; |
|
|
|
class RestoreContractsDateCommand extends Command |
|
{ |
|
/** |
|
* The name and signature of the console command. |
|
* |
|
* @var string |
|
*/ |
|
protected $signature = 'contracts:restore-upload-date'; |
|
|
|
/** |
|
* The console command description. |
|
* |
|
* @var string |
|
*/ |
|
protected $description = 'Restore the upload date of the signed contracts.'; |
|
|
|
/** |
|
* Create a new command instance. |
|
* |
|
* @return void |
|
*/ |
|
public function __construct() |
|
{ |
|
parent::__construct(); |
|
} |
|
|
|
/** |
|
* Execute the console command. |
|
* |
|
* @return int |
|
*/ |
|
public function handle() |
|
{ |
|
Tenant::whereNotNull('dominio')->where('dominio','<>','')->where('db','S')->where('codice', '>', 1420)->chunk(500, function($tenants) { |
|
|
|
$communication = DB::connection('mysql')->getDoctrineConnection()->prepare("SELECT b_comunicazioni.* |
|
FROM b_comunicazioni |
|
LEFT JOIN r_comunicazioni_utenti ON b_comunicazioni.codice = r_comunicazioni_utenti.codice_comunicazione |
|
WHERE b_comunicazioni.codice_gara = :codice_gara |
|
AND b_comunicazioni.sezione = 'contratti' |
|
AND b_comunicazioni.oggetto LIKE 'Upload Contratto%' |
|
AND r_comunicazioni_utenti.codice_ente = :codice_ente |
|
AND r_comunicazioni_utenti.codice_operatore = :codice_operatore"); |
|
|
|
|
|
foreach ($tenants as $tenant) { |
|
|
|
$communication->bindValue(':codice_ente', $tenant->codice); |
|
|
|
config(['database.connections.mysql-tenant.database' => config('json.prefix_db') . "_ente{$tenant->codice}"]); |
|
DB::purge('mysql-tenant'); |
|
|
|
$this->info("Processing: {$tenant->denominazione}"); |
|
$tenderer = DB::connection('mysql-tenant')->getDoctrineConnection()->prepare("SELECT b_contraenti.codice_operatore FROM b_contraenti WHERE codice = :codice"); |
|
|
|
|
|
ContrattiSottoscritti::where('codice_firmatario', '>', 0) |
|
->where('content', '<>', '') |
|
->where('timestamp_creazione', '<', '2024-04-22 14:00:00') |
|
->orderBy('codice', 'ASC') |
|
->chunk(500, function($contracts) use ($communication, $tenderer) { |
|
|
|
foreach ($contracts as $contract) { |
|
|
|
$this->info("Processing contract: {$contract->codice}"); |
|
|
|
$tenderer->bindValue(':codice', $contract->codice_firmatario); |
|
$signer = $tenderer->execute(); |
|
$signer = $signer->fetch(\PDO::FETCH_ASSOC); |
|
|
|
$communication->bindValue(':codice_gara', $contract->codice_contratto); |
|
$communication->bindValue(':codice_operatore', $signer["codice_operatore"]); |
|
$message = $communication->execute(); |
|
if($message->rowCount() == 1) { |
|
|
|
$message = $message->fetch(\PDO::FETCH_ASSOC); |
|
$contract->timestamp = $message["timestamp"]; |
|
$contract->save(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
} |
|
}
|
|
|