2

I am trying to write a batch. And I have a problem that none of the batch operations callback functions are getting called.

I wrote drupal_set_message at the start of each callback and none of the messages are displayed.

I can get the batch page, but the callback ops aren't called at all.

Here's the code I used:

function mymdoule_node_batch()
{
    $batch = array(
        'title'         => t("Migrating"),
        'operations'    => array(
            array('mycallback_001'),
            array('mycallback_002'),
        ),
        'finished'      => 'mycallback_finished',
        'init_message'  => t('Initializing...'),
        'error_message' => t('An error occurred.'),
    );

    batch_set($batch);
    drupal_set_message("step: 0"); // this is the only message the system returns
}


function mycallback_001(&$context)
{
    drupal_set_message("step: 1");
    $nids = db_select("node", "n")
            ->fields("n", array("nid"))
            ->orderBy("nid", "ASC")
            ->execute()
            ->fetchCol();
}

function mycallback_002(&$context)
{
    drupal_set_message("step: 2");
    $nids = db_select("node", "n")
            ->fields("n", array("nid"))
            ->orderBy("nid", "ASC")
            ->execute()
            ->fetchCol();
}

P.s. The batch is getting called in form submission.

What's wrong in that?

4
  • 1
    add one redirection at the end of mymdoule_node_batch function then check. batch_process(URL_TO_REDIRECT);
    – Sibiraj PR
    Commented Mar 20, 2013 at 15:24
  • What do you mean by add one redirection at the end of mymdoule_node_batch? Can you provide a code sample? Commented Mar 20, 2013 at 18:44
  • When I add batch_process(); before drupal_set_message("step: 0"); the message is not displayed as well. Commented Mar 21, 2013 at 7:38
  • where is your mycallback_finished function. can you add that one to the question
    – Sibiraj PR
    Commented Mar 21, 2013 at 8:33

2 Answers 2

3

It worked after I added file to the $batch array.

function mymdoule_node_batch()
{
    $batch = array(
        'title'         => t("Migrating"),
        'operations'    => array(
            array('mycallback_001'),
            array('mycallback_002'),
        ),
        'finished'      => 'mycallback_finished',
        'init_message'  => t('Initializing...'),
        'error_message' => t('An error occurred.'),
        'file'          => 'mypatch.ops.inc',
    );

    batch_set($batch);
    drupal_set_message("step: 0");
}
0
1

This Problem happens when we put our file in different folder like as includes/form_test.inc.In this scenario batch function can't call.So to handle this we put 'file' => 'path_to_file_containing_myfunctions' in our submit function.

    $batch = array(
      'title' => t('Custom File uploader'),
      'operations' => array(
        array('test_feeds_import_form_batch', array($uri)),
      ),
      'progress_message' => t('Uploading Multiple Products...'),
      'error_message' => t('Error!'),
      'finished' => 'test_feeds_import_form_batch_finish',
      'file' => drupal_get_path('module', 'test') . '/includes/test_form.inc',
    );

    batch_set($batch);
    batch_process('admin/import-data'); //Work like as drupal goto

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.