Skip to content

Instantly share code, notes, and snippets.

@dimitridarras
Created April 21, 2018 02:26
Show Gist options
  • Save dimitridarras/1cc9792e970201d4aff653fb07994beb to your computer and use it in GitHub Desktop.
Save dimitridarras/1cc9792e970201d4aff653fb07994beb to your computer and use it in GitHub Desktop.
Setting up a Drupal 7 Batch for Callbacks
//menu callback function - sets up the batch
function batch_dom_parse_to_node($all_raw_hyperlinks,$progress,$ceiling) {
$batch = array(
'operations' => array(),
'finished' => 'dom_parse_to_node_batch_finished', // runs after batch is finished
'title' => t('Processing Import'),
'init_message' => t('Import is starting.'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('Import has encountered an error.'),
);
$max = 120; // how many records to process until stop - can do query here to get max times to run
//$max = count($all_raw_hyperlinks);
while ($progress <= $max) {
drupal_set_message("Progress and ceiling ". $progress." and ".$ceiling);
$batch['operations'][] = array('dom_parse_to_node_parser', array($all_raw_hyperlinks,$progress,$ceiling));
$progress = $progress + $ceiling;
}
batch_set($batch);
//batch_process('admin/dom_parse_to_node'); // page to return to after complete
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment