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 $
| Comment | File | Size | Author |
|---|---|---|---|
| book_51.patch | 466 bytes | scor |
Comments
Comment #1
scor commentedWhat 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.
Comment #2
bwynants commentedAFAIK any type can be added to a book via the outline tab. Your fix will break this.
Comment #3
preferred name commentedBwynants, to make this clear, are you saying that scor's patch will break any node type added to a book via the outline tab?
Comment #4
bwynants commentedyep.
Comment #5
Thomas_Zahreddin commenteda 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 !=tasklistAny other suggestions?
Comment #6
scor commentedsetting the title back to unexpected update of book table in nodeapi update
Comment #7
scor commentedThis is now fixed in tasklist HEAD, a new release of tasklist module will be released soon.
http://drupal.org/node/128552