Implement drush commands for the content import/export

CommentFileSizeAuthor
#76 Screen Shot 2021-09-09 at 3.00.23 PM.png94.61 KBblanca.esqueda
#70 Screenshot 2020-07-07 at 18.19.29.png27.76 KBlexa.mihu
#70 Screenshot 2020-07-07 at 18.16.49.png185.73 KBlexa.mihu
#65 content_sync-drush_commands-2873074-65.patch131.99 KBrhys
#62 content_sync-drush_commands-2873074-62-D8.patch131.97 KBmiguel.leal
#59 interdiff_51-59.patch830 bytesdruplr
#59 content_sync-drush_commands-2873074-59-D8.patch120.33 KBdruplr
#51 content_sync-drush_commands-2873074-51-D8.patch120.37 KBadel-by
#51 interdiff_36-51.patch511 bytesadel-by
#36 content_sync-drush_commands-2873074-36-D8.patch120.34 KBblanca.esqueda
#27 content_sync-drush_commands_fix-get_directory-2873074-27-D8.patch38.35 KBklimp
#27 interdiff_21_27.txt1.36 KBklimp
#25 interdiff-2873074-21-25.txt3.09 KBacmoncadab4
#25 content_sync-drush_commands-2873074-25-8.patch39.29 KBacmoncadab4
#23 content_sync-drush_commands_fix-get_directory-2873074-23-D8.patch30.75 KBklimp
#21 interdiff_18-21.txt6.8 KBliber_t
#21 content_sync-drush_commands-2873074-21.patch38.17 KBliber_t
#20 content_sync-drush_commands-2873074-20.patch36.08 KBliber_t
#19 content_sync-drush_commands-2873074-19.patch8.49 KBliber_t
#18 content_sync-drush_commands-2873074-18.patch36.05 KBgeoffreyr
#14 interdiff-2873074-12-13.txt6.44 KBacmoncadab4
#13 content_sync-drush_commands-2873074-13-8.patch36.06 KBacmoncadab4
#13 content_sync-drush_commands-2873074-13-8.patch36.06 KBacmoncadab4
#12 interdiff-2873074-10-12.txt2.65 KBacmoncadab4
#12 content_sync-drush_commands-2873074-12-8.patch34.89 KBacmoncadab4
#10 interdiff-2873074-9-10.txt5.68 KBacmoncadab4
#10 content_sync-drush_commands-2873074-10-8.patch34.61 KBacmoncadab4
#9 interdiff-2873074-8-9.txt2.56 KBacmoncadab4
#9 content_sync-drush_commands-2873074-9-8.patch32.31 KBacmoncadab4
#8 interdiff-2873074-5-8.txt4.97 KBacmoncadab4
#8 content_sync-drush_commands-2873074-8-8.patch31.41 KBacmoncadab4
#6 interdiff-2873074-5-6.txt3.84 KBacmoncadab4
#6 content_sync-drush_commands-2873074-6-8.patch28.66 KBacmoncadab4
#5 content_sync-drush_commands-2873074-5-8.patch28.41 KBacmoncadab4

Comments

Blanca.Esqueda created an issue. See original summary.

bircher’s picture

I am looking forward to tying out this module when paragraphs are supported.

just fyi, look at how we solved having the same code base for drush and drupal console commands in config_split.
It makes it also easier to support drush 8 and drush 9 commands.

It boils down to creating a cli service that has a method that does what you need to do. Then you add the drush and console commands that get the arguments in their own respective way and pass it to your service which does all the work. This also allows you to test the methods more easily which reduces the surface of possible bugs.

See the drush command and the cli service.

blanca.esqueda’s picture

Hi bircher,

We are planning to do another release next week, on Friday August 4th.
Drush commands and support to paragraphs and in theory any custom field would be included on that release.
We have spent some time re-organizing methods and services, but for sure we would take a look to how you solved it in config_split - Thank you for the tip!

I'll update the status of this issue as soon as the next release is done and would appreciate your feedback.

Regards,
Blanca

websiteworkspace’s picture

Once this module is more fully fleshed out, it would be great to have drush commands for all of this module's functionality, so that the functionality can be incorporated into shell scripts of drush command sets.

acmoncadab4’s picture

Hello, here an implementation for Drush 9.

acmoncadab4’s picture

Adjusts the import source directory.

dabito’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Assigned: blanca.esqueda » dabito
Status: Active » Needs review
acmoncadab4’s picture

Adds files support.

acmoncadab4’s picture

Includes files folder into the exported compressed archive.

acmoncadab4’s picture

Adds entity_types filter.

dabito’s picture

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

The super administrator user cannot be deleted.

acmoncadab4’s picture

acmoncadab4’s picture

StatusFileSize
new6.44 KB
Prabhu.shan’s picture

Hi,

Thanks for the support. Any idea when this feature (drush command for content_sync) will be available.? Any documentation on the same?

Thanks.

pranay agarwal’s picture

Hi Blanca,

Thanks for such a needed module. I was trying out this module when I came to look out for drush commands. If there is any clarity over the roll out of drush commands, please let us know.

Keen subscriber to this issue.

Thanks in advance.

Regards,
Pranay

geoffreyr’s picture

Just been trying this patch out, and while it's great to get this sort of functionality going, it doesn't seem to be all the way there yet.

Example command:
drush content-sync:export --entity_types=block_content,menu_link_content --destination=../content/sync/

What I'd expect to happen:

  • Only block_content and menu_link_content entities are exported
  • YAML files are placed into the ../content/sync directory, relative to the webroot

What actually happens:

  • All entities are exported
  • Exported entities are only available through a tar.gz file which requires an additional request to the server to download
  • There are multiple copies of each entity's export in the base tarball - all of them identical
  • Command doesn't even seem to work unless it's called with sudo - this is probably a local filesystem issue though
  • The error message [error] Message: The content directory type 'sync' does not exist gets displayed

My expectations are probably a bit out of whack though, so I might try and investigate this to see if there's any further work that can be done here.

geoffreyr’s picture

I also had problems getting content-sync:import working from a directory, because the source option wasn't set up to allow a value. I've attached a patch that tweaks #13 to allow a value for this option. (Sorry about the lack of interdiff, my tools are playing up a bit.)

liber_t’s picture

I have an error in Development version
I replace getLogger with getExportLogger in ContentSyncCommands.php

liber_t’s picture

StatusFileSize
new36.08 KB

I'm sorry my old patch (19) is not good

liber_t’s picture

I fixed a bug related to the import.

bander2’s picture

Status: Reviewed & tested by the community » Needs work

Getting this error with #21:

[error] Error: Call to undefined function Drupal\content_sync\Commands\drush_prepare_backup_dir() in Drupal\content_sync\Commands\ContentSyncCommands::getDirectory() (line 717 of /var/www/drupal/web/modules/contrib/content_sync/src/Commands/ContentSyncCommands.php) #0 /var/www/drupal/web/modules/contrib/content_sync/src/Commands/ContentSyncCommands.php(213): Drupal\content_sync\Commands\ContentSyncCommands::getDirectory('sync', true)

Looks like drush_prepare_backup_dir is a drush 8 function. Not sure what the drush 9 equivalent is.

klimp’s picture

Rolled out a wrong patch by mistake

klimp’s picture

acmoncadab4’s picture

Fixes errors:

  1. Class Drupal\content_sync\Commands\ContentSyncCommands contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Drupal\content_sync\Commands\ContentSyncCommands::getLogger).
  2. Call to undefined function Drupal\content_sync\Commands\drush_prepare_backup_dir().
  3. DirectoryIterator::__construct(1): failed to open dir: No such file or directory
manuel.adan’s picture

This is a really needed feature for this module, thank's. It seems that requires drush 9, patch doesn't work in drush 8. I got a reject in content_sync.info.yml, packaging info was added to the patch:

...
      5 --- a/content_sync.info.yml
      6 +++ b/content_sync.info.yml
      7 @@ -2,7 +2,13 @@ name: 'Content Sync'
      8  type: module
      9  description: 'Allows to import/export content using YAML files'
     10  package: Custom
     11 -core: 8.x
     12 +# core: 8.x
     13  configure: content.sync
     14  dependencies:
     15    - serialization
     16 +
     17 +# Information added by Drupal.org packaging script on 2017-12-28
     18 +version: '8.x-2.0'
     19 +core: '8.x'
     20 +project: 'content_sync'
     21 +datestamp: 1514473998
...
klimp’s picture

I didn't get why to rename getExportLogger() to getLogger() in #25

Also, I figured out that the condition

class_exists('FsUtils')

doesn't work but

class_exists('Drush\Utils\FsUtils')

works fine. Tested against Drush 9

Also added default source option value

This patch stems from #21

acmoncadab4’s picture

bircher’s picture

Do you plan to support both drush 8 and drush 9?
If so you should consider putting all the logic in a drush agnostic service and make the drush command very thin just calling the public methods on your agnostic service.

dbjpanda’s picture

Status: Needs work » Needs review
adel-by’s picture

Patch on #27 works fine for me. tested on drupal8.5.5 and drush9

Thanks a lot for this great feature.

ngocketit’s picture

Patch #27 doesn't work for me. It still exports all content entities, no matter what.

zoltán balogh’s picture

Status: Needs review » Reviewed & tested by the community

Patch on #27 works fine for me too

mxt’s picture

Status: Reviewed & tested by the community » Needs work

I used patch #27 with the following instruction:

drush content-sync:export --entity_types=taxonomy_term

Result is not as expected:

ALL entities have been exported (so users, nodes, taxonomies), while it would expected to obtain only taxonomy_term entities exported.

blanca.esqueda’s picture

Assigned: dabito » blanca.esqueda
Status: Needs work » Needs review
StatusFileSize
new120.34 KB

Hi,

Attached the patch that includes the Drush commands for export and import.
IMPORTANT:

  • Apply the patch on top of 8.x-2.x-dev
  • Disable and Re-Enable the module (so the content snapshot is regenerated)
  • Clean the sync content folder - defined in settings.php (so when you export entities are set in the new folder structure)

Notes:
Refactorization of the code was done and these are some of the features included:
- Organization of the content entities into collections (content type and bundle); This is the reason why the snapshot and the content sync folder needs to be regenerated.
- Partial imports/exports filters: by uuids, entity types & bundles, or actions (create/update/delete).
- Exports: an option to include dependencies in the export is provided (because of partial exports);
- Partial imports: dependencies are checked by default if they exist in the active storage and if not then try to pull them from the content sync folder.
- Files: option to import/export physical files or as base64.
- Cache invalidations per entity imported/exported.
- ...

Documentation about the commands: https://www.drupal.org/docs/8/modules/content-synchronization/drush-comm...
Instead of applying the patch, the branch 8.x-2.x from https://github.com/Blanca-Esqueda/content_sync can be pulled - but note that I'm working constantly in that branch.

Thank you to:
@dabito and @acmoncadab4 for the contribution to the CS Drush commands.
@klimp, the refactoring of the code includes some of your patches.

blanca.esqueda’s picture

Note:
PHP 7.2 shows an error when installing the module, to resolve it use the patch in:
https://www.drupal.org/project/content_sync/issues/2982986

sozkara’s picture

I was unable to execute any command:

The drush command 'content-sync:export' could not be found. Run `drush cache-clear drush` to clear the commandfile cache if you have installed new extensions.

Both PHP 7.2 and this patch is applied to 8.x-dev branch

steveoriol’s picture

@sozkara, apparently it only works with drush 9.x, with drush 8.x I had the same problem as you ...

blanca.esqueda’s picture

Yes, it works for Drush 9

sozkara’s picture

I tried with Drush9 today and have some observations:

1. When first enabling the module it takes a whole lot of time to create the db, as I was importing content from a website with 30k users. I had to locally import and delete the users. There should be an option to bypass some entities when creating snapshot.

2. Some entities gave the following error and drush pm-enable stalled:

> In EntityTypeManager.php line 237:
>
>   The "pm_thread_delete_time" entity type did not specify a access handler.
>
>
> batch:process [--format [FORMAT]] [--fields FIELDS] [--field FIELD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-d|--debug] [-y|--yes] [--no] [--remote-host REMOTE-HOST] [--remote-user REMOTE-USER] [-r|--root ROOT] [-l|--uri URI] [--simulate] [--pipe] [-D|--define DEFINE] [--notify [NOTIFY]] [--druplicon] [--xh-link XH-LINK] [--] <command> <batch_id>
>

In ProcessBase.php line 172:

  Output is empty.

I had to delete private message entities although this might be related to corrupt entitites on my part.

3. When enabling the module from the UI, batch processing gave some 500 errors and stalled. drush en seems to work fine.

4. When importing content, the following error happens:

 Do you want to import? (yes/no) [yes]:
 >

>  [notice]
>  [error]  InvalidArgumentException: Placeholders must have a trailing [] if they are to be expanded with an array of values. in Drupal\Core\Database\Connection->expandArguments() (line 729 of /Users/sozkara/Sites/devdesktop/bookmark-dev/docroot/core/lib/Drupal/Core/Database/Connection.php).
>
> In SqlContentEntityStorage.php line 783:
>
>   Placeholders must have a trailing [] if they are to be expanded with an arr
>   ay of values.
>
>
> In Connection.php line 729:
>
>   Placeholders must have a trailing [] if they are to be expanded with an arr
>   ay of values.
>
>
> batch:process [--format [FORMAT]] [--fields FIELDS] [--field FIELD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-d|--debug] [-y|--yes] [--no] [--remote-host REMOTE-HOST] [--remote-user REMOTE-USER] [-r|--root ROOT] [-l|--uri URI] [--simulate] [--pipe] [-D|--define DEFINE] [--notify [NOTIFY]] [--druplicon] [--xh-link XH-LINK] [--] <command> <batch_id>
>

In ProcessBase.php line 172:

  Output is empty.

5. On ImportQueueResolver.php line #58 $file_path is hardcoded.

6. When exporting content with --include-dependencies, I got PHP memory limit exceeded Errors:

> PHP Fatal error:  Allowed memory size of 2688548864 bytes exhausted (tried to allocate 20480 bytes) in /Users/sozkara/Sites/devdesktop/bookmark-prod/docroot/modules/content_sync/src/DependencyResolver/ExportQueueResolver.php on line 28
> PHP Fatal error:  Allowed memory size of 2688548864 bytes exhausted (tried to allocate 32768 bytes) in /Users/sozkara/Sites/devdesktop/bookmark-prod/docroot/vendor/symfony/http-foundation/Response.php on line 1

In ProcessBase.php line 184:

  Unable to decode output into JSON.


content-sync:export [--entity-types [ENTITY-TYPES]] [--uuids [UUIDS]] [--actions [ACTIONS]] [--files [FILES]] [--include-dependencies] [--skiplist] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-d|--debug] [-y|--yes] [--no] [--remote-host REMOTE-HOST] [--remote-user REMOTE-USER] [-r|--root ROOT] [-l|--uri URI] [--simulate] [--pipe] [-D|--define DEFINE] [--notify [NOTIFY]] [--druplicon] [--xh-link XH-LINK] [--] <command> [<label>]

Hope these inputs help you on this project and thank you very much for your efforts!

blanca.esqueda’s picture

Hi @sozkara

Thanks for testing the drush commands.
I'll try to address 1, 3, 5, 6.

But I wasn't able to replicate 2 or 4, maybe it is related to specific type of content entities..
did you try partial imports? did it work or it was giving you the error in #4 for any type of entity?
did you try partial exports? did it work or it was giving you the error in #2 for any type of entity?

sozkara’s picture

Hello @Blanca

Yes, I'm trying partial imports #2 & #4 like this:
drush content-sync:import --entity-types=node,menu
or
drush content-sync:import --entity-types=menu

mattsqd’s picture

This might be an edge case but if you have field permissionson an entity, since this command is running through Drush instead of the UI, the logged in user is the anonymous user instead of whoever started the batch process through the GUI.

I put this in \Drupal\content_sync\Form\ContentExportTrait::processContentExportFiles() and it allowed me to export all fields. I don't know if this is a security risk or if there is a better approach.

if (\Drupal::currentUser()->id() === 0) {
      $user = User::load(1);
      user_login_finalize($user);
    }
wwwprola’s picture

The patch works for making Drush commands available to me, but they don't seem to work as expected.

After running export, the list of items to export returns blank. I can't run --actions=create as it doesn't seem to work with specific only specific entity types, and there far too many entities in the site; I run into PHP Memory exhuasted errors, even at ridiculously high limits.

Below is the blank table I receive when trying to export. Am I missing a step?

 $ ../bin/drush content-sync:export --entity-types=node.article
Differences of the active content to the export directory:

+------------+--------------+-----------+
| Collection | Content Name | Operation |
+------------+--------------+-----------+

 Do you want to export? (yes/no) [yes]:
 >

rivimey’s picture

A note about the field permission issue and the UID, there *used to be* an option "-u" to set the user to run as, but this has been removed in Drush 9; for how to do it there, look at #2861591: Export content as user 1 when running in a CLI context

Is there any chnce of an update to the patch, as there looks to be a few niggles? :-) :-)

dimmech’s picture

This patch does not apply against the Dev branch as directed on #36. It does however successfully apply on the 8.x-2.1 version and I can confirm that the commands work.

Is there a breaking change to the drush commands for this module in the Dev branch?

aangel’s picture

@dimmech: Alas, just three days later and I cannot get it to apply.

blanca.esqueda’s picture

@aangel, what error do you get when trying to apply the patch?
Nothing has been changed on those branches since days ago so it should still apply.

@dimmech, no.. if I remember correctly in dev there is only a couple of patches more. But nothing that should affect the Drush commands.

murz’s picture

I have same problem as @wwwprola with empty list on using Drush commands:

$ drush content-sync:export --entity-types=user
Differences of the active content to the export directory:

+------------+--------------+-----------+
| Collection | Content Name | Operation |
+------------+--------------+-----------+

 Do you want to export? (yes/no) [yes]:
 > yes

And I see no files in content sync folder. Content Sync version 8.x-2.1, Drupal version is 8.7.3, Drush version 9.7.0.
Maybe I need to use only dev version of module for this patch?

adel-by’s picture

StatusFileSize
new511 bytes
new120.37 KB

Hi @Blanca

File entites are imported, but actual files do not get copied from sync folder to the "files" folder.
I had to set the option ['include_files' => 'folder'] on the import command.

Also the method \Drupal\content_sync\DependencyResolver\ImportQueueResolver::depthFirstSearch references an absolute path, i assume this is work in progress or a debug code of yours?
$file_path = "/Users/Blanca/Sites/devdesktop_opin/do/../content/sync/entities/".$entity_type_id."/".$bundle."/".$identifier.".yml";

btw thanks a lot for this useful module!

perarg’s picture

As @dimmech and @aangel mentioned, i confirm that the patch #36 or #51 are applied successfully only in 8.x-2.1. In dev version are failed.

I just confirm @wwwprola and @murz about the empty table when drush content-sync:export

UPDATE: The https://github.com/Blanca-Esqueda/content_sync is working without patches.

tedwyer’s picture

One thing I've noticed here is that the drush content sync export command "--entity-types=page or article etc. won't work. But this will; --entity-types=node.page.
If you do an export of --entity-types=node you will get a list of all nodes on the site with the proper node."entity" name. Don't say yes. Hope this helps.

abychkov’s picture

@wwwprola @murz @perarg

The empty table occurs because there is nothing to import to your website because the drush commands except a file structure for the different entities and files. This follows the naming scheme of the .yml files.
A location node will be stores in /sync/entities/node/location, users in sync/entities/user/user, groups in sync/entities/group/groupname, etc.

So you can't just dump the content.tar.gz and unzip it and import it like you can with config.

murz’s picture

@abychkov, I trying to export content, not import :)
@tedwyer, about --entity-types=node.page - with #51 patch there are no success:

$ drush content-sync:export --entity-types=node.page
Differences of the active content to the export directory:

+------------+--------------+-----------+
| Collection | Content Name | Operation |
+------------+--------------+-----------+

 Do you want to export? (yes/no) [yes]:
 > 

So results are empty, but website have 8 nodes with type "page".
And same empty result for --entity-types=node..

Here is debug and verbose output:

$ drush content-sync:export --entity-types=node.page -v -d
 [preflight] Redispatch to site-local Drush: drupal/vendor/drush/drush/drush.
 [preflight] Config paths: drupal/vendor/drush/drush/drush.yml,drupal/drush/drush.yml
 [preflight] Alias paths: drupal/web/drush/sites,drupal/drush/sites
 [preflight] Commandfile search paths: drupal/vendor/drush/drush/src,drupal/drush
 [debug] Bootstrap further to find content-sync:export [0.11 sec, 8.22 MB]
 [debug] Trying to bootstrap as far as we can [0.11 sec, 8.22 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalRoot() [0.11 sec, 8.22 MB]
 [bootstrap] Change working directory to drupal/web [0.11 sec, 8.22 MB]
 [bootstrap] Initialized Drupal 8.7.7 root directory at drupal/web [0.12 sec, 8.41 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalSite() [0.12 sec, 8.7 MB]
 [bootstrap] Initialized Drupal site default at sites/default [0.13 sec, 8.87 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.13 sec, 8.87 MB]
 [debug] Add service modifier [0.13 sec, 9.09 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalDatabase() [0.14 sec, 9.51 MB]
 [bootstrap] Successfully connected to the Drupal database. [0.14 sec, 9.51 MB]
 [bootstrap] Drush bootstrap phase: bootstrapDrupalFull() [0.14 sec, 9.51 MB]
 [debug] Start bootstrap of the Drupal Kernel. [0.14 sec, 9.51 MB]
 [debug] Finished bootstrap of the Drupal Kernel. [0.24 sec, 17.97 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\config\ConfigCommands [0.52 sec, 43.8 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\config\ConfigExportCommands [0.52 sec, 43.83 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\config\ConfigImportCommands [0.53 sec, 43.84 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\BatchCommands [0.53 sec, 43.84 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\CliCommands [0.53 sec, 43.85 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\DrupalCommands [0.53 sec, 43.85 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\EntityCommands [0.53 sec, 43.86 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\ImageCommands [0.53 sec, 43.87 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\JsonapiCommands [0.53 sec, 43.88 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\LanguageCommands [0.53 sec, 43.89 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\LocaleCommands [0.53 sec, 43.9 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\MessengerCommands [0.53 sec, 43.91 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\QueueCommands [0.53 sec, 43.91 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\RoleCommands [0.53 sec, 43.92 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\StateCommands [0.54 sec, 43.94 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\TwigCommands [0.54 sec, 43.96 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\UserCommands [0.54 sec, 43.97 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\ViewsCommands [0.54 sec, 44.01 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\core\WatchdogCommands [0.54 sec, 44.04 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\pm\PmCommands [0.54 sec, 44.07 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\pm\ThemeCommands [0.54 sec, 44.08 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeCommands [0.54 sec, 44.09 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeCommentsCommands [0.54 sec, 44.09 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeSessionsCommands [0.54 sec, 44.09 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeUserFieldsCommands [0.55 sec, 44.09 MB]
 [debugnotify] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeUserTableCommands [0.55 sec, 44.1 MB]
 [debugnotify] Add a commandfile class: Drupal\config_split\Commands\ConfigSplitCommands [0.55 sec, 44.1 MB]
 [debugnotify] Add a commandfile class: Drupal\content_sync\Commands\ContentSyncCommands [0.55 sec, 44.11 MB]
 [debugnotify] Add a commandfile class: Drupal\devel\Commands\DevelCommands [0.55 sec, 44.12 MB]
 [debugnotify] Add a commandfile class: Drupal\devel_entity_updates\Commands\DevelEntityUpdatesCommands [0.55 sec, 44.15 MB]
 [debugnotify] Add a commandfile class: Drupal\search_api\Commands\SearchApiCommands [0.55 sec, 44.15 MB]
 [debugnotify] Add a commandfile class: Drupal\search_api_solr\Commands\SearchApiSolrCommands [0.55 sec, 44.23 MB]
 [debugnotify] Add a commandfile class: Drupal\views_bulk_operations\Commands\ViewsBulkOperationsCommands [0.55 sec, 44.25 MB]
 [debugnotify] Add a commandfile class: Drupal\pathauto\Commands\PathautoCommands [0.56 sec, 44.26 MB]
 [debug] Done with bootstrap max in Application::find(): trying to find content-sync:export again. [0.56 sec, 44.27 MB]
 [bootstrap] Starting bootstrap to none [0.56 sec, 44.31 MB]
 [bootstrap] Drush bootstrap phase 0 [0.56 sec, 44.31 MB]
 [bootstrap] Try to validate bootstrap phase 0 [0.56 sec, 44.31 MB]
Differences of the active content to the export directory:

+------------+--------------+-----------+
| Collection | Content Name | Operation |
+------------+--------------+-----------+

 Do you want to export? (yes/no) [yes]:
 > 
$

How can I fix this problem?

abychkov’s picture

@Blanca
depthFirstSearch in ImportQueueResolver will go into an infinite recursive loop if you have circular dependencies when importing.
This usually causes the import to hang for ages and then it throws a PHP fatal error of exhausting the available memory. In the web client this usually results in an "ajax http 500 error"

Example
A depends on B
B depends on C
C depends on A

@murz
I had a similar problem at some point and I got around it by unpublishing and then republishing the content.

panshulk’s picture

Facing the same issue mentioned in comment #55 : https://www.drupal.org/project/content_sync/issues/2873074#comment-13273732
Anyone else also facing this ?
Any idea how to fix this ?

rijidij’s picture

Thank you to all contributors for your work on this module.

@Blanca, any idea when the code on Github mentioned in comment #36 will be merged into the official repo?

druplr’s picture

#51 worked for me except for my existing groups (group module 8.x-1.0-rc4) created before enabling the module. They didn't get exported using drush. But new groups did get exported as expected. Couldn't re-publish groups as @abychkov indicated, at least I don't know how to do that with groups.

To get it working with my pre-existing groups, I exported them manually at admin/config/development/content/export/single and saved them at content/sync/entities/group/group_name/group.group_name.UUID.yml. Then ran drush csi --entity-types=group. Even though the group existed, drush thought it was creating a new group, but it actually updated the existing one (group ID 1), which was intended (drush output pasted below). After that, my groups do get exported as expected.

Differences of the export directory to the active content:

+--------------------+-----------------------+-----------+
| Collection         | Content Name          | Operation |
+--------------------+-----------------------+-----------+
| group.group_name   | group.group_name.UUID | Create    |
+--------------------+-----------------------+-----------+

 Do you want to import? (yes/no) [yes]:
 > 

>  [notice] 
>  [notice] Imported content New Group Title (group: 1).

Attaching an updated version of @adel-by's patch with the hard-coded path ("/Users/Blanca/Sites/devdesktop_opin/do/") removed, as indicated in #51.

alessandro.sighnolfi’s picture

i try to install the last patch,
the patch does't find file.
After i manually check and Miss Drush Service

Thanks

jcnventura’s picture

Status: Needs review » Needs work

I'm pretty sure that the change in #59 should use content_sync_get_content_directory(CONFIG_SYNC_DIRECTORY) instead of ./content/sync

miguel.leal’s picture

Applying #59 i had some issues with missing service (content_sync.manager) and wrong entityType declaration, after trying to import the content.

cesardmoro’s picture

Any of this patches are not running on the dev version downloaded by composer, you have to download from this git https://github.com/Blanca-Esqueda/content_sync to make it work, can you publish this versión to drupal so it download from composer ?

tahiche’s picture

Hi,
I was trying out the patch in "https://www.drupal.org/project/content_sync/issues/2985646" regarding an option for Bulk export an i´m getting the following error:

Error: Call to undefined method Drupal\content_sync\Form\ContentExportMultiple::generateBatch() in Drupal\content_sync\Form\ContentExportMultiple->submitForm() (line 160 of modules/contrib/content_sync/src/Form/ContentExportMultiple.php).

This is the line in ContentExportMultiple.php

if (!empty($entities_list)) {
        $batch = $this->generateBatch($entities_list);
        batch_set($batch);
      }

It seems like the patch is not changing ContentExportMultiple like it does with, say, ContentExportForm where generateBatch() is now generateExportBatch()

This is how the patch changes the function to be called
- batch = $this->generateBatch($entities_list);
+ $serializer_context['export_type'] = 'tar';
+ $serializer_context['include_files'] = 'folder';
+ $batch = $this->generateExportBatch($entities_list, $serializer_context);

I´m going to try and change ContentExportMultiple the same way and see if it works.

rhys’s picture

StatusFileSize
new131.99 KB

I've slightly modified the #62 patch so that it cleanly applies against the 8.x-2.1 version that is downloaded via composer.json.

kwadz’s picture

Status: Needs work » Needs review

blanca.esqueda’s picture

Issue summary: View changes
blanca.esqueda’s picture

Issue summary: View changes

Hi,

8.x-2.x-dev has been updated.
It includes the Drush commands and some other patches.

IMPORTANT:

YAML content entity files and folder tree structure are different from the previous versions as refactoring of code was needed to implement more functionality. 8.x-2.x-dev version has to run on the source and target sites.

Steps to use 8.x-2.x-dev:

  • Pull code from 8.x-2.x-dev
  • Disable and Re-Enable the module (so the content snapshot is regenerated)
  • Clean the sync content folder - defined in settings.php (so when you export entities are set in the new folder structure)

Note:
If Drush commands work then we can mark this issue as reviewed and then fixed.
And if needed let's open separate issues for functionality as:

  • Empty Table not showing differences in the export directory to the active content.
  • ImportQueueResolver will go into an infinite recursive loop
  • ...
lexa.mihu’s picture

Hi,

I can confirm that drush content-sync:export works now, with dev version.

console result

folder structure

ñull’s picture

I wanted to test this but after installing I don't see the drush commands anywhere:

composer require 'drupal/content_sync:2.x-dev'
drush content-sync:export
The drush command 'content-sync:export' could not be found.  Run `drush cache-clear drush` to clear the commandfile cache if you have installed new extensions.                                                                                      [error]

Yes I made sure was actually un- and reinstalled, cache cleared. Is the code not installable through composer? I see the drush.services.yml file so the code OK. What could cause it to remain undetected?

drou7’s picture

Same as #71, maybe because I am using Drush 8?

robotjox’s picture

I can confirm that drush commands are not working on content_sync:2.x-dev.
Have uninstalled/reinstalled and flushed all caches numerous times.
drush.services.yml is present.

The drush command 'content-sync' could not be found.

Edit: Sorry, my mistake - you need Drush 9, then it works

tonytheferg’s picture

Drush 9 is end of life

liquidcms’s picture

haven't dug in too much but this doesnt apply to my version of the module. possibly due to having the 9.x version from here: #3114499: Drupal 9 Readiness

- Installing drupal/content_sync (dev-8.x-2.x 849858f): Cloning 849858fca1 from cache
- Applying patches for drupal/content_sync
https://www.drupal.org/files/issues/2020-09-22/2979368-17.patch (2979368 - ignore types)
https://www.drupal.org/files/issues/2020-04-06/content_sync-drush_comman... (2873074 - drush commands)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-04-06/content_sync-drush_comman...

[Exception]
Cannot apply patch 2873074 - drush commands (https://www.drupal.org/files/issues/2020-04-06/content_sync-drush_comman...
h)!

blanca.esqueda’s picture

Title: Drush commands » Drush commands [D9]
Version: 8.x-2.x-dev » 3.0.x-dev
Status: Needs review » Fixed
StatusFileSize
new94.61 KB

Please note the patches were done only for Drush 9 (I tested on Drush version: 9.7.2)
Tried the Drush command with the version that supports D9: 3.0.x-dev
And it works:
cs drush 9

I'm marking as fixed this issue - all patches have been added to 3.0.0-Beta1, and 8.2.1.
I'll open a new ticket for Drush Commands [D10]

blanca.esqueda’s picture

Issue tags: +Drush-9
Related issues: +#3232205: Drush Commands [D10]
lquessenberry’s picture

Hello. I have Drush 9 and Dev 3.x version of this module and I still can't get Drush to recognize the commands. Am I missing something simple like drush updb -y or drush cr?

I can't seem to get it to work.

lquessenberry’s picture

Update, I can now use the drush command, but when I export, nothing happens.

https://dsh.re/6fea2d

What am I missing?

blanca.esqueda’s picture

Does the content folder has YML files? if the content folder is not populated most probably the snapshot hasn't been created.
If you exported already once, then there are no differences and nothing to export.
If you are able to use the Drush commands, let's follow the export in another issue.

lquessenberry’s picture

Thank you Blanca. Our call discussing this fixed my issue. It was helpful to remind myself to check fire permissions and folder permissions of the content/sync folder.

Status: Fixed » Closed (fixed)

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