Problem/Motivation
I'm trying a command: drush -vvv views-bulk-operations:execute -d deleteme_content entity:delete_action:node
where deleteme_content is a View with translations of entities that I want to delete. The command appears to work and prints a success message but the content is not actually deleted.
Steps to reproduce
Create a view with content items to delete.
Drupal Version 9.0.9
Drush 10.3.4
drush vbo-execute deleteme_content entity:delete_action:node
The command appears to work and prints a success message but the content is not actually deleted.
I've traced all the way into drupal/core/lib/Drupal/Core/Action/Plugin/Action/DeleteAction.php where I added some temporary logging messages and see in executeMultiple() that the desired entities are being changed in $this->tempStore.
So it looks to me like the changes are being made in tempStore but then not being "committed" to the permanent storage. I have looked for a "commit" type option in both drush and the vbo-execute command for drush and don't see anything.
Proposed resolution
Don't know, is there a "commit" step I'm missing, is the a bug, or am I attempting something not supported?
Remaining tasks
Need confirmation it's a bug or more info.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | vbo-3185468-10.patch | 1.37 KB | graber |
Comments
Comment #2
sprior commentedComment #3
graber commentedUnfortunately all core actions with a confirmation step are not supported. It's too hacky for VBO, as they don't have the actual action execution in their execute() methods but somewhere else.
Comment #4
sprior commentedI still do need to do a command line deletion of content items based on a view. Does this mean I can do it from a custom module for drush or it's just not possible at all?
Comment #5
graber commentedYou have VBO built-in action: views_bulk_operations_delete_entity, try using this on your view.
Comment #6
sprior commentedviews_bulk_operations_delete_entity worked but it went too far. The short version of the story is that I'm trying not to delete the entire entity, but delete specific translations of an entity that were populated with dummy data. This seems to be what the "Delete Content" Action does from the /admin/content page where translations of an entity appear as separate items from the original entity. This appears to be the "Delete content item" action listed in views bulk operations and not "Delete selected entities".
The longer story behind what I'm attempting is that I'm upgrading a multilingual Drupal 6 site to Drupal 9 using Feeds. Because of the difference in the way translations are handled between those two I wrote code which condenses a D6 translation node of an original node into just one node with additional language fields - body became body-en, body-fr, body-es and so on for each of the languages possible int he original site. But Drupal Feeds requires that the entire node be loaded at once and it is apparently impossible to mark a field mapping as left out if not present, so I had my code generate a translation title of "deleteme" for each translation that wasn't actually in the original site, so this way every entity in the imported site would have every defined language field in the feed mapping.
Then once the import completed it would be a relatively simple matter to use VBO to delete all the translations with a title of "deleteme" and everything would be done.
So if you'd be willing to add views_bulk_operations_delete_content in addition to the existing views_bulk_operations_delete_entity you'd hopefully help me as well as others who are working with the new implementation of field translations for entities.
Comment #7
graber commentedThen a new VBO action is needed. I don't have time for that at the moment, you have to do it yourself or find a developer to do it. Once done, please include a patch here, I'll be happy to review it and add it to VBO.
Comment #8
sprior commentedI've been working through the code and noticed that when dealing with translated entities, in views_bulk_operations/src/Plugin/Action/EntityDeleteAction the function execute($entity) seems to be called multiple times per entity id because it's actually an entity_id/langcode pair.
but the implementation for execute($entity) just calls
$entity->delete();
So I believe that in the case of translated entities the current code is calling $entity->delete(); multiple times for the same entity!
What I suspect (but I'm new to Drupal development) would be more appropriate is:
Comment #9
sprior commentedI've tried the code above and it appears to work and behave more as one would expect.
Comment #10
graber commentedThanks, makes sense. Added a few improvements, please check if this works fine for you.
Comment #11
sprior commentedI spoke too soon, while the test for TranslatableInterface would seem to make sense it appears to return false for the entities I tested so they all got entity deleted instead of a translation removed. I had to comment out that test to work again.
Comment #12
sprior commentedIt is possible that since the entity that is passed to execute() is a translation and not the base entity that the translation itself doesn't implement TranslatableInterface because you can't have a translation of a translation? If so is there a test to see if the entity passed in is not the "base" entity?
Comment #13
sprior commentedI added:
use Drupal\Core\Entity\TranslatableInterface;
to the top of EntityDeleteAction.php and was able to get the :
if ($entity instanceof TranslatableInterface && !$entity->isDefaultTranslation()) {
to work as is.
Comment #14
graber commentedComment #16
graber commentedIncluded your fix and committed. Thanks!
Comment #17
graber commented