diff --git a/app/Console/Commands/XmlIncoReader.php b/app/Console/Commands/XmlIncoReader.php
new file mode 100644
index 0000000..6e7c53b
--- /dev/null
+++ b/app/Console/Commands/XmlIncoReader.php
@@ -0,0 +1,38 @@
+info('Running the Job, this could take some time.');
+ $job = new JobsXmlIncoReader();
+ $job->console = $this;
+ $job->handle();
+ $this->info('Job completed');
+ }
+}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 69914e9..b7ca9cc 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -25,6 +25,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
+ //$schedule->job(new XmlIncoReader)->weeklyOn(1, '8:00');
}
/**
diff --git a/app/Enums/LogType.php b/app/Enums/LogType.php
new file mode 100644
index 0000000..7b87165
--- /dev/null
+++ b/app/Enums/LogType.php
@@ -0,0 +1,21 @@
+archiveFolderName, $filename);
+ if ($this->getDisk()->exists($archiveFile)) {
+ $this->log(
+ sprintf(
+ 'File %s exists, and therefore must be delete before archive',
+ $archiveFile
+ ),
+ LogType::info()
+ );
+ if (!$this->getDisk()->delete($archiveFile)) {
+ Log::critical(sprintf('%s : Could not delete file %s', get_class($this), $archiveFile));
+ };
+ }
+
+ if (!$this->getDisk()->move($filename, sprintf('%s/%s', $this->archiveFolderName, $filename))) {
+ $this->log(
+ sprintf(
+ 'File %s could not be moved to archives',
+ $filename
+ ),
+ LogType::warning()
+ );
+ }
+ }
+
+ /**
+ * Suppression des fichiers dans
+ * archives qui ont plus de 30j
+ *
+ * @return void
+ */
+ protected function clearOldArchives(): void
+ {
+ $disk = $this->getDisk();
+ $archives = $disk->files($this->archiveFolderName);
+
+ // /** @var File */
+ foreach ($archives as $archive) {
+ $pi = \pathinfo($archive, \PATHINFO_BASENAME);
+ if (in_array($pi, $this->ignoreFiles)) {
+ continue;
+ }
+
+ if ($disk->lastModified($archive) < strtotime(Carbon::now()->subDays(30))) {
+ if (!$disk->delete($archive)) {
+ Log::critical(sprintf('%s : Could not delete file %s', get_class($this), $archive));
+ };
+ }
+ }
+ }
+
+ /**
+ * Get the concerned disk
+ *
+ * @return Filesystem
+ */
+ protected function getDisk(): Filesystem
+ {
+ return Storage::disk($this->disk);
+ }
+
+ /**
+ * Logs data
+ *
+ * @param string $message
+ * @param LogType $logtype
+ * @return void
+ */
+ protected function log(string $message, LogType $logtype = null): void
+ {
+ if (!$logtype) {
+ $logtype = LogType::debug();
+ }
+ $message = sprintf('%s : %s', get_class($this), $message);
+ switch ($logtype->value) {
+ case LogType::debug()->value:
+ Log::debug($message);
+ break;
+ case LogType::info()->value:
+ Log::info($message);
+ break;
+ case LogType::log()->value:
+ Log::log($message);
+ break;
+ case LogType::warning()->value:
+ Log::warning($message);
+ break;
+ case LogType::error()->value:
+ Log::error($message);
+ break;
+ case LogType::critical()->value:
+ Log::critical($message);
+ break;
+ default:
+ throw new Exception(sprintf('%s : unhandled log type %s', get_class($this), $logtype->label));
+ }
+ $this->consolePrint($message, $logtype);
+ }
+
+ /**
+ * Prints to the console
+ *
+ * @param string $message
+ * @param LogType $logtype
+ * @return void
+ */
+ protected function consolePrint(string $message, LogType $logtype): void
+ {
+ if ($this->console) {
+ switch ($logtype->value) {
+ case LogType::debug()->value:
+ case LogType::info()->value:
+ case LogType::log()->value:
+ $this->console->info($message);
+ break;
+ case LogType::warning()->value:
+ $this->console->comment($message);
+ break;
+ case LogType::error()->value:
+ case LogType::critical()->value:
+ $this->console->error($message);
+ break;
+ default:
+ throw new Exception(sprintf('%s : unhandled log type %s', get_class($this), $logtype->label));
+ }
+ }
+ }
+}
diff --git a/app/Jobs/XmlIncoReader.php b/app/Jobs/XmlIncoReader.php
new file mode 100644
index 0000000..3a2998e
--- /dev/null
+++ b/app/Jobs/XmlIncoReader.php
@@ -0,0 +1,463 @@
+ 'parent', // Consider this sub array
+ * puis:
+ * "PARENT.LEAF" => 'leaf', // extract this data in the line
+ * Note : Xmljobs iterates the PARENT with RecursiveIteratorIterator::LEAVES_ONLY
+ * intermediate nodes are therefore ignored
+ * example : nodes :
+ * how to extract leaves :
+ * 'EXPLOITANT' => 'exploitant', // Consider this sub array
+ * 'EXPLOITANT.ID_SOCIETE' => 'id_societe',
+ * 'EXPLOITANT.NOM_SOCIETE' => 'nom_societe',
+ */
+ protected $takeColumns = [
+ 'NO_ART' => 'id', // primary key on model
+
+ //this wil not return anything cf doc above
+ 'ID_SOCIETE' => 'id_societe',
+ 'NOM_SOCIETE' => 'nom_societe',
+
+ 'PROD_SAISON' => 'prod_saison',
+ 'NOM' => 'nom',
+ 'NUMERO' => 'numero',
+ 'TAILLE_REF' => 'taille_ref', //$poidsRef censé être dans INCO_COMPO (et généralement 100g)
+ 'ALLEGATIONS' => 'allegations',
+ 'CONSEIL_PREPA' => 'conseil_prepa',
+ 'ASTUCES' => 'astuces',
+ 'DESCRIPTIF' => 'descriptif', //$descriptif
+ 'ARG_VENTE' => 'arg_vente',
+ 'NB_PORTION' => 'nb_portion',
+ 'TYP_PORTION' => 'typ_portion',
+ 'PDS_MOY_THEO' => 'pds_moy_theo',
+ 'LIB_CONSO' => 'lib_conso',
+ 'LST_ING' => 'lst_ing', //$ingredients
+
+ // list alergene
+ 'LST_ALLERGENE' => 'lst_allergene', // Consider this sub array
+ 'LST_ALLERGENE.LIB_ALLERGENE' => 'lib_allergene',
+
+ // Allegations
+ 'ALLEGAT_SANTE' => 'allegat_sante',
+ 'ALLEGAT_NUTRIT' => 'allegat_nutrit',
+ 'ALLEGAT_AUTRE' => 'allegat_autre',
+
+
+ 'INCO_COMPO' => 'inco_compo', // Consider this sub array
+ 'INCO_COMPO.TAILLE_REF' => 'taille_ref',
+ 'INCO_COMPO.VAL_ENERG_KJ_NUT' => 'val_energ_kj_nut',
+ 'INCO_COMPO.VAL_ENERG_KJ_R' => 'val_energ_kj_r', //_R apports de la taille_ref
+ 'INCO_COMPO.VAL_ENERG_KCAL_R' => 'val_energ_kcal_r',
+ 'INCO_COMPO.VAL_ENERG_KCAL_NUT' => 'val_energ_kcal_nut',
+ 'INCO_COMPO.MAT_GRASS_R' => 'mat_grass_r',
+ 'INCO_COMPO.MAT_GRASS_NUT' => 'mat_grass_nut',
+ 'INCO_COMPO.AGS_R' => 'ags_r',
+ 'INCO_COMPO.AGS_NUT' => 'ags_nut',
+ 'INCO_COMPO.GLUCIDES_R' => 'glucides_r',
+ 'INCO_COMPO.GLUCIDES_NUT' => 'glucides_nut',
+ 'INCO_COMPO.SUCRE_NUT' => 'sucre_nut',
+ 'INCO_COMPO.SUCRE_R' => 'sucre_r',
+ 'INCO_COMPO.FIB_ALIM_NUT' => 'fib_alim_nut',
+ 'INCO_COMPO.FIB_ALIM_R' => 'fib_alim_r',
+ 'INCO_COMPO.PROTEINE_R' => 'proteine_r',
+ 'INCO_COMPO.PROTEINE_NUT' => 'proteine_nut',
+ 'INCO_COMPO.SEL_R' => 'sel_r',
+ 'INCO_COMPO.SEL_NUT' => 'sel_nut',
+ 'INCO_COMPO.SODIUM_R' => 'sodium_r',
+ 'INCO_COMPO.ENER_E14_R' => 'ener_e14_r',
+ 'INCO_COMPO.FRUITS_R' => 'fruits_r',
+ 'INCO_COMPO.FRUITS_COQUE_SECH_R' => 'fruits_coque_sech_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_E14_R' => 'pourcent_apport_ref_e14_r', //POURCENT_*_P apports journaliers par portion
+ 'INCO_COMPO.ENER_KJO_R' => 'ener_kjo_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_KJO_R' => 'pourcent_apport_ref_kjo_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_FAT_R' => 'pourcent_apport_ref_fat_r',
+ 'INCO_COMPO.FATSAT_R' => 'fatsat_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_FATSAT_R' => 'pourcent_apport_ref_fatsat_r',
+ 'INCO_COMPO.CHOVAL_R' => 'choval_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_CHOVAL_R' => 'pourcent_apport_ref_choval_r',
+ 'INCO_COMPO.SUGAR_R' => 'sugar_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_SUGAR_R' => 'pourcent_apport_ref_sugar_r',
+ 'INCO_COMPO.FIBTG_R' => 'fibtg_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_FIBTG_R' => 'pourcent_apport_ref_fibtg_r',
+ 'INCO_COMPO.PRO_R' => 'pro_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_PRO_R' => 'pourcent_apport_ref_pro_r',
+ 'INCO_COMPO.SALTEQ_R' => 'salteq_r',
+ 'INCO_COMPO.POURCENT_APPORT_REF_SALTEQ_R' => 'pourcent_apport_ref_salteq_r',
+ 'INCO_COMPO.APPORT_REF' => 'apport_ref',
+ 'INCO_COMPO.TAILLE_PORT' => 'taille_port', //$poidsPortion
+ 'INCO_COMPO.VAL_ENERG_KJ_P' => 'val_energ_kj_p', //_P apports par portion
+ 'INCO_COMPO.VAL_ENERG_KCAL_P' => 'val_energ_kcal_p',
+ 'INCO_COMPO.MAT_GRASS_P' => 'mat_grass_p',
+ 'INCO_COMPO.AGS_P' => 'ags_p',
+ 'INCO_COMPO.GLUCIDES_P' => 'glucides_p',
+ 'INCO_COMPO.SUCRE_P' => 'sucre_p',
+ 'INCO_COMPO.FIB_ALIM_P' => 'fib_alim_p',
+ 'INCO_COMPO.PROTEINE_P' => 'proteine_p',
+ 'INCO_COMPO.SODIUM_P' => 'sodium_p',
+ 'INCO_COMPO.FRUITS_P' => 'fruits_p',
+ 'INCO_COMPO.SEL_P' => 'sel_p',
+ 'INCO_COMPO.FRUITS_COQUE_SECH_P' => 'fruits_coque_sech_p',
+ 'INCO_COMPO.ENER_E14_P' => 'ener_e14_p',
+ 'INCO_COMPO.POURCENT_APPORT_REF_E14_P' => 'pourcent_apport_ref_e14_p',
+ 'INCO_COMPO.ENER_KJO_P' => 'ener_kjo_p',
+ 'INCO_COMPO.POURCENT_APPORT_REF_KJO_P' => 'pourcent_apport_ref_kjo_p',
+ 'INCO_COMPO.FAT_P' => 'fat_p',
+ 'INCO_COMPO.POURCENT_APPORT_REF_FAT_P' => 'pourcent_apport_ref_fat_p',
+ 'INCO_COMPO.FATSAT_P' => 'fatsat_p',
+ 'INCO_COMPO.POURCENT_APPORT_REF_FATSAT_P' => 'pourcent_apport_ref_fatsat_p',
+ 'INCO_COMPO.CHOVAL_P' => 'CHOVAL_P',
+ 'INCO_COMPO.POURCENT_APPORT_REF_CHOVAL_P' => 'pourcent_apport_ref_choval_p',
+ 'INCO_COMPO.SUGAR_P' => 'SUGAR_P',
+ 'INCO_COMPO.POURCENT_APPORT_REF_SUGAR_P' => 'pourcent_apport_ref_sugar_p',
+ 'INCO_COMPO.FIBTG_P' => 'fibtg_p',
+ 'INCO_COMPO.POURCENT_APPORT_REF_FIBTG_P' => 'pourcent_apport_ref_fibtg_p',
+ 'INCO_COMPO.PRO_P' => 'pro_p',
+ 'INCO_COMPO.POURCENT_APPORT_REF_PRO_P' => 'pourcent_apport_ref_pro_p',
+ 'INCO_COMPO.SALTEQ_P' => 'salteq_p',
+ 'INCO_COMPO.POURCENT_APPORT_REF_SALTEQ_P' => 'pourcent_apport_ref_salteq_p',
+ 'INCO_COMPO.APPORT_PORT' => 'apport_port',
+ 'INCO_COMPO.PART_P' => 'part_p',
+ 'INCO_COMPO.PART_G' => 'part_g',
+ 'INCO_COMPO.PART_L' => 'part_l',
+ 'INCO_COMPO.P_SUR_L' => 'p_sur_l',
+ 'INCO_COMPO.POURCENT_AGS' => 'pourcent_ags',
+ 'INCO_COMPO.POURCENT_AGI' => 'pourcent_agi',
+ 'INCO_COMPO.POURCENT_SS' => 'pourcent_ss',
+ 'INCO_COMPO.POURCENT_AMIDON' => 'pourcent_amidon',
+ 'INCO_COMPO.COMPOSANTE_N' => 'composante_n',
+ 'INCO_COMPO.COMPOSANTE_P' => 'composante_p',
+ 'INCO_COMPO.POURCENT_FRUITS' => 'pourcent_fruits',
+ 'INCO_COMPO.SCORE_NUTRI' => 'score_nutri', //du coup nutriscore ?
+ 'INCO_COMPO.CLASSEMENT' => 'classement', //$nutriscore mais pas censé être dans INCO_COMPO
+ 'INCO_COMPO.MAT_GRASS_R_PREC' => 'mat_grass_r_prec',
+ 'INCO_COMPO.AGS_R_PREC' => 'ags_r_prec',
+ 'INCO_COMPO.GLUCIDES_R_PREC' => 'glucides_r_prec',
+ 'INCO_COMPO.SUCRE_R_PREC' => 'sucre_r_prec',
+ 'INCO_COMPO.FIB_ALIM_R_PREC' => 'fib_alim_r_prec',
+ 'INCO_COMPO.PROTEINE_R_PREC' => 'proteine_r_prec',
+ 'INCO_COMPO.SEL_R_PREC' => 'sel_r_prec',
+ 'INCO_COMPO.SODIUM_R_PREC' => 'sodium_r_prec',
+ 'INCO_COMPO.FRUITS_R_PREC' => 'fruits_r_prec',
+ 'INCO_COMPO.FRUITS_COQUE_SECH_R_PREC' => 'fruits_coque_sech_r_prec',
+ ];
+
+ protected $nullableFields = [
+ 'taille_ref',
+ 'conseil_prepa',
+ 'typ_portion',
+ 'nb_portion',
+ 'descriptif',
+ 'prod_saison',
+ 'allegations',
+ 'astuces', 'arg_vente',
+ 'pds_moy_theo',
+ 'lib_conso', 'lst_ing',
+ 'allegat_sante', 'allegat_nutrit', 'allegat_autre',
+ 'inco_compo',
+ 'inco_compo.nom',
+ 'inco_compo.numero',
+ 'inco_compo.taille',
+ 'inco_compo.taille_ref',
+ 'inco_compo.val_energ_kj_nut',
+ 'inco_compo.val_energ_kj_r',
+ 'inco_compo.val_energ_kcal_r',
+ 'inco_compo.val_energ_kcal_nut',
+ 'inco_compo.mat_grass_r',
+ 'inco_compo.mat_grass_nut',
+ 'inco_compo.ags_r',
+ 'inco_compo.ags_nut',
+ 'inco_compo.glucides_r',
+ 'inco_compo.glucides_nut',
+ 'inco_compo.sucre_nut',
+ 'inco_compo.sucre_r',
+ 'inco_compo.fib_alim_nut',
+ 'inco_compo.fib_alim_r',
+ 'inco_compo.proteine_r',
+ 'inco_compo.proteine_nut',
+ 'inco_compo.sel_r',
+ 'inco_compo.sel_nut',
+ 'inco_compo.sodium_r',
+ 'inco_compo.ener_e14_r',
+ 'inco_compo.fruits_r',
+ 'inco_compo.fruits_coque_sech_r',
+ 'inco_compo.pourcent_apport_ref_e14_r',
+ 'inco_compo.ener_kjo_r',
+ 'inco_compo.pourcent_apport_ref_kjo_r',
+ 'inco_compo.pourcent_apport_ref_fat_r',
+ 'inco_compo.fatsat_r',
+ 'inco_compo.pourcent_apport_ref_fatsat_r',
+ 'inco_compo.choval_r',
+ 'inco_compo.pourcent_apport_ref_choval_r',
+ 'inco_compo.sugar_r',
+ 'inco_compo.pourcent_apport_ref_sugar_r',
+ 'inco_compo.fibtg_r',
+ 'inco_compo.pourcent_apport_ref_fibtg_r',
+ 'inco_compo.pro_r',
+ 'inco_compo.pourcent_apport_ref_pro_r',
+ 'inco_compo.salteq_r',
+ 'inco_compo.pourcent_apport_ref_salteq_r',
+ 'inco_compo.apport_ref',
+ 'inco_compo.taille_port',
+ 'inco_compo.val_energ_kj_p',
+ 'inco_compo.val_energ_kcal_p',
+ 'inco_compo.mat_grass_p',
+ 'inco_compo.ags_p',
+ 'inco_compo.glucides_p',
+ 'inco_compo.sucre_p',
+ 'inco_compo.fib_alim_p',
+ 'inco_compo.proteine_p',
+ 'inco_compo.sodium_p',
+ 'inco_compo.fruits_p',
+ 'inco_compo.sel_p',
+ 'inco_compo.fruits_coque_sech_p',
+ 'inco_compo.ener_e14_p',
+ 'inco_compo.pourcent_apport_ref_e14_p',
+ 'inco_compo.ener_kjo_p',
+ 'inco_compo.pourcent_apport_ref_kjo_p',
+ 'inco_compo.fat_p',
+ 'inco_compo.pourcent_apport_ref_fat_p',
+ 'inco_compo.fatsat_p',
+ 'inco_compo.pourcent_apport_ref_fatsat_p',
+ 'inco_compo.choval_p',
+ 'inco_compo.pourcent_apport_ref_choval_p',
+ 'inco_compo.sugar_p',
+ 'inco_compo.pourcent_apport_ref_sugar_p',
+ 'inco_compo.fibtg_p',
+ 'inco_compo.pourcent_apport_ref_fibtg_p',
+ 'inco_compo.pro_p',
+ 'inco_compo.pourcent_apport_ref_pro_p',
+ 'inco_compo.salteq_p',
+ 'inco_compo.pourcent_apport_ref_salteq_p',
+ 'inco_compo.apport_port',
+ 'inco_compo.part_p',
+ 'inco_compo.part_g',
+ 'inco_compo.part_l',
+ 'inco_compo.p_sur_l',
+ 'inco_compo.pourcent_ags',
+ 'inco_compo.pourcent_agi',
+ 'inco_compo.pourcent_ss',
+ 'inco_compo.pourcent_amidon',
+ 'inco_compo.composante_n',
+ 'inco_compo.composante_p',
+ 'inco_compo.pourcent_fruits',
+ 'inco_compo.score_nutri',
+ 'inco_compo.classement',
+ 'inco_compo.mat_grass_r_prec',
+ 'inco_compo.ags_r_prec',
+ 'inco_compo.glucides_r_prec',
+ 'inco_compo.sucre_r_prec',
+ 'inco_compo.fib_alim_r_prec',
+ 'inco_compo.proteine_r_prec',
+ 'inco_compo.sel_r_prec',
+ 'inco_compo.sodium_r_prec',
+ 'inco_compo.fruits_r_prec',
+ 'inco_compo.fruits_coque_sech_r_prec'
+ ];
+
+ protected $uniqueKeyField = ['id'];
+
+ protected $mergeColumns = [
+ 'allegations' => [
+ 'allegat_sante',
+ 'allegat_nutrit',
+ 'allegat_autre'
+ ],
+ 'nutritional_values' => [
+ 'taille_ref',
+ 'val_energ_kj_nut',
+ 'val_energ_kj_r',
+ 'val_energ_kcal_r',
+ 'val_energ_kcal_nut',
+ 'mat_grass_r',
+ 'mat_grass_nut',
+ 'ags_r',
+ 'ags_nut',
+ 'glucides_r',
+ 'glucides_nut',
+ 'sucre_nut',
+ 'sucre_r',
+ 'fib_alim_nut',
+ 'fib_alim_r',
+ 'proteine_r',
+ 'proteine_nut',
+ 'sel_r',
+ 'sel_nut',
+ 'sodium_r',
+ 'ener_e14_r',
+ 'fruits_r',
+ 'fruits_coque_sech_r',
+ 'pourcent_apport_ref_e14_r',
+ 'ener_kjo_r',
+ 'pourcent_apport_ref_kjo_r',
+ 'pourcent_apport_ref_fat_r',
+ 'fatsat_r',
+ 'pourcent_apport_ref_fatsat_r',
+ 'choval_r',
+ 'pourcent_apport_ref_choval_r',
+ 'sugar_r',
+ 'pourcent_apport_ref_sugar_r',
+ 'fibtg_r',
+ 'pourcent_apport_ref_fibtg_r',
+ 'pro_r',
+ 'pourcent_apport_ref_pro_r',
+ 'salteq_r',
+ 'pourcent_apport_ref_salteq_r',
+ 'apport_ref',
+ 'taille_port',
+ 'val_energ_kj_p',
+ 'val_energ_kcal_p',
+ 'mat_grass_p',
+ 'ags_p',
+ 'glucides_p',
+ 'sucre_p',
+ 'fib_alim_p',
+ 'proteine_p',
+ 'sodium_p',
+ 'fruits_p',
+ 'sel_p',
+ 'fruits_coque_sech_p',
+ 'ener_e14_p',
+ 'pourcent_apport_ref_e14_p',
+ 'ener_kjo_p',
+ 'pourcent_apport_ref_kjo_p',
+ 'fat_p',
+ 'pourcent_apport_ref_fat_p',
+ 'fatsat_p',
+ 'pourcent_apport_ref_fatsat_p',
+ 'choval_p',
+ 'pourcent_apport_ref_choval_p',
+ 'sugar_p',
+ 'pourcent_apport_ref_sugar_p',
+ 'fibtg_p',
+ 'pourcent_apport_ref_fibtg_p',
+ 'pro_p',
+ 'pourcent_apport_ref_pro_p',
+ 'salteq_p',
+ 'pourcent_apport_ref_salteq_p',
+ 'apport_port',
+ 'part_p',
+ 'part_g',
+ 'part_l',
+ 'p_sur_l',
+ 'pourcent_ags',
+ 'pourcent_agi',
+ 'pourcent_ss',
+ 'pourcent_amidon',
+ 'composante_n',
+ 'composante_p',
+ 'pourcent_fruits',
+ 'score_nutri',
+ 'classement',
+ 'mat_grass_r_prec',
+ 'ags_r_prec',
+ 'glucides_r_prec',
+ 'sucre_r_prec',
+ 'fib_alim_r_prec',
+ 'proteine_r_prec',
+ 'sel_r_prec',
+ 'sodium_r_prec',
+ 'fruits_r_prec',
+ 'fruits_coque_sech_r_prec',
+ ]
+ ];
+
+ public function handle()
+ {
+
+ $this->parseData('INCO', XmlInco::class, function (SimpleXMLElement $xmlData, array &$line) {
+
+ // merge columns
+ foreach ($this->mergeColumns as $key => $values) {
+ $line[$key] = [];
+ // merge columns and remove merged columns from line
+ array_map(function ($kValue) use (&$line, $key) {
+ if (array_key_exists($kValue, $line)) {
+ $line[$key][$kValue] = $line[$kValue];
+ unset($line[$kValue]);
+ }
+ }, $values);
+ if ($key == 'allegations') {
+ $line[$key] = implode(',', array_filter($line[$key]));
+ $line[$key] = strlen($line[$key]) ? $line[$key] : null;
+ }
+ //json column cast into array in model => no need for encode
+ // if ($key == 'nutritional_values') {
+ // $line[$key] = json_encode($line[$key], \JSON_FORCE_OBJECT);
+ // }
+ }
+
+ // Boolean cast prod_saison
+ $line['prod_saison'] = isset($line['prod_saison']) ?
+ (strtolower($line['prod_saison']) == 'non' ? false : true) : false;
+
+ $arImgPaths = $this->parseImage($xmlData);
+ $line['picture'] = $arImgPaths;
+ });
+ }
+
+ private function parseImage(SimpleXMLElement $xmlData)
+ {
+ $images = $xmlData->INCO->MEDIA_VISUEL_EAI->MEDIA_VISUEL_EAI;
+ $arImgPaths = array();
+ $index = 1;
+
+ foreach ($images as $image) {
+ $imageData = trim((string)$image);
+ if (strlen($imageData)) {
+ $imageData = base64_decode($imageData);
+ $imgName = strval($xmlData->INCO->INCO_COMPO->TBL_INCO_COMPO->ID_INCO);
+ if(empty($imgName)) {
+ $imgName = strval($xmlData->INCO->NO_ART);
+ }
+ $imgName = $imgName."_".$index;
+ $imgNamePath = sprintf('%s/%s', rtrim($this->imagesPath, '/'), $imgName);
+
+ $disk = $this->getDisk();
+
+ $info = getimagesizefromstring($imageData);
+ $mime = $info['mime'];
+ switch ($mime) {
+ case 'image/jpeg':
+ $imgExtension = 'jpg';
+ break;
+ case 'image/png':
+ $imgExtension = 'png';
+ break;
+ case 'image/gif':
+ $imgExtension = 'gif';
+ break;
+ default:
+ throw new AbortXmlImportException(sprintf('Unknown image type %s', $imgName));
+ }
+
+ $imgNamePath = sprintf('%s.%s', $imgNamePath, $imgExtension);
+
+ if (!$disk->put($imgNamePath, $imageData)) {
+ throw new AbortXmlImportException(sprintf('The image %s could not be saved', $imgNamePath));
+ }
+
+ $arImgPaths[$index] = sprintf('%s/%s', $this->disk, $imgNamePath);
+ $index++;
+ }
+ }
+
+ return $arImgPaths;
+ }
+}
diff --git a/app/Jobs/XmlJobs.php b/app/Jobs/XmlJobs.php
new file mode 100644
index 0000000..d87ef6d
--- /dev/null
+++ b/app/Jobs/XmlJobs.php
@@ -0,0 +1,379 @@
+getDisk();
+ $this->log('Démarrage du traitement');
+ $files = $disk->files();
+
+ $progress = 1;
+ $total = count(array_filter($files, function ($filename) {
+ if ($this->fileHasToBeIgnored($filename)) {
+ return false;
+ }
+ return true;
+ }));
+
+ foreach ($files as $filename) {
+ if ($this->fileHasToBeIgnored($filename)) {
+ continue;
+ }
+
+ $this->log(sprintf(' traitement %d sur %s ', $progress++, $total));
+
+ try {
+ /** @var string $data */
+ $data = $disk->get($filename);
+ try {
+ if ($this->encapsulate) {
+ $data = sprintf('%s', $data);
+ /** @var SimpleXMLElement|false */
+ $xmlContent = simplexml_load_string($data);
+ } else {
+ /** @var SimpleXMLElement|false */
+ $xmlContent = simplexml_load_string($data, null, LIBXML_NOCDATA | LIBXML_PARSEHUGE);
+ }
+
+ if ($xmlContent === false) {
+ throw new InvalidXmlException('XML is Invalid (simplexml_load_string returned false)');
+ // $this->log(
+ // sprintf('File %s could not be parsed (simplexml_load_string)', $filename),
+ // LogType::critical()
+ // );
+ // continue; // ignore the file
+ }
+ } catch (ErrorException $e) {
+ throw new InvalidXmlException('XML is Invalid', 0, $e);
+ }
+
+ $data = $this->extract($xmlContent);
+
+ $lines = [];
+ foreach ($data[$entityName] as $traca) {
+ $line = $this->processFields($traca);
+ if ($callback) {
+ $callback($xmlContent, $line);
+ }
+ $lines[] = $line;
+ }
+
+ // Mise en base des données
+ foreach ($lines as $line) {
+ /** @var array Unique Key columns */
+ $uniqueColumnsKey = [];
+ foreach ($this->uniqueKeyField as $uField) {
+ $uniqueColumnsKey[$uField] = $line[$uField];
+ }
+ $savedData = forward_static_call_array(
+ [$modelClass, 'updateOrCreate'],
+ [$uniqueColumnsKey, $line]
+ );
+ // @todo : should we put that method in a interface ?
+ $savedData->updateLocalProductInfo();
+ }
+ } catch (InvalidXmlException $e) {
+ $message = $e->getMessage();
+ if (get_class($e) === QueryException::class) {
+ $message = implode(' ', $e->errorInfo);
+ }
+ $this->log(
+ sprintf(
+ 'File %s could not be parsed => %s on line %d',
+ $filename,
+ $message,
+ $e->getLine()
+ ),
+ LogType::critical()
+ );
+ $this->sendInvalidXmlEmail($filename, $e);
+ $this->moveToInvalid($filename);
+ continue;
+ } catch (ErrorException | TypeError $e) {
+ $this->log(
+ sprintf(
+ 'CRITICAL: File %s could not be parsed => %s on line %d',
+ $filename,
+ $e->getMessage(),
+ $e->getLine()
+ ),
+ LogType::critical()
+ );
+ $this->sendErrorParseEmailToServiceWeb($e);
+ continue; // ignore the file
+ } catch (AbortXmlImportException $e) {
+ $this->log(
+ sprintf(
+ 'ERROR: File %s could not be parsed => %s on line %d',
+ $filename,
+ $e->getMessage(),
+ $e->getLine()
+ ),
+ LogType::error()
+ );
+ $this->sendErrorParseEmailToServiceWeb($e);
+ $this->moveToInvalid($filename);
+ continue; // ignore the file
+ } catch (FileNotFoundException | QueryException $e) {
+ // This happens because of concurent xml jobs read
+ $message = $e->getMessage();
+ if (get_class($e) === QueryException::class) {
+ $message = implode(' ', $e->errorInfo);
+ }
+ $this->log(
+ sprintf(
+ 'ERROR: File %s could not be read (not found) => %s on line %d',
+ $filename,
+ $message,
+ $e->getLine()
+ ),
+ LogType::debug()
+ );
+ continue; // ignore the file
+ }
+ $this->moveToArchives($filename);
+ }
+
+ // Clear old archives
+ $this->clearOldArchives();
+ }
+
+ /**
+ * Recursive extract to array
+ *
+ * @param \SimpleXMLElement|false $sxe
+ * @return array
+ */
+ protected function extract($sxe = null): array
+ {
+ if (!$sxe instanceof SimpleXMLElement) {
+ return array();
+ }
+ $extract = array();
+ foreach ($sxe->children() as $key => $value) {
+ if ($value->count()) {
+ $extract[$key][] = $this->extract($value);
+ continue;
+ }
+ $value = strval($value);
+ if (array_key_exists($key, $extract) and is_array($extract[$key])) {
+ $extract[$key][] = strlen($value) ? $value : null;
+ } else {
+ $extract[$key] = strlen($value) ? $value : null;
+ }
+ }
+ return $extract;
+ }
+
+ /**
+ * Process fields to gather data
+ *
+ * @param array $fields
+ * @return array
+ * @throws AbortXmlImportException
+ */
+ protected function processFields(array $fields): array
+ {
+ $result = [];
+ foreach ($fields as $key => $field) {
+ if (!($key = $this->shouldFieldBeConsidered($key))) {
+ continue;
+ }
+ if (!$this->isFieldNullable($key) && is_null($field)) {
+ throw new AbortXmlImportException(sprintf('The field %s is not allowed to be null', $key));
+ }
+ if (is_array($field)) {
+ // Flatten data
+ $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($field));
+ foreach ($it as $k => $f) {
+ $ko = strtolower(sprintf('%s.%s', $key, $k));
+ if (!$this->isFieldNullable($ko) && is_null($f)) {
+ throw new AbortXmlImportException(sprintf(
+ '%s : The field %s is not allowed to be null',
+ get_class($this),
+ $ko
+ ));
+ }
+ if (!($k = $this->shouldFieldBeConsidered($ko))) {
+ continue;
+ }
+ $result[$k] = $f;
+ }
+ } else {
+ $result[$key] = $field;
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Is the filed nullable
+ *
+ * @param string $key
+ * @return boolean
+ */
+ private function isFieldNullable(string $key): bool
+ {
+ if (in_array($key, $this->nullableFields)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * - replace key name with the corresponding alias
+ * - strtolower the key
+ * - snake_case the key
+ *
+ * @param string $key
+ * @return string|false
+ */
+ private function shouldFieldBeConsidered(string $key)
+ {
+ $key = strtolower($key);
+ foreach ($this->takeColumns as $k => $alias) {
+ if (strtolower($k) === $key) {
+ return Str::snake(strtolower($alias));
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Is the file to be ignored
+ *
+ * @param string $filename
+ * @return boolean
+ */
+ protected function fileHasToBeIgnored(string $filename): bool
+ {
+ return in_array($filename, $this->ignoreFiles) or !$this->checkExtension($filename, 'xml');
+ }
+
+ /**
+ * Check if the file is an xml file
+ *
+ * @param string $filename
+ * @return boolean
+ */
+ protected function isFileXml(string $filename): bool
+ {
+ $isXml = strtolower(pathinfo($filename, \PATHINFO_EXTENSION)) === 'xml';
+ if (!$isXml) {
+ Log::warning(sprintf('%s : unwanted file type in %s', get_class($this), $filename));
+ }
+ return $isXml;
+ }
+
+ protected function sendErrorParseEmailToServiceWeb(Throwable $e)
+ {
+ Mail::send('emails.exception', [
+ 'exception' => $e,
+ 'appName' => config('app.name'),
+ ], function ($m) {
+ $m->to(
+ config('mail.contactsList.serviceweb'),
+ sprintf('%s Exception Handler', config('app.name'))
+ )->subject('Could not eat INCO, because of its toxicity !');
+ });
+ }
+
+ protected function sendInvalidXmlEmail(string $filename, Throwable $e)
+ {
+ $message = $e->getPrevious()->getMessage();
+ Mail::send('emails.invalidxml', [
+ 'strError' => sprintf(
+ 'File %s could not be parsed => %s on line %d',
+ $filename,
+ $message,
+ $e->getLine()
+ ),
+ 'appName' => config('app.name'),
+ 'filename' => $filename,
+ 'exception' => $e->getPrevious()
+ ], function ($m) {
+ $m->to(
+ config('mail.contactsList.invalidInco'),
+ sprintf('%s Exception Handler', config('app.name'))
+ )->subject('You sent me an invalid XML file, please check its validity before resend ASAP.');
+ });
+ }
+
+ /**
+ * Move the file to invalid folder
+ *
+ * @param string $filename
+ * @return void
+ */
+ protected function moveToInvalid(string $filename): void
+ {
+ if (!$this->getDisk()->move($filename, sprintf('%s/%s', $this->invalidFolderName, $filename))) {
+ $this->log(
+ sprintf(
+ 'File %s could not be moved to invalid folder name',
+ $filename
+ ),
+ LogType::warning()
+ );
+ }
+ }
+}
diff --git a/app/Models/XmlInco.php b/app/Models/XmlInco.php
new file mode 100644
index 0000000..f33346b
--- /dev/null
+++ b/app/Models/XmlInco.php
@@ -0,0 +1,235 @@
+ 'array',
+ 'nutritional_values' => 'array',
+ ];
+
+ /**
+ * The Laravel disk name
+ *
+ * @var string
+ */
+ protected $disk = 'inco';
+
+ protected $imagesPath = 'images';
+
+ /**
+ * The files to ignore
+ *
+ * @var array
+ */
+ protected $ignoreFiles = [
+ '.gitignore', '.gitkeep'
+ ];
+
+ /**
+ * retrieve a collection of medias
+ */
+ public function getMediasAttribute() {
+ /** @var Filesystem */
+ $disk = $this->getDisk();
+ $files = $disk->files($this->imagesPath);
+
+ $collFiles = new Collection();
+ // /** @var File */
+ foreach ($files as $file) {
+ $pi = \pathinfo($file, \PATHINFO_BASENAME);
+ if (in_array($pi, $this->ignoreFiles)) {
+ continue;
+ }
+ if (!in_array($pi, array($this->id))) {
+ continue;
+ }
+ $image = base64_encode($disk->get($file));
+ $element = array(
+ "filename" => $pi,
+ "imgdata" => $image
+ );
+ $collFiles->add($element);
+ }
+ return $collFiles;
+ }
+
+ /**
+ * Get the concerned disk
+ *
+ * @return Filesystem
+ */
+ protected function getDisk(): Filesystem
+ {
+ return Storage::disk($this->disk);
+ }
+
+ public function getNiceStringAttribute()
+ {
+ return sprintf('%s - %s', $this->id, $this->descriptif);
+ }
+
+ public function updateLocalProductInfo()
+ {
+ $foodProduct = FoodProduct::where('no_art', $this->id)->first();
+
+ if (!empty($foodProduct)) {
+ //info produits à suggerer lors de l'édition
+ // this->descriptif (doit aller dans la table products)
+ // $table->text('preparation')->nullable(); => $this->conseil_prepa
+ // $table->text('selling_argument')->nullable(); => $this->arg_vente
+
+ //infos produit maj automatique
+ $foodProduct->ingredients = $this->lst_ing;
+ $foodProduct->allergens = $this->lib_allergene;
+ //$foodProduct->servings = $this->nb_portion; // problem les types de correspondent pas numeric = string (exemple this->nb_portion = '1/2')
+
+ $nutri_values = $this->nutritional_values;
+ if (!empty($nutri_values)) {
+ //maj des info nutri locales
+ //pour la ref
+ $foodProduct->nv_ref_weight_g = $nutri_values["taille_ref"];
+ $foodProduct->nv_kj = $nutri_values["val_energ_kj_r"]; //Energie Kj
+ $foodProduct->nv_kcal = $nutri_values["val_energ_kcal_r"]; //Energie Kcal
+ $foodProduct->nv_fat_g = $nutri_values["mat_grass_r"]; //graisses
+ $foodProduct->nv_sat_fat_g = $nutri_values["ags_r"]; //dont acides gras saturés
+ $foodProduct->nv_carb_g = $nutri_values["glucides_r"]; //Glucides
+ $foodProduct->nv_sugar_g = $nutri_values["sucre_r"]; //dont sucres
+ $foodProduct->nv_fiber_g = $nutri_values["fib_alim_r"]; //fibres alimentaires
+ $foodProduct->nv_protein_g = $nutri_values["proteine_r"]; //protéines
+ $foodProduct->nv_salt_g = $nutri_values["sel_r"]; //sel
+
+ // $foodProduct-> = $nutri_values["sodium_r"];
+ // $foodProduct-> = $nutri_values["ener_e14_r"];
+ // $foodProduct-> = $nutri_values["fruits_r"];
+ // $foodProduct-> = $nutri_values["fruits_coque_sech_r"];
+ // $foodProduct-> = $nutri_values["ener_kjo_r"];
+ // $foodProduct-> = $nutri_values["fatsat_r"];
+ // $foodProduct-> = $nutri_values["choval_r"];
+ // $foodProduct-> = $nutri_values["sugar_r"];
+ // $foodProduct-> = $nutri_values["fibtg_r"];
+ // $foodProduct-> = $nutri_values["pro_r"];
+ // $foodProduct-> = $nutri_values["salteq_r"];
+
+
+ //valeurs nutritionnelles par portion
+ $foodProduct->nv_serving_size_g = $nutri_values["taille_port"]; //taille portion en grammes
+ $foodProduct->nv_serving_kj = $nutri_values["val_energ_kj_p"]; //Energie Kj
+ $foodProduct->nv_serving_kcal = $nutri_values["val_energ_kcal_p"]; //Energie Kcal
+ $foodProduct->nv_serving_fat_g = $nutri_values["mat_grass_p"]; //graisses
+ $foodProduct->nv_serving_sat_fat_g = $nutri_values["ags_p"]; //dont acides gras saturés
+ $foodProduct->nv_serving_carb_g = $nutri_values["glucides_p"]; //Glucides
+ $foodProduct->nv_serving_sugar_g = $nutri_values["sucre_p"]; //dont sucres
+ $foodProduct->nv_serving_fiber_g = $nutri_values["fib_alim_p"]; //fibres alimentaires
+ $foodProduct->nv_serving_protein_g = $nutri_values["proteine_p"]; //protéines
+ $foodProduct->nv_serving_salt_g = $nutri_values["sel_p"]; //sel
+
+ // $foodProduct-> = $nutri_values["sodium_p"];
+ // $foodProduct-> = $nutri_values["fruits_p"];
+
+
+ //apports journaliers
+ $foodProduct->nv_daily_energy = $nutri_values["pourcent_apport_ref_kjo_r"]; //Energie % recommandé
+ $foodProduct->nv_daily_fat = $nutri_values["pourcent_apport_ref_fat_r"]; //graisses
+ $foodProduct->nv_daily_sat_fat = $nutri_values["pourcent_apport_ref_fatsat_r"]; //dont acides gras saturés
+ $foodProduct->nv_daily_carb = $nutri_values["pourcent_apport_ref_choval_r"]; //Glucides
+ $foodProduct->nv_daily_sugar = $nutri_values["pourcent_apport_ref_sugar_r"]; //dont sucres
+ $foodProduct->nv_daily_fiber = $nutri_values["pourcent_apport_ref_fibtg_r"]; //fibres alimentaires
+ $foodProduct->nv_daily_protein = $nutri_values["pourcent_apport_ref_pro_r"]; //protéines
+ $foodProduct->nv_daily_salt = $nutri_values["pourcent_apport_ref_salteq_r"]; //sel
+
+ //$foodProduct-> = $nutri_values["pourcent_apport_ref_e14_r"];
+
+ //nutriscore
+ $foodProduct->nutriscore = $nutri_values["classement"];
+
+
+ //Infos n'ayant pas de mapping
+ // $foodProduct-> = $nutri_values["val_energ_kj_nut"];
+ // $foodProduct-> = $nutri_values["val_energ_kcal_nut"];
+ // $foodProduct-> = $nutri_values["mat_grass_nut"];
+ // $foodProduct-> = $nutri_values["ags_nut"];
+ // $foodProduct-> = $nutri_values["glucides_nut"];
+ // $foodProduct-> = $nutri_values["sucre_nut"];
+ // $foodProduct-> = $nutri_values["sucre_r"];
+ // $foodProduct-> = $nutri_values["fib_alim_nut"];
+ // $foodProduct-> = $nutri_values["proteine_nut"];
+ // $foodProduct-> = $nutri_values["sel_nut"];
+ // $foodProduct-> = $nutri_values["apport_ref"];
+ // $foodProduct-> = $nutri_values["fruits_coque_sech_p"];
+ // $foodProduct-> = $nutri_values["ener_e14_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_e14_p"];
+ // $foodProduct-> = $nutri_values["ener_kjo_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_kjo_p"];
+ // $foodProduct-> = $nutri_values["fat_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_fat_p"];
+ // $foodProduct-> = $nutri_values["fatsat_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_fatsat_p"];
+ // $foodProduct-> = $nutri_values["choval_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_choval_p"];
+ // $foodProduct-> = $nutri_values["sugar_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_sugar_p"];
+ // $foodProduct-> = $nutri_values["fibtg_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_fibtg_p"];
+ // $foodProduct-> = $nutri_values["pro_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_pro_p"];
+ // $foodProduct-> = $nutri_values["salteq_p"];
+ // $foodProduct-> = $nutri_values["pourcent_apport_ref_salteq_p"];
+ // $foodProduct-> = $nutri_values["apport_port"];
+ // $foodProduct-> = $nutri_values["part_p"];
+ // $foodProduct-> = $nutri_values["part_g"];
+ // $foodProduct-> = $nutri_values["part_l"];
+ // $foodProduct-> = $nutri_values["p_sur_l"];
+ // $foodProduct-> = $nutri_values["pourcent_ags"];
+ // $foodProduct-> = $nutri_values["pourcent_agi"];
+ // $foodProduct-> = $nutri_values["pourcent_ss"];
+ // $foodProduct-> = $nutri_values["pourcent_amidon"];
+ // $foodProduct-> = $nutri_values["composante_n"];
+ // $foodProduct-> = $nutri_values["composante_p"];
+ // $foodProduct-> = $nutri_values["pourcent_fruits"];
+ // $foodProduct-> = $nutri_values["mat_grass_r_prec"];
+ // $foodProduct-> = $nutri_values["ags_r_prec"];
+ // $foodProduct-> = $nutri_values["glucides_r_prec"];
+ // $foodProduct-> = $nutri_values["sucre_r_prec"];
+ // $foodProduct-> = $nutri_values["fib_alim_r_prec"];
+ // $foodProduct-> = $nutri_values["proteine_r_prec"];
+ // $foodProduct-> = $nutri_values["sel_r_prec"];
+ // $foodProduct-> = $nutri_values["sodium_r_prec"];
+ // $foodProduct-> = $nutri_values["fruits_r_prec"];
+ // $foodProduct-> = $nutri_values["fruits_coque_sech_r_prec"];
+ // $foodProduct-> = $nutri_values["score_nutri"];
+ }
+
+ $foodProduct->save();
+ }
+ }
+}
diff --git a/composer.json b/composer.json
index 61f4912..04ae987 100644
--- a/composer.json
+++ b/composer.json
@@ -8,6 +8,8 @@
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
+ "kwaadpepper/enum": "^2.1",
+ "kwaadpepper/exception-handler": "^0.0.5",
"laravel/framework": "^8.65",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5"
diff --git a/composer.lock b/composer.lock
index c72566c..7007d1e 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "d4842c22e789d247c4b660e69490545f",
+ "content-hash": "6b1a297d35d8fae5b28044365e8ae9f0",
"packages": [
{
"name": "asm89/stack-cors",
@@ -883,6 +883,127 @@
],
"time": "2021-10-06T17:43:30+00:00"
},
+ {
+ "name": "kwaadpepper/enum",
+ "version": "2.1.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/Kwaadpepper/enum.git",
+ "reference": "bbd08723895cad5a41bc0d57e565fe64fa13ca41"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/Kwaadpepper/enum/zipball/bbd08723895cad5a41bc0d57e565fe64fa13ca41",
+ "reference": "bbd08723895cad5a41bc0d57e565fe64fa13ca41",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.3"
+ },
+ "require-dev": {
+ "orchestra/testbench": "^5",
+ "phpunit/php-code-coverage": "^9.2",
+ "phpunit/phpunit": "~9.0",
+ "slevomat/coding-standard": "^7.0",
+ "squizlabs/php_codesniffer": "^3.5"
+ },
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Kwaadpepper\\Enum\\EnumServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Kwaadpepper\\Enum\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jérémy Munsch",
+ "email": "github@jeremydev.ovh",
+ "homepage": "https://jeremydev.ovh"
+ }
+ ],
+ "description": "Enums to use for any project",
+ "homepage": "https://github.com/kwaadpepper/enum",
+ "keywords": [
+ "enum",
+ "laravel"
+ ],
+ "support": {
+ "issues": "https://github.com/Kwaadpepper/enum/issues",
+ "source": "https://github.com/Kwaadpepper/enum/tree/2.1.2"
+ },
+ "time": "2021-11-18T16:52:08+00:00"
+ },
+ {
+ "name": "kwaadpepper/exception-handler",
+ "version": "0.0.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/Kwaadpepper/exception-handler.git",
+ "reference": "52a3f5a3f72246f6d99a486cf2951c5c65b88d1a"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/Kwaadpepper/exception-handler/zipball/52a3f5a3f72246f6d99a486cf2951c5c65b88d1a",
+ "reference": "52a3f5a3f72246f6d99a486cf2951c5c65b88d1a",
+ "shasum": ""
+ },
+ "require": {
+ "illuminate/support": "~7|~8",
+ "laravel/framework": "~7|~8"
+ },
+ "require-dev": {
+ "orchestra/testbench": "^6.13",
+ "phpunit/phpunit": "~9.0",
+ "squizlabs/php_codesniffer": "^3.5"
+ },
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Kwaadpepper\\ExceptionHandler\\ExceptionHandlerServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Kwaadpepper\\ExceptionHandler\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jérémy Munsch",
+ "email": "github@jeremydev.ovh",
+ "homepage": "https://jeremydev.ovh"
+ }
+ ],
+ "description": "Send emails when exceptions occurs",
+ "homepage": "https://github.com/kwaadpepper/exception-handler",
+ "keywords": [
+ "email",
+ "exception",
+ "laravel",
+ "policies"
+ ],
+ "support": {
+ "issues": "https://github.com/Kwaadpepper/exception-handler/issues",
+ "source": "https://github.com/Kwaadpepper/exception-handler/tree/0.0.5"
+ },
+ "time": "2021-11-08T15:35:37+00:00"
+ },
{
"name": "laravel/framework",
"version": "v8.72.0",
diff --git a/config/exception-handler.php b/config/exception-handler.php
new file mode 100644
index 0000000..83ec149
--- /dev/null
+++ b/config/exception-handler.php
@@ -0,0 +1,15 @@
+ !config('app.debug'),
+
+ /**
+ * Put a developper secured mailbox in here
+ * so you can receive email if things go mad
+ */
+ 'contactsList' => []
+];
diff --git a/config/filesystems.php b/config/filesystems.php
index 760ef97..bb148b2 100644
--- a/config/filesystems.php
+++ b/config/filesystems.php
@@ -53,6 +53,10 @@ return [
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],
+ 'inco' => [
+ 'driver' => 'local',
+ 'root' => storage_path('inco'),
+ ],
],
/*
diff --git a/config/mail.php b/config/mail.php
index e860749..33b0987 100644
--- a/config/mail.php
+++ b/config/mail.php
@@ -96,6 +96,11 @@ return [
'name' => env('MAIL_FROM_NAME', 'Example'),
],
+ 'contactsList' => [
+ 'serviceweb' => explode(",", env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr')),
+ 'invalidInco' => explode(",", env('MAIL_LIST_INVALIDINCO', 'equipe.web@ldc.fr,vincent.pierre@ldc.fr,christelle.manceau@ldc.fr')),
+ ],
+
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
diff --git a/database/migrations/2021_11_19_102529_create_jobs_table.php b/database/migrations/2021_11_19_102529_create_jobs_table.php
new file mode 100644
index 0000000..1be9e8a
--- /dev/null
+++ b/database/migrations/2021_11_19_102529_create_jobs_table.php
@@ -0,0 +1,36 @@
+bigIncrements('id');
+ $table->string('queue')->index();
+ $table->longText('payload');
+ $table->unsignedTinyInteger('attempts');
+ $table->unsignedInteger('reserved_at')->nullable();
+ $table->unsignedInteger('available_at');
+ $table->unsignedInteger('created_at');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('jobs');
+ }
+}
diff --git a/database/migrations/2021_11_19_102629_create_xml_incos_table.php b/database/migrations/2021_11_19_102629_create_xml_incos_table.php
new file mode 100644
index 0000000..092ced7
--- /dev/null
+++ b/database/migrations/2021_11_19_102629_create_xml_incos_table.php
@@ -0,0 +1,51 @@
+id();
+
+ $table->boolean('prod_saison');
+
+ $table->string('allegations')->nullable();
+ $table->text('descriptif')->nullable();
+ $table->json('picture');
+ $table->text('astuces')->nullable();
+ $table->string('lib_conso')->nullable();
+ $table->string('nb_portion', 20)->nullable();
+ $table->string('typ_portion', 200)->nullable();
+ $table->string('pds_moy_theo', 20)->nullable();
+
+ $table->text('conseil_prepa')->nullable();
+ $table->text('arg_vente')->nullable();
+ $table->text('lst_ing')->nullable();
+ $table->text('lib_allergene')->nullable();
+
+ $table->json('nutritional_values');
+
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('xml_incos');
+ }
+}
diff --git a/resources/views/emails/invalidxml.blade.php b/resources/views/emails/invalidxml.blade.php
new file mode 100644
index 0000000..e212653
--- /dev/null
+++ b/resources/views/emails/invalidxml.blade.php
@@ -0,0 +1,28 @@
+
+
+
+ {{ $appName }} Exception Handler: Unvalid XML
+
+
+
+ {{ $appName }} à reçu un fichier xml non valide !!
+ {{ $strError }}
+ FICHIER: `{{ $filename }}`
+ {{ $exception->getMessage() }}
+
+ date : {{ date('Y-m-d H:i:s') }}
+ code : {{$exception->getCode() }}
+ file : {{$exception->getFile() }}
+ line : {{$exception->getLine() }}
+
+ Merci de corriger le flux, puis de renvoyer le fichier en provoquant un mouvement EAI.
+ Pour rappel : Il est recommandé de valider un fichier XML à l'aide d'un DTD
+ https://www.w3schools.com/xml/xml_dtd.asp
+ ou bien XSD https://www.w3schools.com/xml/schema_intro.asp
+ Pourquoi ?
+ Pour que les concepteurs puissent identifier les types de données qui transitent (les champs et leurs caratéristiques)
+ Mais aussi valider les fichiers reçus.
+
+ En l'absence de données valides, cette fiche va être mise de coté.
+
+
diff --git a/storage/.gitignore b/storage/.gitignore
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/storage/.gitignore
@@ -0,0 +1 @@
+
diff --git a/storage/inco/.gitkeep b/storage/inco/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/storage/inco/archives/.gitkeep b/storage/inco/archives/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/storage/inco/images/.gitkeep b/storage/inco/images/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/storage/inco/invalid/.gitkeep b/storage/inco/invalid/.gitkeep
new file mode 100644
index 0000000..e69de29