148c148,155
< 
---
>     $form['performance']['user_import_batch'] = array(
>         '#type' => 'textfield',
>         '#title' => t('Maximum Users/Process per batch'),
>         '#default_value' =>variable_get('user_import_batch', variable_get('user_import_max', 250)),
>         '#size' => 10,
>         '#maxlength' => 10,
>         '#description' => t('Maximum number of users to import each batch process.'),
>     );
212c219
< 
---
> 	
214,216c221,222
<         if ($form_state['values']['user_import_max'] < 10) form_set_error('user_import_max', t("Value should be at least 10."));       
<     } 
<     else {
---
>         if ($form_state['values']['user_import_max'] < 1) form_set_error('user_import_max', t("Value should be at least 1."));       
>     } else {
218a225,227
>     if (!is_numeric($form_state['values']['user_import_batch'])) {
>        form_set_error('user_import_batch', t('Value must be a number.'));    
>     } 
238c247
< 
---
>   variable_set('user_import_batch', $form_state['values']['user_import_batch']);
540c549
<   _user_import_process($form_state['values']); 
---
>   _user_import_batch_run($form_state['values']);
654c663
<         
---
> 
656c665,668
<     _user_import_process($import);
---
>       _user_import_batch_run($import);
>     }
>     else {
>       drupal_goto('admin/user/user_import');
658,659d669
<     
<     drupal_goto('admin/user/user_import');
665c675
<         
---
> 
669,670c679,747
<     
<     drupal_goto('admin/user/user_import');
---
>     else {
>       drupal_goto('admin/user/user_import');
>     }
> }
> 
> /**
>  * Imports using Batch API
>  * 
>  * @param int $import_id
>  */
> function _user_import_batch_run($import) {
> 	$settings['current_processed'] = 0;
>     $batch = array(
>       'operations' => array(
>         array('_user_import_batch_process', array($import))
>       ),
>       'title' => $import['setting'] == 'test' ? t('Processing user import test') : t('Processing user import'),
>       'init_message' => t('Starting import'),
>       'error_message' => t('Import failed')
>     );
>     batch_set($batch);
>     batch_process('admin/user/user_import');
> 
> }
> 
> /**
>  * Callback for batch processing. Ensures the import is property initialised,
>  * then starts (or continues) the import in batches of 100 users
>  *
>  */
> function _user_import_batch_process($import, &$context) {
> 
>     if (!isset($context['sandbox']['import'])) {
>       $context['sandbox']['import'] = $import;
>       $context['sandbox']['file_bytes'] = filesize($import['filepath']);
>     }
>     else {
>       $import = $context['sandbox']['import'];
>     }
>     $batch_max = variable_get('user_import_batch',variable_get('user_import_max',250));
>     $import_max = variable_get('user_import_max',250);
>     if (($extra = (($import['current_processed']+ $batch_max)- $import_max))>0 ) $import_current_max = $batch_max - $extra;
>     else $import_current_max = $batch_max;
>     if ($import_current_max < 1) $import_current_max =1;
>     
>     if (in_array($import['setting'], array('import', 'test'))) {
>       $import = _user_import_process($import,  $import_current_max);
>     }
>     if (in_array($import['setting'], array('imported', 'tested')) || $import['current_processed'] >= $import_max) {
>       // finished
>       db_query("UPDATE {user_import} SET current_processed = 0 WHERE import_id = %d ",array($import['import_id']));
>       $import['current_processed'] = 0 ;
>       $context['finished'] = 1;
>     }
>     else {
>       // use our byte position in the file to show progress
>       if ($context['sandbox']['file_bytes']) {
>         $context['finished'] = min(array(0.99, $import['current_processed']/$import_max));//($import['pointer'] / ($context['sandbox']['file_bytes']))));
>       }
>       else {
>         // no idea how far through we are
>         $context['finished'] = 0;
>       }
> 
>       $context['message'] = t('Imported @count users', array('@count' => $import['processed']));
>     }
> 
>     $context['sandbox']['import'] = $import;
> 
1237c1314
< function _user_import_settings_update($pointer, $processed, $valid, $setting, $import_id) {
---
> function _user_import_settings_update($pointer, $processed, $valid, $setting,$current_processed, $import_id) {
1240c1317
<   db_query("UPDATE {user_import} SET pointer = %d, processed = %d, valid= %d, setting = '%s' WHERE import_id = %d", $pointer, $processed, $valid, $setting, $import_id);
---
>   db_query("UPDATE {user_import} SET pointer = %d, processed = %d, valid= %d, setting = '%s', current_processed = '%s'  WHERE import_id = %d", $pointer, $processed, $valid, $setting,$current_processed, $import_id);
1338c1415
< function _user_import_process($settings) {  
---
> function _user_import_process($settings, $import_max_override = null) {  
1342c1419,1424
<     $import_max = variable_get('user_import_max', 250);
---
>     if ($import_max_override) {
>       $import_max = $import_max_override;
>     }
>     else {
>       $import_max = variable_get('user_import_max', 250);
>     }
1455c1537,1539
<     _user_import_settings_update($settings['pointer'], $settings['processed'], $settings['valid'], $settings['setting'], $settings['import_id']);  
---
>     $settings['current_processed'] = $settings['current_processed']+$send_counter;
>     _user_import_settings_update($settings['pointer'], $settings['processed'], $settings['valid'], $settings['setting'],$settings['current_processed'], $settings['import_id']);
>     
1517c1601
<             _user_import_process($import);
---
>             _user_import_batch_run($import);
1532c1616
<             _user_import_process($import);
---
>             _user_import_batch_run($import);
