Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We are using VBO on Drupal.org to mass delete nodes created by specific user. It turns out no watchdog entry is being created on such bulk deletions, therefore we can't find out who deleted something if there was a mistake.
Steps to reproduce:
1. Bulk delete nodes.
2. Go to watchdog and check if any new message appeared.
We can provide D.o dev site for testing.
Comment | File | Size | Author |
---|---|---|---|
#21 | Recent_log_messages___D7.jpg | 195 KB | Peter Majmesku |
#21 | vbo-config-option.jpg | 129.47 KB | Peter Majmesku |
#19 | view.jpg | 185.18 KB | Peter Majmesku |
#17 | actions-form.jpg | 148.08 KB | Peter Majmesku |
#10 | views_bulk_operations-2282079-watchdog_on_delete.patch | 2 KB | Steven Jones |
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedVBO doesn't log to watchdog any kind of operation.
It also has no way of knowing all of the ids that were processed, since there could theoretically be 100k.
I suggest implementing hook_entity_delete / hook_node_delete and logging from there.
Comment #2
tvn CreditAttribution: tvn commentedThanks! Sorry for useless issue. :)
Comment #4
Steven Jones CreditAttribution: Steven Jones commentedSorry for re-opening, but I just want to clarify why VBO doesn't/can't log what it's doing.
If we look at the specific VBO action we're talking about here, delete:
http://cgit.drupalcode.org/views_bulk_operations/tree/actions/delete.act...
Then we can see that of course, VBO does know the ID that's being processed, because it doesn't just delete a random entity.
Would you accept a patch that added configurable (on/off) logging to the delete action (at least) so that VBO logs in a similar way to deleting an entity through other admin UIs?
Otherwise, we'll have to write our own action that's basically the same, but logs.
Comment #5
bojanz CreditAttribution: bojanz commentedWell yes, I meant logging all ids at once.
VBO is frequently used to delete thousands of entities, having thousands of matching new entries in watchdog sounds very impractical.
I would accept such a patch, if the option is disabled by default.
Comment #6
Steven Jones CreditAttribution: Steven Jones commentedWhile I agree about the thousands of extra log messages, VBO is often used to replace an admin UI where people will only be deleting 10s of entities at a time.
I'll look into providing a patch.
Thanks!
Comment #7
Steven Jones CreditAttribution: Steven Jones commentedOkay, here's an initial patch, to get some feedback on the approach etc.
This adds optional logging to just the delete_item action.
Comment #8
bojanz CreditAttribution: bojanz commentedWe already have the entity, why are we loading it again?
No need to switch, we know the entity_type and we can use entity_label() to get the label of the entity. "%name %email" for users is the only special case here, which we might want to keep (or fix so that the default entity label looks like that)
Comment #9
Steven Jones CreditAttribution: Steven Jones commentedOh yeah, didn't notice that we did already have the entity around.
As for the different messages, I was making it so they match the relevant modules log messages when bulk deleting in them, hence the switch.
I'll work on the improvements, and provide a new patch.
Comment #10
Steven Jones CreditAttribution: Steven Jones commentedHere's an improved patch, we don't re-load the entity, we use
entity_label
and I've added a little more documentation to explain why we use the switch on the format of log messages.Comment #11
klidifia CreditAttribution: klidifia commentedThis is good, I don't think it matters if there's thousands of logs, could be important! Just a question about your watchdog calls though:
Is there a reason the "severity" is set only on the taxonomy and user ones? WATCHDOG_NOTICE is the default.
Would it be possible to add in a "link" for them, something like: l('view', 'node/' . $entity->entity_id));
Comment #12
Steven Jones CreditAttribution: Steven Jones commented@klidifia I just copied the relevant lines from the core modules that do that logging, so I'm just copying what core does. Adding a link would be bit redundant because the item has been deleted, so the link would be an immediate 404.
Comment #13
klidifia CreditAttribution: klidifia commentedGood point. What about the configurability of this. Is it something that perhaps the administrator of the site can set rather than the person performing the action deciding whether to log it.
The issue I am trying to solve here along the lines of the initial one is if someone deletes some stuff using VBO by accident. (Or malicious - in which case they would choose not to log it).
Comment #14
Steven Jones CreditAttribution: Steven Jones commentedComment #15
Peter MajmeskuHow about this issue now? The last post is 1 year old and no logging for deletion of nodes is an important aspect from my point of view. Will the suggested code land in the release?
Comment #16
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commented@jepSter have you had chance to review the patch in #10? Does it work for you?
Comment #17
Peter Majmesku@Steven Jones:
Sorry, but I cannot bring it to work.
What have I tried? I've applied the patch, flushed the cache. Afterwards I was searching for the settings form, to enable your functionality. But I couldn't find it. The code for the settings form inside your patch is as follows (it would be good, if it had a comment about the path to the settings form):
Since it seems to be a "action", I was searching for the actions settings form for it. But I couldn't find anything about it:
Comment #18
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commented@jepSter ah, that's the core 'actions' UI.
You want to edit the view that you're adding Views Bulk Operations to, and where you can select the VBO actions available, you should be able to configure this one.
Comment #19
Peter MajmeskuThanks for your fast reply.
Where can I find the setting inside views? I was searching for any "field" but there is no setting for it. Here's the screenshot from the default administration page for nodes:
Comment #20
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commented@jepSter if you click on 'Bulk operations: Content' isn't there some config options in there?
Comment #21
Peter Majmesku@Steven Jones: Thank you! I can confirm that your patch works. I hope that your patch will go into the admin views module code with some description. So that people don't have to google around. ;)
See below the screenshots from my test:
Changed state to "Reviewd & tested by the community".
Comment #22
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commented@jepSter thank you for the review! Glad you found the patch useful in the end.
Comment #23
Peter MajmeskuYou're welcome! :)
Will anybody apply the patch into the VBO module?
Comment #24
bojanz CreditAttribution: bojanz at Centarro commentedTweaked the look of the setting, and committed. Thanks!
Comment #27
Peter MajmeskuWouldn't it make sense to enable this setting by default if watchdog (dblog module) is switched on? I have no idea, why this behavior should be an option.
Comment #28
Peter MajmeskuComment #29
bojanz CreditAttribution: bojanz at Centarro commentedSee #5
Comment #30
Peter Majmesku@bojanz: Ah, good point with the mass-deletion.
I've opened an issue at https://www.drupal.org/node/2638108 for a feature improvement plan to discuss.