Can you tell if the nodapia hook (or some kind of hook) is running from batch mode?

I have a Drupal module that makes a soap request in node using hook_nodapi. This is not a big loss in performance for individual savings, but if thousands of nodes are saved in batch mode, this is a big bottleneck.

I would like to perform a different action when the hook is called from batch mode, but cannot see an easy way to tell it.

Does anyone have any ideas?

+2


source to share


3 answers


You can call batch_get()

and check the result. If it is not empty, you are in batch mode.



(Note: Let's assume Drupal-6 is here)

+3


source


If you are referencing a drupal level package using the Batch API , Henrik's suggestion is recommended.



If, however, you are referring to a wrapped batch process, which is more practical for large batches than for websites, you might want to test php_sapi_name () : if return "cli"

is a command line and could be a shell package. Depends on your context.

+1


source


You can use the global var you set at the beginning of the script value and unset / change at the end. Then you can check this global var on your hook and do nothing if it is set with a specific value.

0


source







All Articles