For some of my custom modules, i use VBO merely a selection tool, it would be quite nonsense to rewrite the UI. But then, I need to be able to act on completed operations.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

infojunkie’s picture

Thanks for the initiative. I've been meaning to add this for a while.

I committed this slightly differently, to support VBO_EXECUTION_DIRECT and VBO_EXECUTION_BATCH execution modes. Please review and let me know if it still works as intended for you.

infojunkie’s picture

Status: Needs review » Needs work

Oops, committed too soon. I'll issue another patch.

Aron Novak’s picture

Status: Needs work » Fixed

perfect, awesome

Aron Novak’s picture

Status: Fixed » Needs work

hah, just changed the status accidentally

infojunkie’s picture

Reverted the previous commit.

What needs to be done is this: support VBO_EXECUTION_DIRECT and VBO_EXECUTION_BATCH for calling hook_views_bulk_operations_finish, possibly by invoking it from within _views_bulk_operations_batch_finished (which ends up being called in both cases). This just needs the relevant parameters to be accessed inside this function.

infojunkie’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bojanz’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev
Status: Closed (fixed) » Patch (to be ported)

7.x-3.x should have this.

bojanz’s picture

Status: Patch (to be ported) » Fixed

Done.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bojanz’s picture

If anyone finds this issue, note that this hook was removed afterwards from 7.x-3.x:
http://drupalcode.org/project/views_bulk_operations.git/commitdiff/f4e6e...

It wasn't actually useful since it got very little data (no entity ids operated on for example). A much better solution for the problem is to write an action that just calls your function. It is just a few extra lines of code and gives you much more data (all loaded entities, etc).
From a performance point of view it is not feasible to have the same amount of data present in the finished callback.

If there is a use case that can work with getting the rows & entities, we can reconsider.
Either that, or store the processed entity ids in the process functions so that the finished callback can pass them along to the hook.
However, that might be too much for Batch API, because I'm guessing the data saved in $context is serialized as well, and serializing another thousand ids might be too much.

bojanz’s picture

Status: Closed (fixed) » Needs work

This is a better status. Could use feedback. What are the exact use cases for this hook?

bojanz’s picture

Status: Needs work » Closed (won't fix)

No clever ideas for now, it seems. My #11 (writing a small custom action) still sounds good. Reopen if you have anything to add.

yvmarques’s picture

Status: Closed (won't fix) » Needs work

Hi,

I've an example that needs to know when VBO finish.

In my example, I've to export a thousand items (user or node) in only one PDF. My idea was to create different files and when VBO will finish I concat all of them, but actually I've not idea how to know when VBO finish or not.

Or somebody has another idea how to do it without that hook ?

bojanz’s picture

Status: Needs work » Closed (fixed)

I think a better idea is to create the PDF, then append to it for each entity.
You can see an example of this in the "create archive" action (actions/archive.action.inc) that ships with 7.x-3.x-dev (it uses $context to see the position in the set, like 0/100, 50/100, 100/100). In any case, the data in $context ($context['progress']['current'], $context['progress']['total']) should be enough to allow you to do what you need.

yvmarques’s picture

Version: 7.x-3.x-dev » 6.x-1.x-dev
Status: Closed (fixed) » Needs work

Its exactly what I want do. Unfortunately, I forgot to tell that is form Drupal 6.x branch. There is also possible ?

bojanz’s picture

Status: Needs work » Closed (fixed)

6.x has the mentioned hook (hook_views_bulk_operations_finish) so you can just use that.

yvmarques’s picture

Well, I didn't understand that you kept the patch for the 6.x branch. Thanks !

-- Yvan

kevin.mcnamee@mailbox.org’s picture

Status: Closed (fixed) » Active

A much better solution for the problem is to write an action that just calls your function.

But actions are called per object. So I am assuming that the $context contains information about when the last object is being processed so that my function can trigger on that to do any post-processing.

Furthermore, if the user can select between a list of actions to apply to the list of objects, then all of them will have to be implemented as custom actions in order to trigger post-processing. Of course, these can be just wrappers around normal actions which can be called with actions_do.

Something like:

function mymodule_dosomething_action(&$object, $context = array()) {

  actions_do(real action id, &$object, $context);

  if (last object) {
    my_postprocessing_function();
  }

}

Have I understood correctly?

Cheers,
Kevin

infojunkie’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev

@kmcnamee, are you talking about D7?

kevin.mcnamee@mailbox.org’s picture

No, D6.

/Kevin

infojunkie’s picture

Version: 7.x-3.x-dev » 6.x-1.x-dev
Status: Active » Fixed

In D6, the hook hook_views_bulk_operations_finish($operation, $params, $results) is called.

kevin.mcnamee@mailbox.org’s picture

Sorry, a bit slow this morning. Yes, the finish hook is available in D6 and I am successfully using it. My observation in #20, is that without the hook, the developer must do a lot more work. In other words, I am arguing for reinstating the hook in D7, assuming my analysis is correct.

/Kevin

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kevin.mcnamee@mailbox.org’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev
Status: Closed (fixed) » Active
bojanz’s picture

Version: 7.x-3.x-dev » 6.x-1.x-dev
Status: Active » Closed (fixed)

The changes I plan to make in #1176794: Improve Batch Performance (storing the ids in a queue) make it even more impossible for the finished hook to get the entity ids.
So you could only get the operation name and a few params, which is useless.

Hence, this is a "won't fix" for D7.

hansfn’s picture

A related question: I need to do something when my action is called on the last row. I don't see how I can use hook_views_bulk_operations_finish. Is there any work-around? I know this is trivial in the D7 version since it has the $context['progress'] array.

PS! Is hook_views_bulk_operations_finish documented at all?

hansfn’s picture

Status: Closed (fixed) » Active

I'm reopening this so it hopefully gets some attention. (Sorry if I'm violating a guideline.)

agungsuyono’s picture

If I need nodes/nids selected to be passed to 'hook_views_bulk_operations_finish', how to I do that? My case is I want to select some nodes using VBO and then those nodes to be printed out in HTML format after submit, using .tpl.php defined in 'hook_theme'.

Thanks for the help,
Agung

xatoo’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev

I'd wish to give this issue a little kick. Is there already an alternative solution for D7?

@bojanz: I don't agree with you that just getting the operation name with some extra parameters is useless. In some cases the only thing what you wish to do is clear/rebuild some kind of cache. You don't need a list of processed items for that. Isn't there any chance on a hook_views_bulk_operations_finish in D7?

hansfn’s picture

Version: 7.x-3.x-dev » 6.x-1.x-dev

This is fixed for D7 - see comment #15.

bluetegu’s picture

I wasn't aware of the solution described in #15 and took a different approach of firing up a 'finish' rule event. It doesn't work for queue processing though. FWIW attached is the patch.

kenorb’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev
Issue summary: View changes
Status: Active » Fixed

Fixed as per #15. Drupal 6 is no longer supported.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Bedstvie’s picture

You can use hook_batch_alter

function MODULE_batch_alter(&$batch) {
  foreach ($batch['sets'] as $key => $set) {
    if ($set['finished'] == 'views_bulk_operations_execute_finished') {
      $batch['sets'][$key]['finished'] = 'MODULE_views_bulk_operations_execute_finished';
    }
  }
}

function MODULE_views_bulk_operations_execute_finished($success, $results, $operations) {
  /*
   * Your code.
   */

  views_bulk_operations_execute_finished($success, $results, $operations);
}