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.
When I want to generate contents for selected content types, by default, some contents are generated authored by anonymous users (not verified).
In major circumstances, we want to avoid contents generated by anonymous users(not verified).
Proposed Solution:
We can provide an option to select users so that we can choose preferred content authors for generated contents.
Comment | File | Size | Author |
---|---|---|---|
#35 | 2929385-35.interdiff-28-35.txt | 7.27 KB | jonathan1055 |
#35 | 2929385-35.exclude_anonymous.patch | 14.89 KB | jonathan1055 |
Comments
Comment #2
Himanshu5050 CreditAttribution: Himanshu5050 at Infosys for Infosys commentedComment #3
Himanshu5050 CreditAttribution: Himanshu5050 at Infosys for Infosys commentedComment #4
Momo4 CreditAttribution: Momo4 at Ibuildings commentedAdding an option to remove anonymous user from the authors.
Comment #5
Momo4 CreditAttribution: Momo4 at Ibuildings commentedI added a checkbox field in the form that checks if the anonymous user has to be in the authors of generated contents; when it is checked, the db query excludes the anonymous user from selected users.
Comment #8
rafuel92 CreditAttribution: rafuel92 as a volunteer and at Ibuildings commentedSetting it to needs review to run the tests
Comment #9
rafuel92 CreditAttribution: rafuel92 as a volunteer and at Ibuildings commentedComment #10
Momo4 CreditAttribution: Momo4 at Ibuildings commentedComment #11
rafuel92 CreditAttribution: rafuel92 as a volunteer and at Ibuildings commentedI've tested it on Drupal 8.5 and it works fine, you can see the attached screenshots as evidence, nodes are generated without "Anonymous User" as owner.
Comment #12
rafuel92 CreditAttribution: rafuel92 as a volunteer and at Ibuildings commentedComment #13
moshe weitzman CreditAttribution: moshe weitzman commentedInstead of a checkbox, how about we check if anon are permitted to post comments?
Comment #14
davidferlay CreditAttribution: davidferlay at Skilld commentedInstead of a single checkbox, would be great to have :
Comment #15
vacho CreditAttribution: vacho at Skilld commentedComment #16
vacho CreditAttribution: vacho at Skilld commentedI contribute to this solution implementing the option to select users that randomly create content. Validating that users have the privilege to create the content types selected to generate.
View the image:
TODO:
Needs to implement it for drush command
Comment #17
vacho CreditAttribution: vacho at Skilld commentedThis patch contains #16 enhancement + drush command.
Now you can run:
$ drush --kill --types=page --authors=1,0,9 devel-generate-content 10 3
specifying the users that you can set as authors.
Where 0 is user anonymous.
Comment #18
vacho CreditAttribution: vacho at Skilld commentedComment #19
davidferlay CreditAttribution: davidferlay at Skilld commented@vacho, i tested patch #17 locally :
Comment #20
davidferlay CreditAttribution: davidferlay at Skilld commentedComment #21
vacho CreditAttribution: vacho at Skilld commentedComment #22
vacho CreditAttribution: vacho at Skilld commentedHi @davidferlay Thanks for the review of this solution.
About the points:
It is because you need to select the content type that you need to generate, so the users that have roles that let create it shows.
It is strange. Maybe versions of the base software. Please provide me drupal core version where you test, drush version too.
However, I solve some new problem that I found after review again. Maybe now you don't have any error again.
BTW
The Drush command to generate content with devel now is 'generate-content':
$ drush --kill --types=article --authors=0,1 generate-content 10
Comment #23
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThis needs to be done at 8.x-3.x first. The patch applies OK. I will investigate the failing tests.
Comment #24
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI like this enhancement, lots of good work here everyone :-) I've done some testing, and the first problem as shown in the test results was:
This is caused on the initial visit to admin/config/development/generate/content because $node_types is bound to be empty. This can be fixed by getting rid of $node_types_select and removing
as this is just not needed. $node_types is ready to use like it is, we can just add array_filter() to remove the 0 values in getCreators().
With this fixed, the tests still fail because the new functionality requires a second pass at the form to select the users. This is a problem, not only for the existing tests, but also because it changes the default functionality of the generation process and adds an extra step (or blockage) to the admin/developer. It can easily be fixed by having the default as "all users" like before, but we still give the admin the new abiliy to select specific users if they want to. In drush, the default of 0,1 is a restriction of previous functionality so this should be removed and we have the default as all users. This means that the tests work and pass as before, too.
The other problem is that of enforcing the assigned user to have a valid role with authority to create the content being created. This is a nice idea, but it is beyond the scope of this particular issue. It changes the flow of operations, because there are many times when a site developer does not need roles, they just want to create 20 users, then create 100 pieces of content distributed randomly among those 20 users. To enforce the role restriction means an extra step, you have to create at leat one role. And currently that cannot be done in devel_generate, so it means doing it manuallly. It's a good improvement, but needs to be discussed separately, on its own issue.
I've added an interdiff and you will see a few other changes, some just to variable names for better code understanding. The patch #22 also had a new call to $this->develGenerateContentPreNode($values) within generateBatchContent() which should not be there.
To assist in testing this change manually you will need the one-line change to ContentDevelGenerate.php in #3076613-8: Undefined index: users in $result array (it would be good to get that fix in first, so please test that and lend your weight to getting that committed). Also be aware of #3081503: Generate content in batch ignores selected node types which can make manual testing confusing. The patch on that issue would be good to get in too.
Comment #25
moshe weitzman CreditAttribution: moshe weitzman commentedChange status based on last post.
Comment #26
piggito CreditAttribution: piggito as a volunteer and at Skilld commentedRerolled last patch
Comment #27
piggito CreditAttribution: piggito as a volunteer and at Skilld commentedAs mentioned in #24 the permissions check for users goes out of scope for current issue so I removed everything related to this. Also, I implemented some missing dependency injection and one tiny code standard issue.
Comment #28
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHi @piggito,
Thanks for re-rolling, and for removing the out-of-scope code, and adding dependency injection for user storage. This all looks quite good now.
I have made two additions:
(a) Placed the user table into a 'details' fieldset and set it to collapsed by default. If lots of users have been generated and you do not want to specify any particular ones, the long table gets means lots of scrolling down to the 'Generate' button
(b) I added the user ID into the table.
Two things I noted
(1) Is there a simple way for the user table to be sorted by clicking on the columns. This would allow easy finding of roles or user names
(2) When using in drush, if a non-existant user id is specified in the --authors parameter there is no warning message and the generated content gets assigned to the anonymous user 0. This may be OK, but wanted to state it here.
Patch and interdiff attached. [testing is currently only working at Core 8.9, see #3130041: Composer Require failure at Core 8.8 and 9.0 testing
Comment #29
KondratievaS CreditAttribution: KondratievaS at Skilld commentedTested patch from #28 using drush command like
drush devel-generate-content --bundles=basic_page --authors=3 --kill 10
and UI and result is OKComment #30
vacho CreditAttribution: vacho at Skilld commentedAfter reviewed the code is better, much more clean. and the feature works by GUI and by drush console.
I run this command and this make done:
$ drush --kill --bundles=article --authors=1 generate-content 5
Comment #31
andypostWhy list cleaned from UID0 but "all" is not?
Comment #32
andypostReturning "all" is very expensive on 500k user base
Comment #33
vacho CreditAttribution: vacho at Skilld commentedComment #34
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks @KondratievaS and @vacho for testing and reviewing.
@andypost - yes you are right. I did not consider a test or development site would have 500k users, but of course it could have. How about if the query is changed so that if no users are specified we pick a random selection with a limit of 50. Therefore, on sites with fewer than 50 users it will be all of them.
Comment #35
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI have implemented the idea in #34, limiting the user selection to 50.
Also in this patch is new test coverage for both the UI functionality and the Drush 'authors' option
Comment #36
moshe weitzman CreditAttribution: moshe weitzman commentedLGTM. Thanks.
Comment #38
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks for the review, and thank you to all who have contributed. Nice to get this in and done