Say a module uses it's own node hierarchy (like acidfree, tasklist). They have the parent field in their own table, and implement as a result this field in the node object: $node->parent
The problem is when they use the node_save function for updating a node.
Here is the pipeline:
* node_save($node); //mymodule.module
* node_invoke_nodeapi($node, 'update'); //node.module
* book_nodeapi($node, 'update'); //book.module

Here is the detail of what happens in the book nodeapi update

    case 'update':
      if (isset($node->parent)) {
        if ($node->revision) {
          db_query("INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)", $node->nid, $node->vid, $node->parent, $node->weight);
        }
        else {
          db_query("UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d", $node->parent, $node->weight, $node->vid);
        }
      }
      break;

because the $node->parent is present in this node, this node is treated as a book page. The test should not be only if (isset($node->parent)) but if (isset($node->parent) && $node->type == 'book').
I think the modules should keep their own hierarchy in their own tables, if not, the book table should be renamed node_hierarchy. It becomes quite confusing otherwise.

The visible effect of this is that every nodes I edit appear at the bottom of the parent node such as a book. I posted an issue with more details in the tasklist project.
The patch is against the book.module file // $Id: book.module,v 1.412 2007/03/17 18:30:14 dries Exp $

CommentFileSizeAuthor
book_51.patch466 bytesscor

Comments

scor’s picture

Status: Needs review » Active

What do you think of this patch? Is there any plan to fix that, or is there a better practice you would recommend when it comes to deal with the parent node of a node.

bwynants’s picture

Status: Active » Closed (works as designed)

AFAIK any type can be added to a book via the outline tab. Your fix will break this.

preferred name’s picture

Bwynants, to make this clear, are you saying that scor's patch will break any node type added to a book via the outline tab?

bwynants’s picture

yep.

Thomas_Zahreddin’s picture

Title: unexpected update of book table in nodeapi update » Suggestion

a quick an dirty fix as scor suggests with "The test should not be only if (isset($node->parent)) but if (isset($node->parent) && $node->type == 'book')."

should be rewriten (my php - and drupal - knowledge is in the moment not enough for this task).

It should only work on every node type that is not tasklist like .. && $node->type !=tasklist

Any other suggestions?

scor’s picture

Title: Suggestion » unexpected update of book table in nodeapi update

setting the title back to unexpected update of book table in nodeapi update

scor’s picture

This is now fixed in tasklist HEAD, a new release of tasklist module will be released soon.
http://drupal.org/node/128552