Problem/Motivation

For users that likes UI-less experience we need a drush command.

By using the drush command you can easyally export any allowed content or bunch of content (zip) into a target folder or with option --dry-run display in the console. There should be options do to the following (include translations, include assets)

By using the drush command you can easyally import the exported content (file or zip).

CommentFileSizeAuthor
#12 drush-commands-3345288-12.patch56.7 KBcameron prince
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

nginex created an issue. See original summary.

artycal’s picture

Assigned: Unassigned » artycal

artycal’s picture

Issue summary: View changes
artycal’s picture

Issue summary: View changes
artycal’s picture

Issue summary: View changes
artycal’s picture

Assigned: artycal » nginex
Status: Active » Needs review
reece.oliver’s picture

Hey @artycal, may I request a feature to be added into these drush commands? I see that you have added the ability to export specific entity ids do you think it would be possible to add to the import commands the ability to import to a specific entity id as well?

My use case is that I have two sites and the entity IDs of say A basic page that is present on both sites may not necessarily be the same but the content is. This would be helpful because i could make changes on my "dev" site to the basic page and then I could export and import those changes to my "prod" site to the basic page which has a different ID.

I think this would a useful feature to add as from my experience if you haven't used a content sync module in the past and have been copying changes over sites manually your node/entity ids wouldn't necessarily link up if created in different orders

artycal’s picture

Hi @reece.oliver

If I understand your request correctly, you want to be able to import content from an export into another entity that doesn't necessarily have the same entity id.

I can see the value in that, but this is is better moved to a separate issue, as it is not only related to the drush commands, but could also be a good general functionality to have in the ui too

artycal’s picture

@reece.oliver
An alternative approach for your issue might be to downsync your live database to your dev environment. In that case, the uuid's will match up, and then any changes exported from dev to live shouldn't be a problem.

Replacing uuid's is possible, but there is the issue of how to handle any references that the content may provide, as there might be duplicates if those are also using a different uuid.
Or there might be references to the wrong content, if there is a uuid on the dev that is in use by some other content on the live environment.

reece.oliver’s picture

Yes you understood correctly. Okay I understand, so many variables to think about here. The sql sync command didn't cross my mind I shall look further into this and see if that can circumvent this problem for me. Thank you for your help :)

cameron prince’s picture

StatusFileSize
new56.7 KB

I've been testing this, but had to re-roll the patch. It looks like it's either outdated or it's trying to patch on top of another patched version instead of origin.

The export ran without error and the zip file was created when testing with about 10 nodes. The import fails with a AssertionError: Cannot load the "file" entity with NULL ID. error. I think this may be related to my setup.

I'm going to test again on another environment and will report back.

cameron prince’s picture

We tested this again today on the servers where the source images are and it worked well. I believe this will be ready for RTBC once the MR is updated so the patch applies.

mortona2k’s picture

Status: Needs review » Reviewed & tested by the community

The latest MR applies and the drush export/import from zip is working, with content entity ids.

@cameron prince I was getting that error when it was in my private directory, but it is working in public.

nginex’s picture

Assigned: nginex » Unassigned
Status: Reviewed & tested by the community » Needs work

Hi @artycal,

Thanks for the patch, please fix my notes to move on with this issue.

artycal’s picture

Status: Needs work » Needs review
qzmenko’s picture

Status: Needs review » Needs work

Thanks for the work! Please check my notes to MR.

artycal’s picture

Issue summary: View changes

@Kuzmenko Thanks for your work on this.
I propose to also add an interface for the helper class.
Will need to investigate the DRUPAL_ROOT alternative to the $this->requestStack->getCurrentRequest()->server->get('PWD')

artycal’s picture

Took another look at this.
I don't think we should be using the DRUPAL_ROOT approach for the outputpath. It should be using relative path as it was before. Rather than changing the result to a path from the DRUPAL_ROOT, it should be investigated how to make that relative path work for all users. It also doesn't make much sense to me to use DRUPAL_ROOT, as the fall back for a NULL in $this->requestStack->getCurrentRequest()->server->get('PWD') was already the default export location.

samlerner’s picture

I just pulled down this branch and it looks like the DRUPAL_ROOT and/or get->('PWD') solutions are replaced with things like

$grandparent_path = \Drupal::root();

Can we consider that issue resolved? I also went through the unresolved issues in the MR, and it looks like they were fixed weeks ago.

I recently tested the drush commands to export a page in Layout Builder with multiple uploaded images, and both the import and export worked like a charm on my Drupal 9.5.10 site. What needs to happen next to get this merged?

artycal’s picture

Issue summary: View changes
artycal’s picture

Assigned: Unassigned » nginex
Issue summary: View changes
Status: Needs work » Needs review

We have decided to go with the Drupal::root() approach after all. So this can be considered resolved after review.

yashsk8’s picture

Hello, I tried applying the latest patch locally to my Drupal installation which is successful. The web/modules/contrib/single_content_sync reflects the updated files and folders. The issue that I am facing is that drush is unable to recognize the Commands. However, It recognizes commands from all the other contrib modules. I am using drush 10.6.2 and Drupal 9.5.9. Am I missing something here? Thanks in advance!

PS: I tried everything from rebuilding the app from scratch, clearing drush cache etc. I also checked the drush --debug logs where it shows the files that it is able to pick up. The single_content_sync command file does not show up in that log.

mortona2k’s picture

Version: 1.3.x-dev » 1.4.x-dev

I rebased onto the 1.4.x branch.

dblanken’s picture

I was able to test merge !59 on 1.4.x and it is working great locally. I am so psyched to see this Drush command and how flexible this project is that it can handle other exports like media and taxonomy_terms. Thank you so much for your work on this, and great job on this project as a whole!

samlerner’s picture

Status: Needs review » Reviewed & tested by the community

I tested !59 as well and it's working great for me on Drupal 9.5.10. Setting to RTBC.

@yashsk8 did you try cloning the repo and checking out MR !59 instead of applying a patch? After doing that and running drush cc drush I saw the content:export and content:import commands listed in the drush status.

  • nginex committed 22590de0 on 1.4.x authored by mortona2k
    Issue #3345288: Provide a drush command to export/import content
    
nginex’s picture

Assigned: nginex » Unassigned
Status: Reviewed & tested by the community » Fixed

What a great work guys, love it so much, thank you all

Status: Fixed » Closed (fixed)

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