Guest User

Untitled

a guest
Apr 29th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. $operations = array();
  2. $items = array();
  3. $limit = 100;
  4. $i = 0;
  5.  
  6. $regs = db_query("SELECT * FROM {table_import_apunte} WHERE field_processed = :processed", array(':processed' => 0));
  7.  
  8. foreach ($regs as $row) {
  9. $row = (array) $row;
  10. if ($i < $limit) {
  11. $items[] = $row;
  12. $i += 1;
  13. } else {
  14. $operations[] = array('csvImporter_create_nodes', array($items, 'apunte'));
  15. $items = array();
  16. $items[] = $row;
  17. $i = 1;
  18. }
  19. }
  20.  
  21. if (!empty($items)) {
  22. $operations[] = array('csvImporter_create_nodes', array($items, 'apunte'));
  23.  
  24.  
  25. $batch = array(
  26. 'title' => t('Importing %name table', array('%name' => drupal_strtoupper('apunte'))),
  27. 'init_message' => t('Starting Import...'),
  28. 'progress_message' => t('Processed @current out of @total.'),
  29. 'error_message' => t('There was a problem importing the file.'),
  30. 'operations' => $operations,
  31. 'finished' => 'csvImporter_batch_finished',
  32. );
  33.  
  34. batch_set($batch);
  35. }
  36.  
  37. while (($row = db_fetch_array($regs)) !== FALSE) {
  38. if ($i < $limit) {
  39. $items[] = $row;
  40. $i += 1;
  41. } else {
  42. $operations[] = array('_aicia_import_batch_create_nodes', array($items, $table));
  43. $items = array();
  44. $items[] = $row;
  45. $i = 1;
  46. }
  47. }
Add Comment
Please, Sign In to add comment