tags:

views:

25

answers:

3

I have a Drupal module which performs a soap request on node save via hook_nodapi. This isn't a big performance loss on individual saves, but if thousands of nodes are being saved in batch mode this is a big bottleneck.

I would like to perform a different action when the hook is invoked from batch mode but can't see an easy way to tell this.

Does anyone have any ideas?

A: 

You can use a global var that you set in the start of the script and unset / change value in the end. Then you could check for that global var in your hook and do nothing if if it's set with a certain value.

googletorp
That would work for a batch process that I wrote, but not for any other batch process.
Jeremy French
+2  A: 

You could call batch_get() and check the result. If it is not empty, you are in batch mode.

(Note: Assuming Drupal-6 here)

Henrik Opel
+1  A: 

If you're making reference to a drupal-level batch using Batch API, Henrik's suggestion is best.

If, however, you are making reference to a shell-driven batch process, which is more practical for large batches than web-based ones, you could test php_sapi_name(): if the return is "cli", then it's command-line and can be a shell batch. Depends on your context

FGM
I was refering to the batch API but thanks for the tip.
Jeremy French

related questions