Problem/Motivation
Sometimes, we want to import default content and then disable the module, keeping the content.
Sometimes we want to bulk delete the content provided by this module.
Sometimes, we want to reimport again the content to refresh it.
Our preference is not to auto-delete on uninstall. Consider this use-case:
* Create custom_content module to import content to production
* custom_content requires default_content which requires hal and serialization
* We want the content, but do not want these 4 modules enabled
* We enable the module via drush and then disable it (and its dependencies)
* Content is present in production
The approach in #2844276: Option to automatically delete demo content would break that workflow.
During testing, however, we may want to import and delete the custom_content at will.
Steps to reproduce
n/a
Proposed resolution
* Create a drush command to read the info.yml files of default_content modules.
* Allow the drush command to delete all content or content of a specific entity type.
e.g. `drush default-content:delete my_test_content image`
Remaining tasks
Write the drush commands.
User interface changes
None, though this approach could be used to build a form later.
API changes
None anticipated.
Data model changes
None anticipated.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3282547-default-content_delete_drush-8.patch | 5.98 KB | agentrickard |
| #6 | 3282547-default-content_delete_drush.patch | 7.98 KB | agentrickard |
Issue fork default_content-3282547
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
agentrickardComment #3
agentrickardInteresting -- this works, but it creates a pretty ugly loop.
- default_content must be enabled for the command to be found.
- The content module must be enabled for content to be found.
- Trying to uninstall the two after delete disables the command.
We may be better off putting this in a custom module, except that we're using the State element to prevent re-import.
-- Drush command --
Comment #4
agentrickardI figured out how to bypass the module enabled bit, patch coming.
Comment #5
agentrickardOK, I officially hate the git workflow. It's not what I use everyday and I have screwed it up three times -- and I can't delete the branches?!?
Patch coming.
Comment #6
agentrickardStill needs work, since the drush output is non-standard.
Comment #7
agentrickardAnd thanks to GIT defaulting to the 8.x-1.x branch, this patch is malformed.
Please update the project.
Comment #8
agentrickardNew version against 2.0.x.
Notes:
* Still needs better message handling
* Requires that default_content be enabled but not the module that created the content.
Comment #9
ressaThanks @agentrickard, I have created #3282736: Set default Git branch to 2.0.x about your comment in #7.
Comment #10
c_archer commentedPatch in #8 does not work I get the error:
ArgumentCountError: Too few arguments to function Drupal\default_content\Commands\DefaultContentCommands::__construct()Comment #11
tascPatch #8 works fine for me so far.
There are however some questions arising...
Wouldn't it make more sense to delete the content in the same way: regardless of a definition, like its done in the 8.1 patch?
It would be also more practical in case one is using drush dcer entity_type_id --folder and doesn't fiddle around with uuids.
Comment #13
tascThe patch in MR23 is another approach which deletes everything present in the content-folder of a module, without parsing the .info-file. Furthermore also all entity_reference_revisions attached to an entity are deleted.
drush dcdm <module>Comment #14
eduardo morales albertiIn our case, we tried to find all the UUIDs definitions on the default_content and remove them, it will remove all entities defined by default_content.
We tried the drush command and the paragraphs were not removed for example.
Comment #16
eduardo morales albertiWe created a new branch "3282547-drush-delete-content-reimport" to delete all entities from default_content based on all the uuids defined on the default_content module.
Also we add a reimport command (deletes and import again the content).
MR https://git.drupalcode.org/project/default_content/-/merge_requests/45/d...
Comment #17
delacosta456 commentedhi @eduardo-morales-alberti
I was looking for something like this.
The patch applied correctly but looks to have breaks another patch Drush comand to export all items from entity with defined criteria that i was using to export at once node+references to folder .
Example :
drush dcer node 34 --folder=modules/custom/mycustom_default_content/contentafter the merge request 45.patch
the above command doesn't work and send the following error
Can you help
Thanks
Comment #18
eduardo morales alberti@delacosta456 Did you clear the caches after applying the patch?
The service is defined on https://git.drupalcode.org/project/default_content/-/merge_requests/45/d...
It is possible that Drupal did not detect the service without clearing caches first.
Comment #19
eduardo morales albertiComment #20
eduardo morales albertiRefactor code to delete also inline entities