ldc-bogt/app/Jobs/CafelMepEggJob.php

55 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Jobs;
use App\Lib\CafelApi\Models\CafelMepEgg;
use App\Models\CafelEggMiseEnPlace;
class CafelMepEggJob extends CafelJobs
{
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$dateDebut = now()->subDays(config('cafel.mises_en_places_retain', 370));
$this->syncWithCafelApi(
CafelMepEgg::class,
'cafel.ldc.mepoeufs',
[
'dateDebut' => $dateDebut->format('Y-m-d'),
'dateFin' => now()->format('Y-m-d')
],
function (array $row) {
2022-10-27 17:36:46 +02:00
// * Explode inuav
if (\array_key_exists('inuav_codes', $row)) {
$row['inuav_codes'] = explode(',', $row['inuav_codes']);
}
// * Validate row data
CafelMepEgg::validateDataRow($row);
/** @var array Unique Key columns */
$uniqueColumnsKey = [];
foreach (CafelMepEgg::UNIQUE_COLUMN_KEYS as $uField) {
$uniqueColumnsKey[$uField] = $row[$uField];
}
forward_static_call_array(
[CafelEggMiseEnPlace::class, 'updateOrCreate'],
[$uniqueColumnsKey, $row]
);
}
);
$this->mailInvalidRows(CafelMepEgg::UNIQUE_COLUMN_KEYS, CafelMepEgg::class);
// * DeleteOld MEPs
2022-06-08 16:42:14 +02:00
// * Garder une interstice de X jours entre la suppression et ce qu'on récupère de CAFEL
CafelEggMiseEnPlace::whereDate('transfert_date', '<', $dateDebut->subDays(
config('cafel.mises_en_places_retain', 370)
))->delete();
}
}