I need to run a bulk operation that prepares a large number of entities and then does one operation across the whole set (it's to do with simplenews and has it's own batching process)

The way I would normally do with is by writing some logic into the finish handler of the batch operation, however, when writing a VBO Handler there is no way for me to inject logic into the finish method.

Comments

rlmumford’s picture

Status: Active » Needs review
StatusFileSize
new5.45 KB
andrewbelcher’s picture

Status: Needs review » Needs work

Mostly look good to me, do you want to provide an explanation of what you've done and what API changes it involves to help verify what you've written does what you want?

Also, I would imagine passing through the $success variable into ViewsBulkOperationsBaseOperation::finish() would be helpful so that the finish function can take status into consideration.

public function execute($data, array $context, &$vbo_sandbox) {
  ...
}

As we have type hinting for $context, it would make sense to have it for $vbo_sandbox as well for consistency.

/*
 * @param $vbo_sandbox
 *   An array of variables to persist between the batch calls.
 */

Is it worth mentioning that it also gets passed to the finish() method, as that may well be the more common usage and is certainly yours...

rlmumford’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB
new6 KB

Here's the changes andrewbelcher suggested. Also added some improvements to the docs.

rlmumford’s picture

StatusFileSize
new6.19 KB

This patch fixes some problems with the direct execution stuff.

douggreen’s picture

Shouldn't there also be a change to allow hook_action_info() to define the finish function?

bojanz’s picture

Issue summary: View changes
Status: Needs review » Needs work

I consider it bad DX to have to override the operation plugin every time I want to execute some code after a set of entities.
Let's make it a callback defined by hook_action_info() like #5 suggests.

slurpee’s picture

Hello from Drupal's GSoC 2014 team. Google Summer of Code (GSoC)? - an annual program for university students organized by Google with projects managed by open source organization mentors such as us (Drupal!).

We're currently browsing the issue queue looking for projects. Do you think this issue/project is worth a student spending a summer on it and being paid by Google? If so, are you interested in mentoring the student? Learn more about Summer of Code and how to get involved at links below. We're submitting our Summer of Code application to Google in just over 24 hours and looking for last minute ideas. Please respond quickly if you're interested.

Group to join - https://groups.drupal.org/google-summer-code

Ideas for projects for Summer of Code 2014 - https://groups.drupal.org/node/404778

GSoC Homepage http://www.google-melange.com/gsoc/homepage/google/gsoc2014

Google's Summer of Code 2014 Announcement - http://google-opensource.blogspot.com/2014/02/mentoring-organization-app...

andrewbelcher’s picture

StatusFileSize
new6.37 KB

Here is the patch re-rolled... I've not addressed the issue raised in #5. However, I'm not sure I agree with it, as this is allowing the operations themselves to do things. I wonder if that is really a separate issue that may be best solved with a rules event or similar?

rlmumford’s picture

Status: Needs work » Needs review
StatusFileSize
new6.38 KB
new692 bytes

This patch seems to cause problems when en-queuing large sets of results.