bulk add to book

mhhelle - September 16, 2009 - 01:28
Project:Views Bulk Operations (VBO)
Version:6.x-1.8
Component:Actions
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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?

#1

kratib - October 3, 2009 - 20:10
Status:active» postponed

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

kratib - October 3, 2009 - 20:15
Component:User interface» Actions

#3

omjn - October 7, 2009 - 15:17
Status:postponed» active

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.

AttachmentSize
book.action.inc_.txt 1.45 KB

#4

kratib - October 7, 2009 - 15:53
Status:active» needs review

Thanks for your contribution omjn! It would be great if the original poster could try it. I will do so too.

#5

pxlar8 - November 3, 2009 - 23:25

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

kentr - November 18, 2009 - 14:30

@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');
  }
?>

AttachmentSize
book.action.inc_.txt 714 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.