Jump to:

I have a large number of books with images that I'm scanning and using image_import to import them in bulk. image_import doesn't support adding to a book as I import these images, and I am thinking that I might be able to do them after the fact using VBO instead. Each book has about 100 pages and I'm fine with going in and manually setting up the initial page in the book. This is not a feature I need to expose to my users so I'm fine with a one-off for now.

I don't see an option for this as a built in feature for VBO so I'd like to request it. In the meantime, I'm guessing I could use the option to execute some PHP code for each node instead. Can someone give me some pointers on how I can figure out what to do to try that?

Comments

I don't usually work on feature requests for actions because there's an infinite number of actions that can be needed. I'll keep this as postponed until someone picks it up or I need to implement it myself.

I've attached book.action.inc which I used myself to achieve more or less the above poster's needs. It's ugly as sin, using direct database inserts and ignoring any logic the book module might contain for checking existing parents. But it works on nodes that have no existing book structure. You'll have to edit the file manually to add the mlid and the nid of the parent book. Hopefully the comments I've added should help with that if you don't know already how to do it.

I'm hesitant to put this up since I don't what hell it might cause to your database if you try to reparent a node that is already in a book. That being said it helped me out so here goes. To avoid problems I suggest you add the book depth field to your view, and only run this action on nodes with a depth value of 0. If you have a number a books to which you wish to add nodes and wish to save time, you can duplicate the action in both the info and action function with minimal changes.

To use, just rename as book.action.inc and place it in your vbo folder. If you get stuck, let me know. And as always, back up the database in case you do something wrong.

This works great for me. Thanks for posting it--you saved me several hours of the tedium of manually adding hundreds of nodes to a book.

Since I couldn't get the Book Depth attribute of 0 to show any results, I created an imperfect workaround of adding a Book Depth column to my view so that I could at least visually see which nodes had already been assigned to a book.

Looks like you can get by with just this, which calls the API and hopefully avoids side-effects. I think it also avoids multiple entries if you process the same node twice, lets you move nodes from one book to another, etc due to the 'update' action.

function views_bulk_operations_book_movetobook_action($node) {$node->book['bid'] = 297; // set this to the nid of the book parent.$node->book['plid'] = 5269; //set this to the mlid of the book parent. you can find this by looking in the "add child to book" link rendered on the parent page.book_nodeapi($node, 'update'); }?>

Update: Due to menu issues reported in comments above, consider other solutions. Or build on this to solve the menu entry problems mentioned below. AFAIK, the first solution doesn't have the menu problems, but also doesn't fire any hooks when creating nodes.

syslog: Cannot modify header information - headers already sent by (output started at /home/www/sites/all/modules/views_bulk_operations/book.action.inc:21) in /home/www/includes/common.inc on line 345.

subscribe - is there any way to use #16 in its current form? I've added it to the folder and "see it" under actions but I'm not putting 2+2 together to be able to use it, such as in content management filter so I can bulk add content to books. Thanks!

@starminder: Edit the numbers in these two lines as noted in the comments:

<?php $node->book['bid'] = 285; // set this to the nid of the book parent.$node->book['plid'] = 3033; //set this to the mlid of the book parent. you can find this by looking in the "add child to book" link rendered on the parent page.?>

Hello all, I've taken the above code and made it into a configurable action. Unfortunately I'm not a pro PHP programmer, so please use with caution and please if you have time could you check my code for problems. I also have a version that works with OG.

You'll need to add to a custom module and change the parent book type that it will check. Sorry it's not more general, but I don't have time to change it around.

** I've removed the code since it was slightly defunct. I have a better version which I will be putting up soon.

Hey
I tried the port to Drupal 7 . I'm using dev version of VBO.
But I do not see a new action appearing.
I do have change value but book is not listed
Just to let you know.
How is vbo made aware of the new book function?

thx for the fast response
I had a number of problems i think.
Here is what i did:

I did not have enable Actions permissions (VBO)
I have a tabbed module page, did not see it at first.

in .info
You can mark Actions permissions (VBO) as required
and Views Bulk Operations if they are required of course

In admin/config/system/actions i found the book actions
in advanced actions i can select move to book.
If this is the intended location for starting the configuration a pointer in that direction would be nice. I would never have found that.

For making use of the action i had to change the content2 view witch comes standard with vbo to make the new actions visible.

Just wanted to say a big thanks. I installed the module from #36, flushed the cache, and added that action to my VBO.
Using: Views 7.x-3.7, Views Bulk Operations (VBO) 7.x-3.1

Worked flawlessly. Our use case was a client who was building a Celtic Knowledge 'book' in a WordPress blog. Needed to import over 530 posts to the Book content, unfortunately couldn't assign the parent at that time, but a little Views work, and the module above let me add all those book pages to a parent.

FYI the use case for this was syndicating content from another Wiki system, via Feeds module, and the content was arranged as a hierarchical book in the source system as well. Feeds will bring in the pages but not the book hierarchy, in the RSS, so this allows me to keep the hierarchy the same in both systems without too much effort. Thanks again!

I am missing something. I have all of the required modules. I enabled the Book Operations module (# 36 above), I added the action. I cleared all the caches several times. The action will not show up in the drop-down lists on the Triggers page (under When content is viewed by an authenticated user). I am using Views admin pages. Suggestions are appreciated!

I have 2000 book pages to assign.

Edit: I should add that I am the only site user, so permissions should not be an issue.

I don't know if I would be using the triggers page. Assuming the administration views module has been activated, I would make the action available to your admin/content page (admin/structure/views/view/admin_views_node/edit). Then, if you can come up with a filter that will show only nodes that you would like to move you can select all of your nodes at once and run the move to book action in bulk.

joel_osc thank you very much! I am familiar with Views but I was a VBO virgin until activating the module for the first time yesterday when I saw this thread. Now that I see how much more powerful some of its features are, I should have checked it out long ago. I followed your directions, and it worked wonderfully. This script is going to save me a lot of work migrating some D6 sites into D7.

I added five hundred pages to a dozen different books over my morning coffee. Thanks again!

We are using Drupal 7, and have been trying to implement the book action but when we activate the action in views it does not appear in dropdown as an operation. Any ideas what the problem could be? Any help would be greatly appreciated.