--- phpbb2drupal.module	2008-02-03 18:00:55.000000000 +0000
+++ phpbb2drupal_batch.module	2008-02-07 17:15:39.472723400 +0000
@@ -374,20 +374,45 @@ function phpbb2drupal_import_users() {
     db_query($query);
 
     variable_set('phpbb2drupal_import_user_started', 1);
+
+    db_set_active('default');
+    $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
+    db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)', $drupal_admin->uid);
+  
   }
 
-  db_set_active('default');
-  $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
-  db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)', $drupal_admin->uid);
+  $batch = array(
+    'operations' => array('phpbb2drupal_batch_import_users', array()),
+    'finished' => 'phpbb2drupal_batch_import_users_finished',
+    'title' => t('Migrating Users'),
+    'init_message' => t('User import is starting.'),
+    'progress_message' => t('@current users processes.'),
+    'error_message' => t('User import has encountered an error.'),
+  );
+  batch_set($batch);
 
+}
+
+function phpbb2drupal_batch_import_users(&$context) {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
   $files_path = variable_get('file_directory_path', 'files');
   $pictures_path = variable_get('user_picture_path', 'pictures');
+  
+  if (!isset($context['sandbox']['progress'])) {
+    $context['sandbox']['progress'] = 0;
+    $context['sandbox']['user_row'] = 0;
+	db_set_active('phpbb');
+    $user_count = db_result(db_query('SELECT COUNT(user_id) FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre));
+	db_set_active('default');
+    $context['sandbox']['max'] = $usercount;
+  }
+
 
   // Insert the users into drupal
   db_set_active('phpbb');
-  $user_ids = db_query('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre);
-
-  $user_count = db_result(db_query('SELECT COUNT(user_id) FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre));
+  //how many to proccess in a single pass
+  $limit = 5;
+  $user_ids = db_query_range('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre, $context['sandbox']['user_row'], $limit);
 
   if (!$user_count) {
       drupal_set_message(t('There were no users found: Aborting script'), 'error');
@@ -398,7 +423,7 @@ function phpbb2drupal_import_users() {
   
   $import_spammers = variable_get('phpbb2drupal_import_spammers', 1);
   
-  while ($result = db_fetch_object($user_ids)) {    
+  while ($result = db_fetch_object($user_ids)) {   
 
     db_set_active('phpbb');
     $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d', $pre, $result->user_id));
@@ -490,8 +515,16 @@ function phpbb2drupal_import_users() {
 
     db_set_active('phpbb');
     }
+    $context['sandbox']['progress']++;
+    $context['sandbox']['user_row']++;
   }
+  
+  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
+    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
+  }
+}
 
+function phpbb2drupal_batch_import_users_finished() {
   // set the user import successful flag in the variable table
   db_set_active('default');
   variable_set('phpbb2drupal_import_user_successful', '1');
