| Project: | Views Bulk Operations (VBO) |
| Version: | 6.x-1.8 |
| Component: | Actions |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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
#1
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.
#2
#3
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.
#4
Thanks for your contribution omjn! It would be great if the original poster could try it. I will do so too.
#5
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.
#6
@omjn,
Thanks for the base code.
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.
(name changed for accuracy)
<?php
function views_bulk_operations_book_action_info() {
if (!module_exists('book')) return array();
return array(
'views_bulk_operations_book_movetobook_action' => array(
'type' => 'node',
'description' => t('Move to book outline'),
'configurable' => FALSE,
'behavior' => array('changes_node_property'),
));
}
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');
}
?>
#7
just to note, in the database table "menu_links", the menu entries that get added with this script are not entirely correct... the "module" column was set to "menu", when it should've been "book"
#8
UPDATE `menu_links` SET `module` = 'book' WHERE `menu_name` LIKE 'book-toc-%'#9
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.
Thanks.
Here's an untested update that sets
$node->book['module'] = 'book'.Based on
menu_link_save(), which is called frombook_nodeapi().#10
Thanks Kentr but your update doesn't work.
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.#11
Hi,
I think it is very important for VBO to fully support the core modules. Especially if it would allow to fix serious issues like those with book hierarchies (see issues linked below).
However, the action from #3 does not allow to add books to the parent level (
./book) and thus needs some work ;)mysql> SELECT * FROM book ORDER BY bid;+-------+-------+-------+
| mlid | nid | bid |
+-------+-------+-------+
| 37874 | 29877 | 797 |
| 37875 | 7285 | 797 |
| 37871 | 34847 | 34847 |
| 37870 | 34848 | 34848 |
+-------+-------+-------+
4 rows in set (0.00 sec)
BIDs 34847 and 34848 were manually added to the book structure; they do appear at
./book. NIDs 29877 and 7285 were attempted to be added to the book hierarchy through VBO but do not appear at./book. Thus we're getting broken book structures which might lead into endless nightmares (see e.g. #645214: No menu links, no books and #467770: Book structure disappears repeatedly)The code from #9 still requires to manually edit the BID and PLID which makes it a bit imperfect action.
Any help to improve this action is gratly appreciated!
Thanks & greetings, -asb
#12
#13
Just a note: remember that coding takes time, so if it's really a high priority to you, consider doing some coding or supporting the coders financially.
Sorry that I can't quickly work up a fix and do the testing for the faults in #9. Many other fires to put out right now.
#14
To get rid of the
Cannot modify header information... error, make sure there is no ?> at the end of your file.Otherwise, it works like a charm! Thank you very much Kentr!
#15
could this help with the menu side of things? http://drupal.org/project/mew
#16
Per #14, removed the closing ?>, which violated the Drupal coding standards anyway. Problem was probably the blank line after the tag.
#17
While I would love to include this action in VBO, it requires to be made into a configurable action that allows selecting the book and parent node via a form.
#18
@infojunkie: agreed!
#19
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!
#20
@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.
?>
#21
Thanks kentr. I've done this now, however, I still don't get an action I can use in Content Management Filter. I think I'm missing something else in the config, hopefully obvious....
#22
@starminder: I misunderstood. I don't know if it will work with Content Management Filter.
#23
Thanks - normally the bulk operations show up there as available. It's the same as 'Content', only it provides a bit more granularity.
I'm just thinking maybe I missed something obvious in the setup to make this work.
#24
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.
#25
I've added a more generic and stable VBO action as a contrib module. It gives 2 actions, one to move node to new book, the other to remove node from all book outlines.
#26
Is there a way in VBO to take a book node and make it a new book in the book hierarchy?
#27
subscribe and testing
#28
@#25 Tested on book with 540 nodes worked perfectly. Thanks very much.
#29
Thanks all for the patch and reviews. Committed to latest dev.
#30
Automatically closed -- issue fixed for 2 weeks with no activity.
#31
is there a chance to see it working on the drupal 7 version?
#32
Subscribe. I'd be very interested in this feature for D7