Context

Current result

  • drush generate-content and drush generate-terms have different syntax and options although no reason for it
    • drush devel-generate-content $COUNT --types=$BUNDLE // takes multiple bundles
    • drush devel-generate-terms $BUNDLE $COUNT // **doesn't take multiple bundles**
  • Most likely other commands are different in their way too
generate-content generate-terms generate-menus generate-users generate-vocabs
Arguments:
num machine_name number_menus num num
max_comments num number_links
max_depth
max_width
Options:
--feedback --feedback --kill --kill --kill
--kill --kill --pipe --pass --pipe
--languages --languages --roles
--skip-fields --skip-fields
--translations --pipe
--types --translations

diff between drush commands syntax diff between drush commands options

Expected result

drush generate-content should be taken as base for syntax, argument, options because most likely it's the most used and most complete of generate commands. These commands should be able to takes multiples bundles as --types options

generate-content generate-terms generate-menus generate-users generate-vocabs
Arguments:
None Remove machine_name None None None
Options:
Rename --types to --bundles Add --bundles
set defaul value for --kill = FALSE
None None None

BTW update messages to more clean and readable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davidferlay created an issue. See original summary.

davidferlay’s picture

Issue summary: View changes
FileSize
63.77 KB
98.87 KB
davidferlay’s picture

Issue summary: View changes
piggito’s picture

Assigned: Unassigned » piggito
YurkinPark’s picture

Is not it better to provide brand new command, something like generate-bundled-entities with options such as type, bundle.

davidferlay’s picture

Is not it better to provide brand new command, something like generate-bundled-entities with options such as type, bundle

Would be nice for maintenance but entities looks too much different from each other so makes sense to keep separate commands imho
Current issue is that at the moment commands are just too much different, would be useful just to uniformize a bit

vacho’s picture

Issue summary: View changes

Update task description with a more specific detail to implement at this issue.

vacho’s picture

At this patch:

generate-content
Rename --types to --bundles
generate-terms
Remove machine_name and replace it functionality by --bundles

Examples to use with drush 8
drush generate-content 2 2 --bundles=page --kill=1
drush generate-terms 4 --kill=1 --bundles=countries

Examples to use with drush 9
drush devel-generate-content 10 1 --kill --bundles=basic_page
drush devel-generate-terms 50 --kill --bundles=themes,metro_stations

By GUI this patch works too.

sorlov’s picture

Updated version of patch from #8
Made *kill* option for terms generation to have same behaviour with other commands.

andypost’s picture

I think this patch is no-go because changes arguments for commands - all scripts will fail

So I see 2 ways
- target this changes to 8.x-3.x branch and normalize arguments
- keep arguments the same and backport to 8.x-2.x

davidferlay’s picture

@andypost

- target this changes to 8.x-3.x branch and normalize arguments

+++

andypost’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
moshe weitzman’s picture

Patch looks good. Needs to pass tests on 8.3.x.

sorlov’s picture

Reroll for 8.x-3.x + updating Tests

sorlov’s picture

Status: Active » Needs review
davidferlay’s picture

Status: Needs review » Reviewed & tested by the community

Both commands works fine !

Only local images are allowed.

Only local images are allowed.

jonathan1055’s picture

Title: Drush commands of devel_generate have no uniformity » Make parameters and options consistent in Drush devel_generate commands
Status: Reviewed & tested by the community » Needs work

@davidferlay those images are a bit small to read. When you add an image can you still allow us to get the link to the actual image, then we can zoom to see :-)

The tests now pass (good) but we need to answer the questions in #10 and #11. If this change it not going to be back-ported to 8.x-2.x branch then the updated tests must also not be back-ported. Is this OK?


[edit: sorry did not mean to change the status]
sorlov’s picture

We're not going to backport this patch to 2.x.

Looks like test for 8.x-2.x was added by mistake or automatically

davidferlay’s picture

Title: Make parameters and options consistent in Drush devel_generate commands » Uniformize Drush commands of devel_generate
Status: Needs work » Reviewed & tested by the community

When you add an image can you still allow us to get the link to the actual image, then we can zoom to see :-)

I'm actually used image embed button provided by this chrome extension to embed images. I'll be careful not to next time) btw you can still right click "Open image in new tab" to see full size

jonathan1055’s picture

Status: Reviewed & tested by the community » Needs work

In validateDrushParams() in TermDevelGenerate.php, the new code is not quite right:

  foreach ($bundles As $bundle) {
    // Try to convert machine name to a vocabulary id.
    if (!$vids[] = $this->vocabularyStorage->load($bundle)->id()) {
      throw new \Exception(dt('Invalid vocabulary name: @name', array('@name' => $vocabulary_name)));

If an invalid $bundle is given then $this->vocabularyStorage->load($bundle)->id() fails badly with "Error: Call to a member function id() on null". In fact, this code, which was copied from later in the function, does not need to get the vocabulary id, because each $bundle is the id/machine name. I have a working versoin of this, but I will also write test coverage because we want to detect and avoid errors like this in future.

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
9.11 KB

Here's a patch exactly the same as #14 but with three extra lines in the test:

// Check that invalid vocabulary machine name throws the correct exception.
$this->setExpectedException('\exception', 'Invalid vocabulary');
$this->drush('devel-generate-terms', [1],
    ['bundles' => $this->randomMachineName(20)]);

This patch will fail testing, and will demonstrate the error reported in #20

Status: Needs review » Needs work

The last submitted patch, 21: 3073850-21.uniform_drush_commands.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
9.09 KB

Here is the fix to validateDrushParams for terms:

     foreach ($bundles As $bundle) {
-      // Try to convert machine name to a vocabulary id.
-      if (!$vids[] = $this->vocabularyStorage->load($bundle)->id()) {
-        throw new \Exception(dt('Invalid vocabulary name: @name', array('@name' => $vocabulary_name)));
+      // Verify that each bundle is a valid vocabulary id.
+      if (!$this->vocabularyStorage->load($bundle)) {
+        throw new \Exception(dt('Invalid vocabulary machine name: @name', array('@name' => $bundle)));
       }
     }
 
@@ -259,7 +259,7 @@ class TermDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu
       'num' => $number,
       'kill' => $this->isDrush8() ? drush_get_option('kill') : $options['kill'],
       'title_length' => 12,
-      'vids' => $vids,
+      'vids' => $bundles,
     ];
 

Also in develGenerateCommands.php, function content line 157 we do not need to include the default value in the doc comment as this is added automatically when you call the command with --help, as you can see in the first image on #16.

-   * @option bundles A comma delimited list of content types to create. Defaults to page,article.
+   * @option bundles A comma-delimited list of content types to create.

Patch now includes these changes, so the new lines in the test should pass.

vacho’s picture

Issue summary: View changes

Updated changes made at the last patches.

vacho’s picture

FileSize
170.23 KB

Thanks, @jhonatan1055 your changes work fine and solve the problem with exceptions. BTW you made a enhance messages.

Now, this is the error message when a User introduces some bad machine name for a bundle.

Error message

jonathan1055’s picture

BTW you made a enhance messages.

That was just a good outcome of altering the code from patch #14 to work properly :-) The exception was already there before.

sorlov’s picture

Status: Needs review » Reviewed & tested by the community

Latest patch looks OK for me.
Got proper exception when trying to generate terms for non-existing vocabulary.

moshe weitzman’s picture

Status: Reviewed & tested by the community » Fixed

Thanks jonathan1055. I appreciate your attention to detail on these issues. It makes our project better.

jonathan1055’s picture

Assigned: piggito » Unassigned

@moshe weitzman, you're welcome. Devel and Devel Generate are great modules and I'm happy to be able to help. Plenty of credit also goes to Vacho and Sorlov for their patches, I just came in at the end and sorted it out a few things.

davidferlay’s picture

+++

Status: Fixed » Closed (fixed)

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