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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

infojunkie’s picture

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.

infojunkie’s picture

Component: User interface » Actions
looplog’s picture

Status: Postponed » Active
FileSize
1.45 KB

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.

infojunkie’s picture

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.

pxlar8’s picture

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.

kentr’s picture

FileSize
714 bytes

@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)

  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');
  }
joetan’s picture

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"

eiland’s picture

UPDATE `menu_links` SET `module` = 'book' WHERE `menu_name` LIKE 'book-toc-%'

kentr’s picture

FileSize
750 bytes

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 from book_nodeapi().

eiland’s picture

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.

asb’s picture

Status: Needs work » Needs review

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

asb’s picture

Status: Needs review » Needs work
kentr’s picture

Status: Needs review » Needs work

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).

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.

kayceedub’s picture

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!

tallsimon’s picture

could this help with the menu side of things? http://drupal.org/project/mew

kentr’s picture

FileSize
746 bytes

Per #14, removed the closing ?>, which violated the Drupal coding standards anyway. Problem was probably the blank line after the tag.

infojunkie’s picture

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.

asb’s picture

@infojunkie: agreed!

Starminder’s picture

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!

kentr’s picture

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

    $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.
Starminder’s picture

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....

kentr’s picture

@starminder: I misunderstood. I don't know if it will work with Content Management Filter.

Starminder’s picture

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.

kenianbei’s picture

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.

kenianbei’s picture

FileSize
1.18 KB

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.

R-H’s picture

Is there a way in VBO to take a book node and make it a new book in the book hierarchy?

SocialNicheGuru’s picture

subscribe and testing

apmac’s picture

@#25 Tested on book with 540 nodes worked perfectly. Thanks very much.

infojunkie’s picture

Status: Needs work » Fixed

Thanks all for the patch and reviews. Committed to latest dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ymeiner’s picture

is there a chance to see it working on the drupal 7 version?

mzwyssig’s picture

Subscribe. I'd be very interested in this feature for D7

lolandese’s picture

Version: 6.x-1.8 » 7.x-3.0-rc1
Status: Closed (fixed) » Active
infojunkie’s picture

Version: 7.x-3.0-rc1 » 7.x-3.x-dev
Status: Active » Patch (to be ported)
kenianbei’s picture

I'd be willing to port since it wouldn't take much time...

joel_osc’s picture

FileSize
1.27 KB

Here is a first crack at a port to D7, modifications are welcome.

ikeigenwijs’s picture

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?

joel_osc’s picture

Are the new actions listed in admin/config/system/actions ? If so then you may want to try flushing caches.

The call to hook_actions_info makes actions aware of the new actions:

/**
 * Implements hook_action_info()
 */
function book_actions_action_info() {
...

I don't know if this will help but we are running VBO version:

; Information added by drupal.org packaging script on 2012-09-14
version = "7.x-3.0"

Let me know how it goes.

ikeigenwijs’s picture

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.

Imported 250 pages in a book ;-)
thx a lot

jlockhart’s picture

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.

Worked Great. No errors, no issues.

pauldawg’s picture

#36 worked like a charm! Please submit this as an official project to Drupal. This is exactly what I needed, and would love to be kept up to date on any changes or enhancements.

pauldawg’s picture

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!

bojanz’s picture

Issue summary: View changes
Status: Patch (to be ported) » Fixed

Converted #36 to a patch and committed it. Thanks!

(Small note: Had to remove the custom messages that are shown when the action is reported. We'll readd that once #1327632: Support action specific status message reporting. is ready)

wmfinck’s picture

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.

joel_osc’s picture

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.

wmfinck’s picture

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!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Gletzer’s picture

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.

sonSticks’s picture

#36 works to move items to the root books, but it would be nice if you could select book parent as well.
I have a whole hierarchy of book pages that I would like to bulk update.