syncWithCafelApi( ApiCafelPoultryBreeder::class, 'cafel.ldc.eleveursvolailles', [], function (array $row) { // * Explode inuav if (\array_key_exists('inuavs', $row)) { $row['inuavs'] = explode(',', $row['inuavs']); } // * Validate row data ApiCafelPoultryBreeder::validateDataRow($row); // * Cast numeric index $row['cafel_code'] = intval($row['cafel_code']); // * Fetch pictures try { $row['path_picture_1'] = !empty($row['path_picture_1']) ? ApiCafelPoultryBreeder::fetchPicture( (new CafelPoultryBreeder())->getTable(), $row['path_picture_1'] ) : null; } catch (CafelApiImageFetchException | CafelApiException $e) { report($e); $row['path_picture_1'] = null; } try { $row['path_picture_2'] = !empty($row['path_picture_2']) ? ApiCafelPoultryBreeder::fetchPicture( (new CafelPoultryBreeder())->getTable(), $row['path_picture_2'] ) : null; } catch (CafelApiImageFetchException | CafelApiException $e) { report($e); $row['path_picture_2'] = null; } foreach (['issue_1', 'issue_2'] as $fieldName) { $row[$fieldName] = !empty($row[$fieldName]) ? $row[$fieldName] : null; } /** @var array Unique Key columns */ $uniqueColumnsKey = []; foreach (ApiCafelPoultryBreeder::UNIQUE_COLUMN_KEYS as $uField) { $uniqueColumnsKey[$uField] = $row[$uField]; } forward_static_call_array( [CafelPoultryBreeder::class, 'updateOrCreate'], [$uniqueColumnsKey, $row] ); } ); $this->mailInvalidRows(ApiCafelPoultryBreeder::UNIQUE_COLUMN_KEYS, ApiCafelPoultryBreeder::class); } }