Drupal-6 Batch Processing Tip on Include File

In Drupal-6, there is a fantastic new set of function for batch process. The idea is that you first define an array structure, such as

$batch = array(
        'operations' => array(),
        'finished' => 'module_batchtask_form_finished',
        'title' => t('Importing terms from CSV file'),
        'init_message' => t('Starting import...'),
        'progress_message' => t('Imported @current out of @total lines.'),
        'error_message' => t('An error occured during the import.'),
      );

Then add your batch operations into $batch['operations'][].

If you define the functions that handle this batch job in an include file and want to conditionally load the include file, you have to add the following into the $batch array:

        'file' => drupal_get_path('module', 'your-module-name'). '/your-include-file',

As of Drupal-6.1, this behavior is not yet documented in any Drupal API documentations. It took me a while to figure this out, after reading the core module and include files system.module, form.inc, and batch.inc.

Comments

Thanks for this post - it

Thanks for this post - it helped me when I was hitting my head against the wall as to why my batch wasn't working.

--Andrew