The entity API function entity_save does only take single entities, it cannot handle entity arrays. When the aggregation property is set on an action via hook_action_info we need to save the entities one by one after performing the action.

Comments

bojanz’s picture

Status: Active » Needs work

Changing status so that I see this the next time I go on a commit spree.

The patch is very close to what I can commit.
We need the API to be clearer on this.
I'm going to modify the execute() method and _views_bulk_operations_operation_do() to always accept $entities, and modify the processing functions to provide array($entity) in case there's only one.
That removes the need for us to change the datatype manually in the patch, we just need the foreach and we're done.
I will make these changes and commit, you don't need to do anything.

Thank you for bringing this issue to my attention, and providing a patch.

bojanz’s picture

Title: [PATCH] Fix saving entities for actions with aggregation » Fix saving entities for operations using aggregation
Status: Needs work » Needs review
StatusFileSize
new3.8 KB

I have this committed locally.
Won't have git access until tomorrow, pushing it then.

bojanz’s picture

StatusFileSize
new3.8 KB

Whoops, the previous patch is reverse.

znerol’s picture

Thanks for the patch. I quickly tested it with my custom actions on top of todays git head, it works.

I'm not the person picking on other peples code. I for myself prefer being as specific as possible for parameter and varialbe names, therefore I suggest using $entities instead of $data.

bojanz’s picture

Status: Needs review » Fixed

Yes, but the problem with that is that it's invalid half of the time.
Sometimes $entities contains just one entity, and sometimes an $entity contains multiple entities.
And I can't force it to be an array always because Rules complains, and going around that is then an ugly hack in the Rules integration code.
So I went with $data which I also hate :) Good enough, I guess.

Pushed the fix.

Status: Fixed » Closed (fixed)

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