*/ $eggBreeders = CafelEggBreeder::all(); $eggBreeders->each(function (CafelEggBreeder $breeder) { $breeder->deleteOrFail(); }); $this->syncWithCafelApi( ApiCafelEggBreeder::class, 'cafel.ldc.eleveursoeufs', [], function (array $row) { // * Explode inuav if (\array_key_exists('inuavs', $row)) { $row['inuavs'] = explode(',', $row['inuavs']); } // * Validate row data ApiCafelEggBreeder::validateDataRow($row); // * Cast numeric index $row['cafel_code'] = intval($row['cafel_code']); // * Fetch pictures try { $row['path_picture_1'] = !empty($row['path_picture_1']) ? ApiCafelEggBreeder::fetchPicture( (new CafelEggBreeder())->getTable(), $row['path_picture_1'] ) : null; } catch (CafelApiImageFetchException | CafelApiException $e) { report($e); $validationException = ValidationException::withMessages([ 'path_picture_1' => $e->getMessage() ]); ToolboxHelper::useReflectionToUpdateProperty( $validationException->validator, 'data', ['path_picture_1' => $row['path_picture_1']] ); ToolboxHelper::useReflectionToUpdateProperty( $validationException->validator, 'failedRules', ['path_picture_1' => $e->getMessage()] ); throw $validationException; }//end try try { $row['path_picture_2'] = !empty($row['path_picture_2']) ? ApiCafelEggBreeder::fetchPicture( (new CafelEggBreeder())->getTable(), $row['path_picture_2'] ) : null; } catch (CafelApiImageFetchException | CafelApiException $e) { report($e); $validationException = ValidationException::withMessages([ 'path_picture_2' => $e->getMessage() ]); ToolboxHelper::useReflectionToUpdateProperty( $validationException->validator, 'data', ['path_picture_2' => $row['path_picture_2']] ); ToolboxHelper::useReflectionToUpdateProperty( $validationException->validator, 'failedRules', ['path_picture_2' => $e->getMessage()] ); throw $validationException; }//end try foreach (['exploitation', 'aboutyou', 'vocation', 'likeinjob', 'loue_means'] as $fieldName) { $row[$fieldName] = !empty($row[$fieldName]) ? $row[$fieldName] : null; } /** @var array Unique Key columns */ $uniqueColumnsKey = []; foreach (ApiCafelEggBreeder::UNIQUE_COLUMN_KEYS as $uField) { $uniqueColumnsKey[$uField] = $row[$uField]; } forward_static_call_array( [CafelEggBreeder::class, 'updateOrCreate'], [$uniqueColumnsKey, $row] ); } ); $this->mailInvalidRows(ApiCafelEggBreeder::UNIQUE_COLUMN_KEYS, ApiCafelEggBreeder::class); } }