I’m trying to create a batch to import users. I used this (http://pastebin.com/duTbxpgd) as an example, but somehow it’s not working. I see the progress bar advancing and It’s showing the right number of rows I’m processing. But what I’m trying to do in the operation function isn’t executed.
Here’s my code:
function form_submit($form, &$form_state) { batch_import_users(); } function batch_import_users() { db_set_active('mysqldb'); $result = db_query("SELECT * FROM {users}"); db_set_active('default'); $batch = array( 'title' => t('Importing users ...'), 'operations' => array(), 'init_message' => t('Commencing'), 'progress_message' => t('Processed @current out of @total.'), 'error_message' => t('An error occurred during processing'), 'finished' => 'batch_import_users_finished', 'progressive' => FALSE, 'file' => 'users.inc', ); foreach ($result as $row) { $batch['operations'][] = array('batch_create_user', array($row)); } batch_set($batch); batch_process(); } function batch_create_user($row, &$context) { // Here I'm just trying to get some output so I know the operation is called, I'm not actually importing the users yet. drupal_set_message($row->uid . ' : ' . $row->login); dd($row->uid . ' : ' . $row->login); $context['results']['processed']++; $context['message'] = $row->login; } function batch_import_users_finished($success, $results, $operations) { if ($success) { drupal_set_message('Importing users has finished.'); } else { drupal_set_message('Some error.'); } }
Am I missing something or doing something wrong? Any help is very much appreciated.