48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Lib\CafelApi\Models\CafelFood as ApiModelCafelFood;
|
|
use App\Models\CafelFood;
|
|
|
|
class CafelFoodJob extends CafelJobs
|
|
{
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$dateDebut = now()->subDays(config('cafel.food_retain', 30));
|
|
$this->syncWithCafelApi(
|
|
ApiModelCafelFood::class,
|
|
'cafel.ldc.aliments',
|
|
[
|
|
'dateDebut' => $dateDebut->format('Y-m-d'),
|
|
'dateFin' => now()->format('Y-m-d')
|
|
],
|
|
function (array $row) {
|
|
// * Validate row data
|
|
ApiModelCafelFood::validateDataRow($row);
|
|
|
|
/** @var array Unique Key columns */
|
|
$uniqueColumnsKey = [];
|
|
foreach (ApiModelCafelFood::UNIQUE_COLUMN_KEYS as $uField) {
|
|
$uniqueColumnsKey[$uField] = $row[$uField];
|
|
}
|
|
|
|
forward_static_call_array(
|
|
[CafelFood::class, 'updateOrCreate'],
|
|
[$uniqueColumnsKey, $row]
|
|
);
|
|
}
|
|
);
|
|
$this->mailInvalidRows(ApiModelCafelFood::UNIQUE_COLUMN_KEYS, ApiModelCafelFood::class);
|
|
|
|
// * DeleteOld Food
|
|
// * Garder une interstice de X jours entre la suppression et ce qu'on récupère de CAFEL
|
|
CafelFood::whereDate('delivery_date', '<', $dateDebut->subDays(config('cafel.food_retain', 30)))
|
|
->delete();
|
|
}
|
|
}
|