Problem/Motivation

It's useful to be able to specify bundles to export rather than exporting all bundles for an entity type. Patch attached adds a --bundles option to the drush 'dcer' command.

Steps to reproduce

drush dcer --help
Could not open input file: vendor/bin/drush
/var/www/html/web $ drush dcer --help
Exports an entity and all its referenced entities.

Arguments:
 entity_type                               The entity type to export.      
 entity_id                                 The ID of the entity to export.

Options:
 --bundles=<article,page>                  A comma-separated list of bundles to limit export to.         
 --folder                                  Folder to export to, entities are grouped by entity type into 
                                           directories.

Proposed resolution

Limiting queries by bundle list, throw exception when filter is not applicable (missing bundle field)

Remaining tasks

review/commit

User interface changes

no

API changes

no

Command icon 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

bgilhome created an issue. See original summary.

nashkrammer’s picture

Tested on core 8.5.8 for menu_link_content entity with bundle main. Patch works for with option --bundle

drush dcer menu_link_content --bundle=main --folder=modules/custom/mymodule/content/
berdir’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs review » Needs work

I've recently created the 2.0.x branch, see the project page on all the improvements in the 2.0.x branch. Testing that and providing feedback would be very welcome. The 1.x branch isn't actively maintained and won't receive new features anymore.

I'm changing this to 2.x as it would be a useful feature there as well, but it needs to be rerolled and support for Drush9+ needs to be handled as well.

sonnykt’s picture

Status: Needs work » Needs review
StatusFileSize
new2.71 KB
new2.73 KB
new2.25 KB

This patch checks for bundle support and adds support for Drush 9.

andypost’s picture

StatusFileSize
new3.96 KB
new3.39 KB

++ to get this feature in but better configurable - to allow a list of bundles

Also tuned a bit new option documentation

sonnykt’s picture

Hi @andypost,

I see that you use entityTypeManager instead of the original entityQuery. The exportContentWithReferences method of the exporter expects an ID of the entity to export instead of the entity object. Is it an issue?

andypost’s picture

Title: Add `drush dcer` option to specify bundle » Add `drush dcer --bundles` option to limit export
Issue summary: View changes

@sonnykt because no reason to instantiate storage handler twice

Better title and summary

johnwebdev’s picture

+++ b/drush/default_content.drush.inc
@@ -76,8 +80,19 @@ function drush_default_content_export_references($entity_type_id, $entity_id = N
+        throw new \Exception("The entity type {$entity_type_id} only exposes a single bundle.");

+++ b/src/Commands/DefaultContentCommands.php
@@ -59,12 +60,29 @@ class DefaultContentCommands extends DrushCommands {
+          throw new \Exception("The entity type {$entity_type_id} only exposes a single bundle.");

We should use sprintf() to be consistent with the rest of the code base. Should this be an InvalidArgumentException instead?

andypost’s picture

Status: Needs review » Needs work

++ to #8

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB
new3.45 KB

Here's fixed patch

johnwebdev’s picture

Status: Needs review » Reviewed & tested by the community
andypost’s picture

johnwebdev’s picture

Yes, but within Default Content we're currently using sprintf(), and that make this change consistent. So if core re-evaluates its use of sprintf, so can we, but in a follow up issue imo.

rowrowrowrow made their first commit to this issue’s fork.

Rajeshreeputra made their first commit to this issue’s fork.

andypost’s picture

Status: Reviewed & tested by the community » Needs review

@Rajeshreeputra any reason you're created MR? last patch applies

bladedu’s picture

I confirm that patch #10 works perfectly.

Thanks!

berdir’s picture

Status: Needs review » Needs work

There is a large overlap between this issue and #2786479: Drush comand to export all items from entity with defined criteria . This is easier to use for bundles and supports multiple values, but doesn't support common use cases like all links of a given menu. I recommend to join forces over there and address my review and merge in the useful bits from this like multiple values.

pearls’s picture

+1 for the approach to this issue compared to the other one( #2786479).
I think bundle limit is useful and necessary.