'Import Batch', 'page callback' => 'import_batch_test', //'page arguments' => array(1, 'foo'), "access callback"=>true, 'type' => MENU_NORMAL_ITEM, ); return $items; } function import_batch_test(){ $conn = oracle_get_connection(); $rq = 'SELECT NUMFI FROM NOTICE WHERE NUMFI < 200 ORDER BY NUMFI ASC'; $NUMFI = oracle_query($rq, $conn); drupal_set_message('Il y a '.count($NUMFI).' notices'); $batch = array( 'operations'=>array(), 'finished'=>'import_batch_finished', 'title' => t('Progression batch'), 'init_message' => t('Démarrage batch'), 'progress_message' => t('@current sur @total.'), 'error_message' => t('La progression a rencontré une erreur'), ); $revue_editeur = array( 'OCDE' => 'OCDE', 'O.C.D.E.' => 'OCDE', 'C.I.E.H.' => 'C.I.E.H.', 'EDIT. MONITEUR' => 'EDITIONS DU MONITEUR', 'TECH. DOC.' => 'LAVOISIER', 'MASSON' => 'MASSON', 'EYROLLES' => 'EYROLLES', 'BERGER-LEVRAULT' => 'BERGER-LEVRAULT', 'SPRINGER-VERLAG' => 'SPRINGER-VERLAG', 'CRC PRESS' => 'CRC PRESS', 'DOC. FR.' => 'DOCUMENTATION FRANCAISE', 'J.O.' => 'JOURNAL OFFICIEL', ); $rq = 'SELECT * FROM EMPLOYE ORDER BY MOTCLE_TABOU ASC'; $employe = oracle_query($rq, $conn); $list_employe = array(); foreach($employe as $emp){ $list_employe [$emp['MOTCLE_TABOU']] = $emp['MOTCLE_REMPLACEMENT']; } $batch['operations'][] = array('import_batch', array($NUMFI, $revue_editeur, $list_employe)); batch_set($batch); batch_process('node'); OCILogoff($conn); } function import_batch($numfi, $revue_editeur, $list_employe, &$context){ $conn = oracle_get_connection(); if(empty($context['sandbox']['items'])){ $context['sandbox']['items'] = $numfi; } if (!isset($context['sandbox']['progress'])){ $context['sandbox']['progress'] = 0; // $context['sandbox']['erreur'] = array(); $context['sandbox']['current_node'] = 0; $context['sandbox']['max'] = count($numfi); } $limit = 20; $serialize = array(); //DEBUT DE L'IMPORT $counter = 0; if(!empty($context['sandbox']['items'])){ if($context['sandbox']['progress'] != 0){ array_splice($context['sandbox']['items'], 0, $limit); } reset($context['sandbox']['items']); while(list($key, $item) = each($context['sandbox']['items'])){ if($counter != $limit && $key > 0){ $node = new stdclass(); $node->status = 1; $node->comment = 0; $node->type = 'notice_documentaire'; $numfi = $item['NUMFI']; $rq = 'SELECT * FROM NOTICE WHERE NUMFI = '.$numfi; $notice = oracle_query($rq, $conn); $node->title = $notice[0]['TITRE']; if($nom_creation = $list_surname[$notice[0]['NOM_CREATION']]){ $uid_creation = utils_user_getUidByName($nom_creation); }else{ $uid_creation = utils_user_getUidByName($notice[0]['NOM_CREATION']); } $node->uid = $uid_creation; if(!empty($notice[0]['NOM_MAJ'])){ if($nom_maj = $list_surname[$notice[0]['NOM_MAJ']]){ $uid_maj = utils_user_getUidByName($nom_maj); }else{ $uid_maj = utils_user_getUidByName($notice[0]['NOM_MAJ']); } $node->revision_uid = $uid_maj; } $type_noti = strtolower(trim($notice[0]['TYPE_NOTICE'])); $vid = utils_taxonomy_getVidByLabel('type_notice'); if($typid = utils_taxonomy_getIdByLabel($type_noti, $vid, false, false)){ $node->field_dc_type['und'][0]['tid'] = $typid; }else{ // $context['sandbox']['erreur']['TYPE'][$notice[0]['TYPE_NOTICE']][] = $notice[0]['NUMFI']; } if(!empty($notice[0]['ORIGINE'])){ $lib_orig = str_replace( array('?','(c)',), array('©','©',), $notice[0]['ORIGINE'] ); $vid = utils_taxonomy_getVidByLabel('origine'); if($lib_origid = utils_taxonomy_getIdByLabel($lib_orig, $vid, false, false)){ $node->field_dc_rights['und'][0]['tid'] = $lib_origid; }else{ // $context['sandbox']['erreur']['ORIGINE'][$notice[0]['ORIGINE']][] = $notice[0]['NUMFI']; } $serialize['DROITS'][0] = array('value'=>$lib_orig); } if(!empty($notice[0]['COTEDDD'])){ $node->field_dc_identifier['und'][0] = array('value'=>$notice[0]['COTEDDD']); } if(!empty($notice[0]['COTEPHYSIQUE'])){ $node->field_cote_interne['und'][0] = array('value'=>$notice[0]['COTEPHYSIQUE']); } $node->field_numfi['und'][0] = array('value'=>$numfi); if($notice[0]['STATUT'] == 1) $statut = 'Gratuit'; elseif($notice[0]['STATUT'] == 2) $statut = 'Payant'; elseif($notice[0]['STATUT'] == 3) $statut = 'OIEau'; elseif($notice[0]['STATUT'] == 4) $statut = 'OIEau Prod'; $node->field_statut['und'][0] = array('value'=>$statut); if(!empty($notice[0]['PRIX_DOCUMENT'])) $node->field_prix_doc['und'][0] = array('value'=>$notice[0]['PRIX_DOCUMENT']); $date_orign = strtotime($notice[0]['DATE_CREATION']); // $date = date("Y-m-d", $date_orign); $node->created = $date_orign; if(!empty($notice[0]['DATE_MAJ'])){ $date_maj = strtotime($notice[0]['DATE_MAJ']); $node->changed = $date_maj; } if(!empty($notice[0]['DATENOTI'])){ $date_orign = strtotime($notice[0]['DATENOTI']); $date = date("Y-m-d", $date_orign); $node->field_date_publication['und'][0]['value'] = $date; } $rq = 'SELECT LANGAGE FROM LANGNOTI WHERE NUMFI = '.$numfi; $langage = oracle_query($rq, $conn); if(!empty($langage)){ foreach($langage as $lang){ $node->field_dc_langue['und'][] = array('value'=>$lang['LANGAGE']); $serialize['LANGAGE'][] = array('value'=>$lang['LANGAGE']); } } if(!empty($notice[0]['BASEORIGINE'])){ $node->field_base_origine['und'][0] = array('value'=>$notice[0]['BASEORIGINE']); } $rq = 'SELECT * FROM DOMAINNOTI WHERE NUMFI = '.$numfi; $domaine = oracle_query($rq, $conn); if(!empty($domaine)){ foreach($domaine as $domain){ $node->field_domaine['und'][] = array('value'=>$domain['LIB_DOMAINE']); $serialize['DOMAINE'][] = array('value'=>$domain['LIB_DOMAINE']); } } $rq = 'SELECT * FROM THEMNOTI WHERE NUMFI = '.$numfi; $theme = oracle_query($rq, $conn); if(!empty($theme)){ $vid = utils_taxonomy_getVidByLabel('theme'); foreach($theme as $them){ if($themid = utils_taxonomy_getIdByLabel($them['LIB_THEME'], $vid, false, false)){ $node->field_dc_subject['und'][] = array('tid'=>$themid); }else{ // $context['sandbox']['erreur']['THEME'][$them['LIB_THEME']][] = $notice[0]['NUMFI']; } $serialize['THEME'][] = array('value'=>$them['LIB_THEME']); } } $rq = 'SELECT LIB_AUTEUR FROM AUTEURNOTI WHERE NUMFI = '.$numfi; $auteur = oracle_query($rq, $conn); if(!empty($auteur)){ foreach($auteur as $author){ $node->field_dc_creator['und'][] = array('value'=>$author['LIB_AUTEUR']); $serialize['AUTEUR'][] = array('value'=>$author['LIB_AUTEUR']); } } $rq = 'SELECT LIB_COMMANDITAIRE FROM COMMANDNOTI WHERE NUMFI = '.$numfi; $commanditaire = oracle_query($rq, $conn); if(!empty($commanditaire)){ foreach($commanditaire as $command){ $node->field_commanditaire['und'][] = array('value'=>$command['LIB_COMMANDITAIRE']); $serialize['COMMANDITAIRE'][] = array('value'=>$command['LIB_COMMANDITAIRE']); } } $rq = 'SELECT LIB_ORGANISME FROM ORGANOTI WHERE NUMFI = '.$numfi; $organisme = oracle_query($rq, $conn); if(!empty($organisme)){ foreach($organisme as $organ){ $node->field_organisme['und'][] = array('value'=>$organ['LIB_ORGANISME']); $serialize['ORGANISME'][] = array('value'=>$organ['LIB_ORGANISME']); } } $rq = 'SELECT LIB_EDITEUR FROM EDITNOTI WHERE NUMFI = '.$numfi; $editeur = oracle_query($rq, $conn); if(!empty($editeur)){ foreach($editeur as $edit){ $node->field_dc_publisher['und'][] = array('value'=>$edit['LIB_EDITEUR']); $serialize['EDITEUR'][] = array('value'=>$edit['LIB_EDITEUR']); } }else{ // Recherche d'éditeurs dans le champ PERI_REVUE foreach($revue_editeur as $key=>$editeur){ if(preg_match('/'.$key.'/', $notice[0]['PERI_REVUE'])){ $node->field_dc_publisher['und'][0] = array('value'=>$editeur); } } } $rq = 'SELECT LIB_BIBLIOGRAPHIE FROM BIBLIONOTI WHERE NUMFI = '.$numfi; $biblio = oracle_query($rq, $conn); if(!empty($biblio)){ $list_biblio = ''; foreach($biblio as $bibl){ $list_biblio = $bibl['LIB_BIBLIOGRAPHIE'].' '.$list_biblio; } $node->field_description_biblio['und'][0] = array('value'=>trim($list_biblio)); $serialize['BIBLIOGRAPHIE'] = array('value'=>$list_biblio); } if(!empty($notice[0]['PAGES'])) $node->field_pages['und'][0] = $notice[0]['PAGES']; if(!empty($notice[0]['ISSN_ISBN_ISRN'])) $node->field_issn['und'][0] = $notice[0]['ISSN_ISBN_ISRN']; if(!empty($notice[0]['URLDOCUMENT']) AND $notice[0]['URLDOCUMENT'] != 'http://www.eaufrance.com/') $node->field_url_doc['und'][0] = $notice[0]['URLDOCUMENT']; if(!empty($notice[0]['NOTES'])) $node->field_notes['und'][0] = $notice[0]['NOTES']; $rq = 'SELECT * FROM CANDNOTI WHERE NUMFI = '.$numfi; $candnoti = oracle_query($rq, $conn); if(!empty($candnoti)){ foreach ($candnoti as $candnot){ if($candnot['LANGAGE'] == 'FRE'){ if($value = $list_employe[$candnot['MOTCLE']]){ $vid = utils_taxonomy_getVidByLabel('thesaurus'); $descripteur = utils_taxonomy_getIdByLabel($value, $vid, false, false); $node->field_descripteurs['und'][] = array('tid'=>$descripteur); }else{ $node->field_cand_desc['und'][] = array('value'=>$candnot['MOTCLE']); } }elseif($candnot['LANGAGE'] == 'GEO'){ if($cand_geoid = utils_taxonomy_getIdByLabel($candnot['MOTCLE'], 12, false, false)){ $node->field_dc_coverage['und'][] = array('tid'=>$cand_geoid); }elseif($cand_geoid_node = utils_node_getIdByLabel(str_replace(' ', '-', $geonot['MOTCLE']), false, false)){ $node->field_dc_coverage_fr['und'][] = array('nid'=>$cand_geoid_node); }else{ // $context['sandbox']['erreur']['GEO_MOTCLE'][$candnot['MOTCLE']][] = $notice[0]['NUMFI']; } } $serialize['CANDNOTI'][] = array('value'=>$candnot['MOTCLE']); } } $rq = 'SELECT ID_MOTCLE_FRANCAIS FROM TECHNOTI WHERE NUMFI = '.$numfi; $descript = oracle_query($rq, $conn); if(!empty($descript)){ $vid = utils_taxonomy_getVidByLabel('thesaurus'); foreach($descript as $descr){ if($descripteur = utils_taxonomy_getIdByLabel($descr['ID_MOTCLE_FRANCAIS'], $vid, false, false)){ $node->field_descripteurs['und'][] = array('tid'=>$descripteur); }else{ // $context['sandbox']['erreur']['DESCRIPT'][$descr['ID_MOTCLE_FRANCAIS']][] = $notice[0]['NUMFI']; } } $serialize['DESCRIPTEURS'] = $descript; } $rq = 'SELECT * FROM GEONOTI WHERE NUMFI = '.$numfi; $geonoti = oracle_query($rq, $conn); if(!empty($geonoti)){ $vid = utils_taxonomy_getVidByLabel('zone_geo'); foreach ($geonoti as $geonot){ if($geoid_tax = utils_taxonomy_getIdByLabel($geonot['MOTCLE'], $vid, false, false)){ $node->field_zone_geo['und'][] = array('tid'=>$geoid_tax); }elseif($geoid_node = utils_node_getIdByLabel(str_replace(' ', '-', $geonot['MOTCLE']), false, false)){ $node->field_dc_coverage_fr['und'][] = array('nid'=>$geoid_node); }else{ // $context['sandbox']['erreur']['GEO_MOTCLE'][$geonot['MOTCLE']][] = $notice[0]['NUMFI']; } $serialize['GEONOTI'][] = array('value'=>$geonot['MOTCLE']); } } $dos_var = intval($numfi)/5000; $dos_array = explode('.', $dos_var); $dossier = $dos_array[0]; $resume = 'http://indre.oieau.fr/notices/'.$dossier.'/'.$numfi.'/'.$numfi.'_res.txt'; $node->field_dc_description['und'][0] = array('value'=>trim(utf8_encode(file_get_contents($resume)))); // Recupérer document if(!empty($notice[0]['CORRES_TYPAPPRECIATION'])){ if($notice[0]['CORRES_TYPAPPRECIATION'] != 'A'){ $node->field_appreciation['und'][0] = array('value'=>$notice[0]['CORRES_TYPAPPRECIATION']); } } if(!empty($notice[0]['PHASEETATNOTICE'])){ if($notice[0]['PHASEETATNOTICE'] == 10) $phase = 'Non validée' ; elseif ($notice[0]['PHASEETATNOTICE'] == 40) $phase = 'Validée' ; $node->field_phase_notice['und'][0] = array('value'=>$phase); } if(!empty($notice[0]['PERI_VOLUME'])) $node->field_volume['und'][0] = array('value'=>$notice[0]['PERI_VOLUME']); if(!empty($notice[0]['PERI_NUMERO']))$node->field_num_revue['und'][0] = array('value'=>$notice[0]['PERI_NUMERO']); if(!empty($notice[0]['PERI_REVUE'])){ $revue_array = utils_revue_array('', true); while(list($key, $value) = each($revue_array)){ $pos = strpos($notice[0]['PERI_REVUE'], $key); if(is_int($pos) != false){ $revue_extract = $value; } } if($revue_nid = utils_node_getIdByLabel(strtoupper($notice[0]['PERI_REVUE']), 'revue', false, false)){ $node->field_revue['und'][0] = array('nid'=>$revue_nid); }elseif($revue_corrig = utils_revue_array(strtoupper($notice[0]['PERI_REVUE']), false)){ $revue_nid = utils_node_getIdByLabel($revue_corrig, 'revue', false, false); $node->field_revue['und'][0] = array('nid'=>$revue_nid); }elseif($explo_revue = explode(',', $notice[0]['PERI_REVUE'])){ if($correct = utils_revue_array(strtoupper($explo_revue[0]), false)){ $rev_nid = utils_node_getIdByLabel($correct, 'revue', false, false); $node->field_revue['und'][0] = array('nid'=>$rev_nid); if(strlen(trim($explo_revue[1])) == 4){ $node->field_revue_annee['und'][0] = array('value'=>$explo_revue[1]); } if(!empty($explo_revue[2]) AND substr(trim($explo_revue[2]),0,1) != 'N'){ $node->field_volume['und'][0] = array('value'=>trim($explo_revue[2])); }elseif(!empty($explo_revue[2]) AND substr(trim($explo_revue[2]),0,1) == 'N'){ $node->field_num_revue['und'][0] = array('value'=>str_replace(array('?',), array('°',),$explo_revue[2])); } if(!empty($explo_revue[3]) AND substr(trim($explo_revue[3]),0,1) == 'N'){ $node->field_num_revue['und'][0] = array('value'=>str_replace(array('?',), array('°',),$explo_revue[3])); } if(!empty($explo_revue[4]) AND empty($notice[0]['PAGES'])){ $node->field_pages['und'][0] = array('value'=>trim($explo_revue[4])); } if(!empty($explo_revue[5])){ $node->field_desc_biblio_complete['und'][0] = array('value'=>$notice[0]['PERI_REVUE']); } }elseif(!empty($revue_extract)){ $rev_nid = utils_node_getIdByLabel($revue_extract, 'revue', false, false); $node->field_revue['und'][0] = array('nid'=>$rev_nid); $node->field_desc_biblio_complete['und'][0] = array('value'=>$notice[0]['PERI_REVUE']); }else{ $node->field_desc_biblio_complete['und'][0] = array('value'=>$notice[0]['PERI_REVUE']); } }elseif(!empty($revue_extract)){ $rev_nid = utils_node_getIdByLabel($revue_extract, 'revue', false, false); $node->field_revue['und'][0] = array('nid'=>$rev_nid); }else{ $node->field_desc_biblio_complete['und'][0] = array('value'=>$notice[0]['PERI_REVUE']); } } if(!empty($notice[0]['TAILLEFICHIERDOCUMENT'])) $node->field_taille_fichier['und'][0] = array('value'=>$notice[0]['TAILLEFICHIERDOCUMENT']); if(!empty($notice[0]['HYPERLIEN'])) $node->field_hyperlien['und'][0] = array('value'=>$notice[0]['HYPERLIEN']); if(!empty($notice[0]['REFLOI'])) $node->field_refloi['und'][0] = array('value'=>$notice[0]['REFLOI']); if(!empty($notice[0]['CONF_CONGRES'])) $node->field_conf_congres['und'][0] = array('value'=>$notice[0]['CONF_CONGRES']); if(!empty($notice[0]['JURI_NUMERO'])) $node->field_juri_numero['und'][0] = array('value'=>$notice[0]['JURI_NUMERO']); if(!empty($notice[0]['JURI_NATURE'])) $node->field_juri_nature['und'][0] = array('value'=>$notice[0]['JURI_NATURE']); if(!empty($notice[0]['JURI_DATEJO'])) $node->field_juri_date['und'][0] = array('value'=>$notice[0]['JURI_DATEJO']); if(!empty($notice[0]['JURI_ETAT'])) $node->field_juri_etat['und'][0] = array('value'=>$notice[0]['JURI_ETAT']); if(!empty($notice[0]['JURI_MODIFICATION'])) $node->field_juri_modif['und'][0] = array('value'=>$notice[0]['JURI_MODIFICATION']); if(!empty($notice[0]['CORRES_ID'])) $node->field_corres_id['und'][0] = array('value'=>$notice[0]['CORRES_ID']); if(!empty($notice[0]['CORRES_DATEENVOI'])) $node->field_corres_dateenvoi['und'][0] = array('value'=>$notice[0]['CORRES_DATEENVOI']); if(!empty($notice[0]['CORRES_DATEREPONSE'])) $node->field_corres_datereponse['und'][0] = array('value'=>$notice[0]['CORRES_DATEREPONSE']); if(!empty($notice[0]['CORRES_TYPEAPPRECIATION'])) $node->field_corres_typeappreciation['und'][0] = array('value'=>$notice[0]['CORRES_TYPEAPPRECIATION']); if(!empty($notice[0]['CORRES_EVALDOCU'])) $node->field_corres_evaldocu['und'][0] = array('value'=>$notice[0]['CORRES_EVALDOCU']); if(!empty($notice[0]['NBRE_ACCES'])) $node->field_nbre_acces_old['und'][0] = array('value'=>$notice[0]['NBRE_ACCES']); if(!empty($notice[0]['DATEDEBUTPHASE'])){ $date_phase = strtotime($notice[0]['DATEDEBUTPHASE']); $date = date("Y-m-d", $date_phase); $node->field_date_debutphase['und'][0] = array('value'=>$date); } $rq = 'SELECT * FROM TONUMILOG WHERE NUMFI = '.$numfi; $tonumilog = oracle_query($rq, $conn); if(!empty($tonumilog)){ $serialize['TONUMILOG'] = $tonumilog; } $node->field_notice_origine['und'][0] = array('value'=>serialize($serialize)); dsm($node); /* if(node_submit($node)){ node_save($node); } */ $counter++; $context['sandbox']['progress']++; $context['message'] = t('Import %node sur %count', array('%node' => $context['sandbox']['progress'], '%count' => $context['sandbox']['max'])); } } } if ($context['sandbox']['progress'] != $context['sandbox']['max']){ $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; } OCILogoff($conn); } function import_batch_finished($success, $results, $operations, &$context){ dsm("FIN BATCH TEST"); }