There are a couple of issues here.

When importing a book, if the parent begins with a number, it is assumed that it is a node reference. This is not necessarily true as I was trying to import a book where the pages are numbered as an outline like "1.1 - Legal Basis".

This can be fixed by editing the node_import.api.inc file and changing the node_import_nodereference() function to make sure it is truly a numeric string instead of just a string that starts with a number. The intval() function will return a value greater than 0 if the string starts with a number, even if the string isn't purely numeric.

Change line 183 from
if (intval($title) > 0 && ($node = node_load(intval($title)))) {
to
if (is_numeric($title) && intval($title) > 0 && ($node = node_load(intval($title)))) {
although that's not a perfect solution because someone could still have a title of just "1.1" and it would try to reference node 1.

This whole function seems funny to me (like it was copied from somewhere else but not totally changed). In several places, it refers to the variable $name, but the parameter passed to it is $title. As far as I can tell, the $name variable is undefined. I didn't want to change too much since I didn't fully understand why you were doing a "sounds like" SQL query.

The second issue is non-critical, but it is confusing and may make people think their file isn't going to import. Even after fixing the issue above, a preview complains about not being able to find the parent for any items that don't already exist in database (that is, any child of a page created during the import). However, if you go ahead and apply the changes, then it will create the book pages.

Comments

Robrecht Jacques’s picture

Status: Active » Fixed

Thanks!

I copied the code from node_import_userreference(), hence $name instead of $title.

You are right that if you import a book which has a parent that was imported previously, the preview will complain. That is because the parent node does not exist yet when doing preview (preview doesn't create anything). I see no easy way to avoid this, as I would need to keep track of all created nodes. Ok, it may be doable for book pages (storing the titles of created nodes somewhere).

Setting it as fixed. I may fix the errors during preview someday.

Robrecht Jacques’s picture

With fixed I mean, it has been commited to CVS and will be included in the next release of node_import (5.x-1.3), released later today.

Anonymous’s picture

Status: Fixed » Closed (fixed)