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.
Updated: Comment #N
Problem/Motivation
We want to generate book structures.
How to test
- Navigate to admin/config/development/generate/content
- Check the book settings
- Enable the Book navigation block on admin/structure/block
- Visit the frontpage and check the new books and child pages
drush (not working yet)
To see what book related options are available use
drush @drupal.d7 genc --help
Next you can try to generate book structures with
drush @drupal.d7 genc \
--types=book \
--book-depth=6 \
--book-options=create-and-add-to-books \
100 0
Proposed resolution
See patch
Remaining tasks
Should we always show the book options? Running $ drush @drupal.d7 help genc
does not show the options as we are not sure the book module is enabled. (not fully bootstrapped)
User interface changes
API changes
Related Issues
Original report by @username
With the attached patch books are generated in a hierarchical structure.
Comment | File | Size | Author |
---|---|---|---|
#36 | generate-books-303143-36-D7.patch | 7.49 KB | clemens.tolboom |
#33 | generate-books-303143-33-D7.patch | 7.37 KB | clemens.tolboom |
#32 | generate-books-303143-32-D7.patch | 7.34 KB | clemens.tolboom |
#30 | devel-generate-book-303143-28-D7.patch | 5.52 KB | clemens.tolboom |
#28 | devel-generate-book-303143-28-D7.patch | 5.52 KB | marcp |
Comments
Comment #1
clemens.tolboomThis patch is useful when testing http://drupal.org/project/export_docbook
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedoops. thats a self reference. i think you copied wrong link or posted into wrong window.
Comment #3
clemens.tolboomI edited #1 (sorry for that). Would it be wise to provide a patch for D6 and D7 too?
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedYes, that would be great. Note that book.module changed substantially in D6.
Comment #5
clemens.tolboomD6 patch is #307562: Patch: Generate bookpages with parents
Comment #6
clemens.tolboomComment #7
aclight CreditAttribution: aclight commentedSubscribing. This will probably be necessary for #143805: Auto-populate handbooks to be completed.
Comment #8
clemens.tolboomMaybe #307562: Patch: Generate bookpages with parents helps ... I haven't got time to finish that patch :=(
Comment #9
moshe weitzman CreditAttribution: moshe weitzman commentedpatches must be for d7 and then backported.
Comment #10
Dave ReidPushing to 7.x-1.x. Also marked #307562: Patch: Generate bookpages with parents as a duplicate of this issue.
Comment #11
clemens.tolboomI would prefer the other way around ... this was a D5 patch and so not a duplicate :p
Comment #12
marcp CreditAttribution: marcp commentedA D7 patch for this would be great.
I'd like to see this:
1. A checkbox on admin/config/development/generate/content - "Add nodes to existing books"
2. A checkbox on admin/config/development/generate/content - "Create new books"
And I'll supply the patch if I get a chance, but would be even happier to test out someone else's patch.
Comment #13
marcp CreditAttribution: marcp commentedHere's a patch that:
1. Adds a new file to devel_generate called book.devel_generate.inc that implements the book functionality
2. Adds radio buttons to devel_generate_content_form() to let you choose how you want to associate generated "book allowed" nodes with books
If you choose to add nodes to existing books, nodes will go in there 1 level deep. I'd like to get this patch in and then enhance that if anyone cares about getting book data further into the hierarchy.
To apply:
1. Place patch file in modules/devel/devel_generate
2. patch < devel-generate-book-303143-13.patch
The patch will create the new file for you.
Comment #15
marcp CreditAttribution: marcp commentedHere's another attempt with a patch that can be run with patch -p 0 < devel-generate-book-303143-15.patch
Comment #16
marcp CreditAttribution: marcp commentedSetting to "needs review".
Comment #17
marcp CreditAttribution: marcp commentedHere's a patch that also lets you choose "max depth" for book pages, so you can generate books of any depth (up to MENU_MAX_DEPTH, of course).
This patch supersedes the previous ones.
The only thing missing here would be some javascript to disable the max depth field when either not creating books or creating only new books.
This would be nice to get into devel so other folks could test out the core patch in #589440: Reordering fails with more than 31 book pages in a book.
Comment #18
moshe weitzman CreditAttribution: moshe weitzman commentedThat ORDER BY RAND() looks like a performance killer. We have solved similar problem in devel_generate elsewhere (comment parents?).
Seems like a good patch otherwise. Needs a code and functionality review from someone. That javascript is nice to have but not a prerequisite.
Comment #19
marcp CreditAttribution: marcp commentedYeah, I'll look into what other ways there are of doing that. I did it differently at first but found an ORDER BY RAND() somewhere in devel and thought that it made the code simpler.
Comment #20
marcp CreditAttribution: marcp commentedLooking back at the rest of the devel_generate code, ORDER BY RAND() is still around for comment parents:
and taxonomy:
I think it makes sense to commit this and then possibly open a separate issue to remove the ORDER BY RAND() calls, but since we're just generating random content, I don't think it's a big deal for this to be slow. It's really only slow, as far as I can tell from doing some reading, when the tables get really large.
Comment #21
moshe weitzman CreditAttribution: moshe weitzman commentedTables getting really big is a use case we support heartily.
See devel_generate_terms() and _taxonomy_devel_generate()
Comment #22
marcp CreditAttribution: marcp commented#836330: Generate menu and menu links has some info on this -- I'll use that as a reference.
Comment #23
marcp CreditAttribution: marcp commentedORDER BY RAND() is out; looping around mt_rand() looking for a candidate plid is in.
This strategy runs the risk of causing lots of attempts to find a good candidate plid when the menu_links table has interspersed items that don't belong to books. We first look for the min and max mlid for a book-related menu_link and then take stabs in that range in order to find a good book parent. Also, if there are lots of deep book links and you want to generate only shallow links, you'll see the same thing where it takes a lot of attempts to find a valid plid.
Still, though, it seems better than ORDER BY RAND(), and it's more D7-like.
To apply, put it in sites/all/modules/devel and run patch -p 0 < devel-generate-book-303143-23.patch
Comment #24
marcp CreditAttribution: marcp commentedThe previous patch caused an error during validation of the devel_generate_content form if the book module wasn't enabled.
To apply, put it in sites/all/modules/devel and run patch -p 0 < devel-generate-book-303143-24.patch
Comment #25
moshe weitzman CreditAttribution: moshe weitzman commentedCode looks good. Would be good to get someone to try it and assure it works. Also, would be good to get integration into drush genc commmand.
Comment #26
clemens.tolboomHmmm ... how do I apply this one
Guess my git skill are not helping yet :(
Comment #27
marcp CreditAttribution: marcp commented@clemens.tolboom - That last patch is from the good old CVS days. Here's a re-rolled one that applies with one whitespace error line. I manually re-created it and haven't tested it out yet, but you should be able to apply with:
Make sure to put the patch in sites/all/modules/devel (or wherever devel is on your site).
Comment #28
marcp CreditAttribution: marcp commentedAnd here's a patch that gets rid of the whitespace issue so it should apply cleanly with:
Comment #29
moshe weitzman CreditAttribution: moshe weitzman commentedCNW for drush integration
Comment #30
clemens.tolboomI added the options for Drush.
It works for
but fails when running
For inclusion of the options we need them from book.devel_generate.inc somehow. This has something to do with the drush bootstrap level but I don't know how to solve that.
the attached patch needs review
Powered by Dreditor (triage sandbox) and Triage transitions
Comment #31
marcp CreditAttribution: marcp commented@clemens.tolboom - I'm not seeing the drush genc options in your patch. I started working on this also but stopped when the book module didn't magically add its stuff to the newly created node in "drush genc" mode.
When you re-roll your patch with the genc options, please stick the comment number in the part of the patch name before the "-D7" - I'll test it out and see if we can work together to finish this up.
Comment #32
clemens.tolboom@marcp : thanks for the numbering remark. That triggered the 'bug'. netbeans did not allow for symlink debugging so I diff-ed the wrong git checkout :(
Comment #33
clemens.tolboomI worked around the module_exists
Replaced by
which I don't like. I file a new issue for this.
Comment #34
clemens.tolboomThis relates to #1146504: drush breaks when listing devel commands due to required bootstrap level for generate books
Powered by Dreditor (triage sandbox) and Triage transitions
Comment #35
marcp CreditAttribution: marcp commented@clemens.tolboom - Generating top level books appears to work via drush genc with:
but, adding to books isn't working:
should add 60 child book pages. Instead, it adds 60 book pages that are not associated with any book.
For books that are created via admin/config/development/generate/content here's what we see in the menu_links table:
If you generate 3 top level books with drush genc, here's what you'll see:
Note that the 'module' that owns the menu links is menu in the drush genc case, but it's book when done via the devel_generate gui. So, it looks like the book module is not inserting itself into the node creation process during drush genc.
Comment #36
clemens.tolboomI need this patch for #2139847: Book printer friendly pages has 'Add Comment' all over to test. It needed to move code somewhat around.
It works for the UI to generate 500 book pages with at least a nesting of 6 levels.
We should obviously bump this to D8 but I have no idea how to properly code for the latest D8. I missed the hook_menu changes.
Comment #37
clemens.tolboomComment #38
clemens.tolboomComment #39
clemens.tolboomIn #35 @marcp mentioned the failure to generate book trees through drush. That is still not solved.
I have no idea yet but see a plid appearing in our patch has
while book.module has no plid in it's hook_node_presave / insert / update. That still does not explain the difference between drush and using the UI :-/
Comment #40
clemens.tolboomHmmm plid is surely used in
Could that explain our drush bug?
Comment #41
willzyx CreditAttribution: willzyx commentedClosing for lack of activity. Feel free to reopen if the issue still exists