Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Context
- Devel has some nice drush commands to generate content : https://www.drupal.org/docs/8/modules/devel/new-drush-commands
Current result
drush generate-content
anddrush 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 |
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.
Comment | File | Size | Author |
---|---|---|---|
#25 | drush-error.png | 170.23 KB | vacho |
#23 | 3073850-23.uniform_drush_commands.patch | 9.09 KB | jonathan1055 |
|
Comments
Comment #2
davidferlay CreditAttribution: davidferlay at Skilld commentedComment #3
davidferlay CreditAttribution: davidferlay at Skilld commentedComment #4
piggito CreditAttribution: piggito as a volunteer and at Skilld commentedComment #5
YurkinPark CreditAttribution: YurkinPark at Skilld commentedIs not it better to provide brand new command, something like
generate-bundled-entities
with options such astype
,bundle
.Comment #6
davidferlay CreditAttribution: davidferlay at Skilld commentedWould 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
Comment #7
vacho CreditAttribution: vacho at Skilld commentedUpdate task description with a more specific detail to implement at this issue.
Comment #8
vacho CreditAttribution: vacho at Skilld commentedAt 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.
Comment #9
sorlov CreditAttribution: sorlov at Skilld commentedUpdated version of patch from #8
Made *kill* option for terms generation to have same behaviour with other commands.
Comment #10
andypostI 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
Comment #11
davidferlay CreditAttribution: davidferlay at Skilld commented@andypost
+++
Comment #12
andypostComment #13
moshe weitzman CreditAttribution: moshe weitzman as a volunteer commentedPatch looks good. Needs to pass tests on 8.3.x.
Comment #14
sorlov CreditAttribution: sorlov at Skilld commentedReroll for 8.x-3.x + updating Tests
Comment #15
sorlov CreditAttribution: sorlov at Skilld commentedComment #16
davidferlay CreditAttribution: davidferlay at Skilld commentedBoth commands works fine !
Comment #17
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commented@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]
Comment #18
sorlov CreditAttribution: sorlov at Skilld commentedWe're not going to backport this patch to 2.x.
Looks like test for 8.x-2.x was added by mistake or automatically
Comment #19
davidferlay CreditAttribution: davidferlay at Skilld commentedI'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
Comment #20
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedIn validateDrushParams() in TermDevelGenerate.php, the new code is not quite right:
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.Comment #21
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHere's a patch exactly the same as #14 but with three extra lines in the test:
This patch will fail testing, and will demonstrate the error reported in #20
Comment #23
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHere is the fix to validateDrushParams for terms:
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.Patch now includes these changes, so the new lines in the test should pass.
Comment #24
vacho CreditAttribution: vacho at Skilld commentedUpdated changes made at the last patches.
Comment #25
vacho CreditAttribution: vacho at Skilld commentedThanks, @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.
Comment #26
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThat was just a good outcome of altering the code from patch #14 to work properly :-) The exception was already there before.
Comment #27
sorlov CreditAttribution: sorlov at Skilld commentedLatest patch looks OK for me.
Got proper exception when trying to generate terms for non-existing vocabulary.
Comment #29
moshe weitzman CreditAttribution: moshe weitzman as a volunteer commentedThanks jonathan1055. I appreciate your attention to detail on these issues. It makes our project better.
Comment #30
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commented@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.
Comment #31
davidferlay CreditAttribution: davidferlay at Skilld commented+++