Hi,
i created a patch for a drush command to export the module defined entites with references.

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

Christian.wiedemann created an issue. See original summary.

sam152’s picture

Status: Active » Needs review
andypost’s picture

Status: Needs review » Needs work
+++ b/drush/default_content.drush.inc
@@ -41,7 +41,14 @@ function default_content_drush_command() {
+    'description' => dt('Exports all the content with theire referencs defined in a module info file.'),

here's some typos

pguillard’s picture

Status: Needs work » Needs review
StatusFileSize
new3.23 KB
new563 bytes

Just corrected the typos

Algeron’s picture

#4 works on latest dev.

Algeron’s picture

Status: Needs review » Needs work

When a module .info file marks an entity for export AND that same entity is detected as a reference by another entity, the result is that the entity gets exported twice in the same .json file, producing invalid syntax.

Steps to reproduce:
- Create 2 content types. #1 just has a title. #2 has a title and an entity reference field to #1.
- Create a node for each. In node 2, reference node 1.
- Create a module for use with default-content-export-module-with-references. Add the UUIDs of nodes 1 and 2 in this file. Export the content.

Result:
The JSON file for node 1 will contain duplicate output. There will be two top-level JSON tags, which is considered invalid syntax. Attempting to re-import the files will result in an error.

Algeron’s picture

Status: Needs work » Needs review
StatusFileSize
new4.38 KB
new1.46 KB

Updated patch in attachment. Sadly it conflicts with #2815051: Skip exporting core users by default.

Status: Needs review » Needs work

The last submitted patch, 7: default_content-drush_dcemr-2703607-7.patch, failed testing.

pguillard’s picture

Status: Needs work » Needs review
StatusFileSize
new4.49 KB

Patch rerolled

aaronbauman’s picture

+1 for this feature.
Should we also alert the user about new content that was exported?
Otherwise, how will we update the .info.yml file with the new UUIDs?

pguillard’s picture

Issue tags: +DevDaysSeville
dawehner’s picture

Issue tags: +Needs tests

IMHO some level of test coverage would be super helpful.

larowlan’s picture

Status: Needs review » Needs work
+++ b/src/DefaultContentManager.php
@@ -270,7 +279,10 @@ class DefaultContentManager implements DefaultContentManagerInterface {
     foreach ($entities as $entity) {

@@ -295,6 +307,22 @@ class DefaultContentManager implements DefaultContentManagerInterface {
+  public function exportModuleWithReferences($module_name) {

This needs to go on the exporter now we've split the two. Needs a docblock too

And, yep - needs tests - could use vfsStream to simulate file system.

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new4.24 KB

Here's a reroll.

larowlan’s picture

Thanks, we just need a test now - nice work.

eelkeblok’s picture

Would it make sense to fold this functionality into the dcer command, with a --module option?

jurriaanroelofs’s picture

Great, +1, but I got an error because there was still a reference to the manager service. Here's a fixed patch and interdiff.

joachim’s picture

Status: Needs review » Needs work

> Would it make sense to fold this functionality into the dcer command, with a --module option?

+1 to that.

Also, this is going to need to be ported to Drush 9.

joachim’s picture

I've added the Drush 9 command.

> Would it make sense to fold this functionality into the dcer command, with a --module option?

Don't have the time to do that, I'm afraid, so will leave that for the next person who can push this forward a little!

marios anagnostopoulos’s picture

2.0.x uses a completely different normalization implementation that does not depend on hal.module anymore.

Does this make this issue's progress up to #19 obsolete?

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

justafish’s picture

Status: Needs work » Needs review

I've created a new drush command that works with 2.0.x

damienmckenna’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs review » Reviewed & tested by the community

I've tested the latest merge request from justafish and it works great.

damienmckenna’s picture

damienmckenna’s picture

The only issue I have is that I'd like to be able to define entity types not to export, e.g. the "user" entity. For example, if I export a block that has a media item, which has a file record and then a file, which all point to a user object, the command exports the block, media, file items and the file itself, but not the user. That said, the improvement could be done as a follow-up.

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

  • berdir committed 2fd73122 on 2.0.x authored by justafish
    Issue #2703607 by pguillard, berdir, Algeron, jurriaanroelofs, christian...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Merged, after rebasing to remove the .drush.inc changes (which is now removed).

Never used the module based exports myself, doing that with recipes in the future might be more useful, we'll see.

Status: Fixed » Closed (fixed)

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