'Import Batch', 'page callback' => 'drupal_get_form', 'page arguments' => array('import_batch_form'), "access callback"=>true, 'type' => MENU_NORMAL_ITEM, ); return $items; } function import_batch_form(){ $form['description'] = array( '#type' => 'markup', '#markup' => t('Opération permettant de choisir l\'opération à appliquer'), ); $form['batch'] = array( '#type' => 'select', '#title' => 'Choisir l\'option', '#options' => array( 'load' => t('Import des notices depuis Oracle'), 'delete' => t('Suppression des notices'), ), ); $form['submit'] = array( '#type' => 'submit', '#value' => 'Go', ); return $form; } function import_oracle_simple_submit($form, &$form_state){ $function = 'import_oracle_' . $form_state['values']['batch']; // Execute the function named batch_test_1 or batch_test_2. $batch = $function(); batch_set($batch); batch_process('node'); } function import_batch_load(){ $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'), ); $batch['operations'][] = array('import_batch_load_op', array($NUMFI, &$context)); return($batch); OCILogoff($conn); } function import_batch_load_op($numfi, &$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']; 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_delete(){ $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'), ); $batch['operations'][] = array('import_batch_load_op', array($NUMFI, &$context)); return($batch); OCILogoff($conn); } function import_batch_delete_op($numfi, &$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']; 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"); }