Comments

-enzo- created an issue. See original summary.

-enzo-’s picture

StatusFileSize
new10.01 KB

I did two Drupal Console commands

[generate:default:content] entity-type entity-id --module
[generae:default:content:taxonomy] vocabulary id --module

Both commands allow users to select the module they want to use to export the entities, the name of file exported in automatically calculated base in entity name property.

larowlan’s picture

  1. +++ b/console/translations/en/default.content.export.taxonomy.yml
    @@ -0,0 +1,12 @@
    +description: 'Exports a taxonomy term entities for a specific Taxonomy'
    

    %s/a/all

  2. +++ b/console/translations/en/default.content.export.taxonomy.yml
    @@ -0,0 +1,12 @@
    +  module: 'The Module to export taxonony terms'
    

    %s/taxonomy terms/taxonomy terms to

  3. +++ b/console/translations/en/default.content.export.taxonomy.yml
    @@ -0,0 +1,12 @@
    +  taxonomy-exported: 'Taxonomy %s was exported at module %s'
    

    %s/at/to

  4. +++ b/console/translations/en/default.content.export.taxonomy.yml
    @@ -0,0 +1,12 @@
    +  module-not-found: 'Module to export was not provided'
    

    %s/export/export to

  5. +++ b/console/translations/en/default.content.export.yml
    @@ -0,0 +1,13 @@
    +  entity-exported: 'Entity %s with id %s was exported at file %s'
    

    %s/at/to

  6. +++ b/console/translations/en/default.content.export.yml
    @@ -0,0 +1,13 @@
    +  module-not-found: 'Module to export was not provided'
    

    %s/export/export to

  7. +++ b/src/Command/DefaultExportCommand.php
    @@ -0,0 +1,138 @@
    +    if($entity) {
    ...
    +  protected function interact(InputInterface $input, OutputInterface $output)
    +  {
    ...
    +    // --module option
    
    +++ b/src/Command/DefaultExportTaxonomyCommand.php
    @@ -0,0 +1,131 @@
    +    if($taxonomyEntity) {
    ...
    +      foreach($terms as $term) {
    ...
    +  protected function interact(InputInterface $input, OutputInterface $output)
    +  {
    ...
    +    // --module option
    

    nit: phpcs issues here

  8. +++ b/src/Command/DefaultExportTaxonomyCommand.php
    @@ -0,0 +1,131 @@
    +    $taxonomyManager = $this->getDrupalService('entity.manager')->getStorage('taxonomy_vocabulary');
    +    $taxononyTermManager = $this->getDrupalService('entity.manager')->getStorage('taxonomy_term');
    

    Can we give these better names, vocabularyStorage and termStorage?

  9. +++ b/src/Command/DefaultExportTaxonomyCommand.php
    @@ -0,0 +1,131 @@
    +    $taxonomyEntity = $taxonomyManager->load($taxonomyVid);
    

    Can we call this what it is - vocabulary?

  10. +++ b/src/Command/DefaultExportTaxonomyCommand.php
    @@ -0,0 +1,131 @@
    +      $query->condition('vid', "$taxonomyVid");
    

    no need to quote

  11. +++ b/src/Command/DefaultExportTaxonomyCommand.php
    @@ -0,0 +1,131 @@
    +        $termEntity = $taxononyTermManager->load($term);
    

    Does console support batching? This could be a very slow process on a big vocabulary? Can we use the symfony progress indicator to give some visual feedback?

-enzo-’s picture

StatusFileSize
new10.04 KB

I applied almost all suggestion you did, except by phpcs, feel free to apply after merge if you decide to apply the patch.

About symfony progress, it's totally possible, but I didn't use before.

-enzo-’s picture

StatusFileSize
new10.02 KB

Ignore the previous patch file

darol100’s picture

Status: Active » Needs review
StatusFileSize
new4.5 KB

Here is the interdiff

greg.1.anderson’s picture

-enzo-, did you see #2703131? @jmolivas and @darol100 and I worked quite a bit on trying to get to a point where it would be possible for Drupal 8 contrib modules to provide cli tools that run with both Drush and Drupal Console. Are you interested in this sort of collaboration?

Also, Robo-PHP (http://robo.li) provides easy integration with the Symfony Progress component. Not that it's difficult to use the API directly either, but there was some interest in investigating using teh Robo task runner in Drupal Console. This might be as good a time as any to look into this.

-enzo-’s picture

Hi @greg.1.anderson

To be honest, I did the command before I discover there was an intention to work in that direction, I just need to run these commands with Drupal Console so I just did

About the effort to work towards standard tools, there is something not quite that stable. We (Drupal Console Team) want to focus our efforts first in getting our first 1.0.0 stable release

avibrazil@gmail.com’s picture

Please advise about which patch to use (#5 ?) against which version of the module (-dev ?) to make it usable with Drupal Console.

Thank you

-enzo-’s picture

You need to apply the patch against branch 8.x-1.x-dev

-enzo-’s picture

StatusFileSize
new10.79 KB

New patch to prepare changes for Drupal Console RC1

-enzo-’s picture

Hi @avi

If you install Drupal 8 using the Drupal Composer project using a command like this

composer create-project drupal-composer/drupal-project:8.x-dev drupal8.dev \
--no-dev \
--prefer-dist \
--no-interaction \
--no-progress \
--optimize-autoloader 

You only need to edit your composer.json file to add this dependencies

 "require": {
        "ext-curl": "*",
        "composer/installers": "^1.0.20",
        "cweagans/composer-patches": "~1.0",
        "drupal-composer/drupal-scaffold": "^2.0.1",
        "drupal/commerce": "8.2.x-dev",
        "drupal/console": "~1.0",
        "drupal/core": "8.1.x-dev",
        "drupal/default_content": "dev-8.x-1.x",
        "drupal/devel": "8.*",
        "drupalcommerce/commerce_base": "dev-8.x-1.x"
    },

To apply the patch only add the proper instruction in composer.json files

"extra": {
        "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        },
	    "patches": {
            "drupal/default_content": {
                "Drupal Console commands": "https://www.drupal.org/files/issues/drupal_console_commands-2758847-11.patch"
            }
    	}
    }

After save, you just need to run composer install

composer install --no-progress --prefer-dist --no-dev --optimize-autoloader
miguelc303’s picture

StatusFileSize
new16.23 KB

I did a new Drupal Console command
default:content:export:menu parent-menu --module

The command allow users to export all menu content for a specific parent menu and select the module they want to use to export the entities.

glynnr’s picture

StatusFileSize
new16.16 KB

Using this patch I get the following error:

Error: Call to undefined method Drupal\user\Entity\User::getName() in contrib/default_content/src/Command/DefaultExportCommand.php on line 80

Error: Call to undefined method Drupal\node\Entity\Node::getName() in contrib/default_content/src/Command/DefaultExportCommand.php on line 80

Perhaps it would be better to use ID? Attached patch for this.

glynnr’s picture

StatusFileSize
new2.35 KB

Also, could be quite useful to be able to export all entities of a type, which I would like to do, so here is a patch for that.

With this you can go : drupal default:content:export node all

Status: Needs review » Needs work

The last submitted patch, 15: drupal_console_commands-2758847-15.patch, failed testing.

glynnr’s picture

StatusFileSize
new16.4 KB

Sorry last patch is incorrect. This one should work.

glynnr’s picture

StatusFileSize
new16.4 KB
pguillard’s picture

Status: Needs work » Needs review

The last submitted patch, 4: drupal_console_commands-2758847-4.patch, failed testing.

andypost’s picture

ivnish’s picture

Why drupal console?

The https://www.drupal.org/project/default_content_deploy module has drush commands to export and import

marios anagnostopoulos’s picture

Status: Needs review » Closed (outdated)

I am taking the liberty to close this issue since it is outdated. Last relevant comment was 5 years ago, and the module has implemented the drush approach. Also the drupal console project seems to be on some kind of hiatus anyway.
If there are any objections with closing this feel free to reopen it.