Somewhere in the process of upgrading from 4.7.3 to 4.7.4 I munged my book table. Now the book module refuses to update this table. If I update it manually, I can see the hierarchy, but if I edit a book page and instruct the system to make this book page a child of any other given book page, it does not work. Not only is it not made a child of that book page, but nothing whatsoever is inserted into the book table.

Why is book refusing to update its table? If I manually edit it, the data is used correctly (to create navigation links at the bottom of the page.)

CommentFileSizeAuthor
#6 book_botched_submit445 byteschx
#4 botched_variables.patch495 byteschx

Comments

hyperlogos’s picture

*taptap* is this thing on?

Here's the code that looks like it's not doing what it's supposed to:

/**
 * Implementation of hook_update().
 */
function book_update($node) {
  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);
  }
}

If $node->revision? I don't even know what this means. The only page I could find with a reference on the node object says "Revision number?" Not exactly inspiring. Drupal needs some, like, useful documentation someday.

But what makes me think of this is where I look further down:

/**
 * Implementation of hook_submit().
 */
function book_submit(&$node) {
  global $user;
  // Set default values for non-administrators.
  if (!user_access('administer nodes')) {
    $node->weight = 0;
    $node->revision = 1;
    $book->uid = $user->uid;
    $book->name = $user->uid ? $user->name : '';
  }
}

So like, if you don't have the access right to administer nodes, then you get these values set for you. That seems very odd. Where are they set if you DO? Why would we want to specify a weight only for non-admins? This makes no sense to me :( I guess this is why comments are important.

I would try creating a new user like that but it doesn't seem to want to let me right now, off to go file another bug report.

hyperlogos’s picture

I went in and commented out lines 119, 120, and a closing brace } just a bit lower to enable the outline tab for books. It turns out that if I outline the books, they can be properly added to the book hierarchy. The only problem of course is that pathauto will not generate me a new path if I add them to the book in this fashion. If I then go in and edit the book page and save it, a new path is generated as appropriate.

At this point I guess the plan is to outline all of the book pages manually, then delete the aliases for all nodes whose type is book page, and finally use pathauto's settings to force alias creation. What a PITA.

I still want to know wtf $node->revision does...

pwolanin’s picture

In book_submit, most of the code you cite is actually non-working. The variable $book does not exist (doh!).

The assignment of $node->revision = 1 forces the submission to be a new revision regardless of the workflow settings ( all of this is probably a bad remnant that should be removed). If $node->revision is TRUE, the node is saved as an new entry in the database with a new revision ID ($node->vid). Weight is probably set to zero as non-NULL a default- only admins can set the book weight (for some reason) on the node edit form.

chx’s picture

Version: 4.7.4 » 5.x-dev
Status: Active » Reviewed & tested by the community
StatusFileSize
new495 bytes

Needs a backport, too.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

I'd rather see these lines deleted than corrected- is it really the desired behavior to change the authorship of the node to whoever edited it last?

Also, I don't think there is any effect from setting $node->name

chx’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new445 bytes

Changing behaviour is a feature requet and a separate issue. I am fixing a bug.

I read node_submit and found that the $node->name to $node->uid translation indee dhapppens before hook_submit is called. Therefore that line is pointless now. Rerolled.

pwolanin’s picture

ok, +1 for RTBC

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

killes@www.drop.org’s picture

backported

Anonymous’s picture

Status: Fixed » Closed (fixed)