When I attach a new page node to an outline (either root level or an existing one) there is no "Remove from outline" button and the node can not be removed from the outline. There is only an "Add to book outline" button.

The node cannot be moved to another parent either. The "Add to book outline" button works only the first time. It produces an error if you try to change to another parent.

user warning: Duplicate entry '4' for key 1 query: INSERT INTO enp_book (nid, vid, parent, weight) VALUES (4, 4, 0, 0) in [...]/public_html/drupal-4.7/includes/database.mysql.inc on line 120.

CommentFileSizeAuthor
#2 54565_book_outline.patch743 bytesZen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cog.rusty’s picture

I am pasting the error message again without the pre tags.

user warning: Duplicate entry '5' for key 1 query: INSERT INTO enp_book (nid, vid, parent, weight) VALUES (5, 5, 4, 0) in [...]/public_html/drupal-4.7/includes/database.mysql.inc on line 120.

Zen’s picture

Assigned: Unassigned » Zen
Status: Active » Reviewed & tested by the community
FileSize
743 bytes

One liner. This is also (surprisingly) the only place where book_load is called. Setting to RTC as a result.

Cheers
-K

Zen’s picture

To clarify:

function book_outline($nid) {
  $node = node_load($nid);
  $page = book_load($node);

  $form['parent'] = array('#type' => 'select',
    '#title' => t('Parent'),
    '#default_value' => $page->parent,
    '#options' => book_toc($node->nid),
    '#description' => t('The parent page in the book.'),
  );
  $form['weight'] = array('#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $page->weight,
    '#delta' => 15,
    '#description' => t('Pages at a given level are ordered first by weight and then by title.'),
  );
  $form['log'] = array('#type' => 'textarea',
    '#title' => t('Log message'),
    '#default_value' => $node->log,
    '#description' => t('An explanation to help other authors understand your motivations to put this post into the book.'),
  );

  $form['nid'] = array('#type' => 'value', '#value' => $nid);
  if ($page->nid) {
    $form['update'] = array('#type' => 'submit',
      '#value' => t('Update book outline'),
    );
    $form['remove'] = array('#type' => 'submit',
      '#value' => t('Remove from book outline'),
    );
  }
  else {
    $form['add'] = array('#type' => 'submit', '#value' => t('Add to book outline'));
  }

  drupal_set_title(check_plain($node->title));
  return drupal_get_form('book_outline', $form);
}

The if ($page->nid) was failing as $page is never loaded with the nid by the call to book_load (and its erroneous query).

-K

killes@www.drop.org’s picture

Version: 4.7.0-beta6 » x.y.z
Status: Reviewed & tested by the community » Fixed

applied

Zen’s picture

Status: Fixed » Closed (fixed)