I am trying to write a Batch import to create nodes based on a uploaded file. The form works and I receive the file, and can read it in my submit callback which should initiate the Batch import. Here is the code:
function mymodule_import_submit(&$form, $form_state) {
$xml = file_get_contents($form_state['values']['xml']->uri);
$ads = xml2ary($xml);
$batch = array(
'title' => t('Importing Content ...'),
'operations' => array(),
'init_message' => t('Commencing'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('An error occurred during processing'),
'finished' => 'mymodule_import_finished',
);
foreach ($nodes['nodes']['_c']['node'] as $new_node) {
$batch['operations'][] = array('mymodule_import_create_node', array($new_node['_c']));
}
batch_set($batch);
}
While it seems to know the amount of operations needed (how many need to be created) my callback doesn't seem to get called. Here is its code:
function mymodule_import_create_node($new_node) {
$clean_body = make_safe($new_node['CONTENT_BODY']['_v']);
$node = new stdClass();
$node->type = 'article';
node_object_prepare($node);
$node->title = substr(strip_tags($clean_body, 0, 20)) . '...';
$node->body['und'][0]['value'] = $clean_body;
$node->status = 1;
$node->field_article_category = array();
$node->field_article_location = '';
$node->field_email_address = '';
$node->uid = 1;
node_save($node);
$context['results']['articles_imported']++;
}
I put a few dumps at the start of the batch callback and it never exits. Watchdog indicates nothing, and no new nodes appear.