* * @folder /home/newsite-lepage-vivaces.com/CRON/ * @since 1.0 * @param db adodb object database * 0 champ : 422Conditionnement exemple : AGAPAFG8, AGAPAFC2, AGAPAFC3. 1 champ : Conditionnement. 2 champs : DISPONIBLE, EPUISE et INACTIF DISPONIBLE : plante avec des stocks dispo>0 (sauf lieu fournisseur) ou plantes avec des stocks <0 && stock réservé =0 && Statut =’’ (pour Laurent). EPUISE : Plante avec le statut EPUISE et NEGOCE. INACTIF : plante avec le statut INACTIF. 3 champs : Id Aquila. * * *--------------------------------------------------------------------------------------------------------------- *--------------------------------------------------------------------------------------------------------------- *--------------------------------------------------------------------------------------------------------------- *--------------------------------------------------------------------------------------------------------------- *--------------------------------------------------------------------------------------------------------------- */ require_once ('/home/ubuntu/pepiniere-bretagne.fr/ini.php'); // Database access functions ini_set('display_errors', 1); ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1'); ini_set('memory_limit', '1024M'); error_reporting(E_ALL); define('XMLVERBOSE', 2); set_time_limit(0); set_time_limit(-1); $basename = 'web-abelia.xml'; //$basename = 'test.xml'; $log = ''; $xmlstr = file_get_contents(REPIMPORT . $basename); $jsonname = 'web-abelia.json'; //$jsonname = 'test.json'; libxml_use_internal_errors(true); $whitelist = array('id', 'tarif_id', 'tva_id', 'libelle1_variete', 'libelle2_variete', 'Nom_vermaculaire_1', 'Nom_vermaculaire_2', 'Rusticite', 'Couleur_fleur', 'Famille_botanique', 'Epoque_floraison', 'Epoque_maturite_fruit', 'Type_fruitier', 'variete_memo_texte', 'variete_texte', 'genre', 'espece', 'variete', 'code_famille', 'Exposition1', 'Exposition2', 'Exposition3', 'Exposition4', 'Exposition_solaire', 'Flashcode', 'Type_feuillage', 'Libre', 'Nature_sol', 'Maritime_vent', 'Melifere_odorant_couvre_sol', 'Hauteur_Mini', 'Hauteur_Maxi', 'Largeur_Mini', 'Largeur_Maxi', 'libelle_conditionnement', 'poids_conditionnement', 'libelle_taille', 'libelle1_article', 'libelle2_article', 'prix_base_article', 'unite_vente', 'poids_article', 'stk_dispo', 'nouveaute', 'libelle_famille', 'libelle_sous_famille', 'libelle_forme', 'code_variete', 'code_conditionnement', 'code_taille', 'code_totalisateur', 'mis_en_avant', 'famille_variete', 'code_regroupement', 'Descriptif_article', 'Texte_Genre', 'Texte_Espece', 'Texte_Entretien', 'Vendabilite', 'Prix_Vente_TTC', 'Stock_disponible', 'date_Maj_Variete', 'date_Maj_Article', 'Date_Dernier_Mvt_Stock', 'Images', 'Statut_Web'); $blacklist = array('date', 'colonne52', 'colonne53', 'colonne54', 'colonne55', 'colonne56', 'colonne57', 'colonne58', 'colonne59', 'colonne60', 'colonne61', 'colonne62', 'colonne63', 'colonne64', 'colonne65'); $whiteliste_collection = array('VIV', 'ANN', 'ZAQ', 'AR', 'ARB', 'BAM', 'ZBR', 'ZBU', 'CVI', 'DIV', 'ZFO', 'FRU', 'ZGR', 'GRI', 'HOR', 'LIV', 'ZMA', 'ZOF', 'ZOM', 'OUT', 'ENG', 'DIV', 'GAZ', 'PAI', 'PRO', 'TER', 'PAL', 'LEG', 'SEC', 'ZRE', 'ZZZ', 'ROT', 'ROG', 'ROB', 'CON', 'TOP'); $delais_cron = 30; $datecompare = date('Ymd', strtotime(date('Ymd'). ' - '.$delais_cron.' days')); $_SESSION['blacklist_produit'] = array(14529, 14605, 14604, 12084, 5641, 5640, 14762, 6085, 9915); $_SESSION['liste_ref_conditionnement'] = array(); $_SESSION['liste_ref_tarif'] = array(); $_SESSION['liste_ref_couleurs'] = array(); $_SESSION['liste_ref_couleurs_feuille'] = array(); $_SESSION['liste_ARTICLE'] = array(); $_SESSION['liste_ARTICLE_EXISTER_CONDITIONNEMENT'] = array(); /** *ETAPE 1 *Lecture, conversion et enregistrement du fichier XML au format Json *du fichier XML au format Json */ if ($dh = opendir(REPIMPORT)) { while (($file = readdir($dh)) !== false) { //$log .= $basename.'--->'.$file.'
'; if ($file == $basename) { $timestamp_debut = microtime(true); $XML = simplexml_load_string($xmlstr, "SimpleXMLElement", LIBXML_NOCDATA); // $xml = explode("\n", $xmlstr); if ($XML === false) { $errors = libxml_get_errors(); foreach ($errors as $error) { $log .= display_xml_error($error, $xml); $log .= '
'; } libxml_clear_errors(); } $timestamp_fin = microtime(true); $difference_ms = $timestamp_fin - $timestamp_debut; $log .= '
************************************************************************************************************************************************
'; $log .= 'traitement simplexml_load_string de '. $basename.' - '. $difference_ms .'
'; $log .= '
************************************************************************************************************************************************
'; //print_r($XML); $json = json_encode($XML, JSON_INVALID_UTF8_SUBSTITUTE); $timestamp_fin = microtime(true); $difference_ms = $timestamp_fin - $timestamp_debut; $log .= '
************************************************************************************************************************************************
'; $log .= 'traitement json_encode de '.$jsonname.' - '. $difference_ms .'
'; $log .= '
************************************************************************************************************************************************
'; $resultat = file_put_contents(REPIMPORT.$jsonname, $json); // Vérifiez si l'écriture a réussi if ($resultat !== false) { $log .= 'Le fichier JSON a été enregistré avec succès.
'; } else { $log .= 'Une erreur s\'est produite lors de l\'enregistrement du fichier JSON.
'; } $My_array = json_decode($json, TRUE); $timestamp_fin = microtime(true); $difference_ms = $timestamp_fin - $timestamp_debut; $log .= '
************************************************************************************************************************************************
'; $log .= 'traitement json_decode '. $difference_ms .'
'; $log .= '
************************************************************************************************************************************************
'; } } } $_tampon= $My_array['produits']['produit'][0]['code_variete']; foreach ($My_array['produits']['produit'] as $produit) { if (!in_array($produit['id'], $_SESSION['blacklist_produit']) && in_array($produit['code_famille'], $whiteliste_collection)) { if (1 == 1 || (int)$date_Maj_Article > (int)$datecompare || (int)$date_Maj_Variete > (int)$datecompare || (int)$Date_Dernier_Mvt_Stock > (int)$datecompare) { if($produit['code_variete']==$_tampon){ $Mytab[]=$produit; }else{ //echo $produit['code_variete'].'
'; $Myjson = json_encode($Mytab, TRUE); $resultat = file_put_contents(REPIMPORT.'json_convert/'.$_tampon, $Myjson); $_tampon=str_replace('/','_',$produit['code_variete']); $Mytab=array(); $Mytab[]=$produit; } }} } $My_array = json_decode($json, TRUE); $timestamp_fin = microtime(true); $difference_ms = $timestamp_fin - $timestamp_debut; $log .= '
************************************************************************************************************************************************
'; $log .= 'traitement json_encode par fichier'. $difference_ms .'
'; $log .= '
************************************************************************************************************************************************
'; $cdir = scandir(REPIMPORT.'json_convert'); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { $log .="$key => $value
" ; $file = REPIMPORT.'json_convert/'.$value; // mettre le contenu du fichier dans une variable $data = file_get_contents($file); // décoder le flux JSON $obj = json_decode($data); } } $My_array = json_decode($json, TRUE); $timestamp_fin = microtime(true); $difference_ms = $timestamp_fin - $timestamp_debut; $log .= '
************************************************************************************************************************************************
'; $log .= 'traitement json_encode par fichier'. $difference_ms .'
'; $log .= '
************************************************************************************************************************************************
'; echo $log; ?>