Index: modules/book/book.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/book/book.admin.inc,v retrieving revision 1.8 diff -u -p -r1.8 book.admin.inc --- modules/book/book.admin.inc 8 Jan 2008 10:35:41 -0000 1.8 +++ modules/book/book.admin.inc 5 Jul 2008 16:13:59 -0000 @@ -72,7 +72,7 @@ function book_admin_edit($form_state, $n drupal_set_title(check_plain($node->title)); $form = array(); $form['#node'] = $node; - $form['table'] = _book_admin_table($node); + _book_admin_table($node, $form); $form['save'] = array( '#type' => 'submit', '#value' => t('Save book pages'), @@ -81,6 +81,18 @@ function book_admin_edit($form_state, $n } /** + * Check that the book has not been changed while using the form. + * + * @see book_admin_edit() + */ +function book_admin_edit_validate($form, &$form_state) { + if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) { + form_set_error('', t('This book has been modified by another user, the changes could not be saved.')); + $form_state['rebuild'] = TRUE; + } +} + +/** * Handle submission of the book administrative page form. * * This function takes care to save parent menu items before their children. @@ -128,8 +140,8 @@ function book_admin_edit_submit($form, & * * @see book_admin_edit() */ -function _book_admin_table($node) { - $form = array( +function _book_admin_table($node, &$form) { + $form['table'] = array( '#theme' => 'book_admin_table', '#tree' => TRUE, ); @@ -137,9 +149,19 @@ function _book_admin_table($node) { $tree = book_menu_subtree_data($node->book); $tree = array_shift($tree); // Do not include the book item itself. if ($tree['below']) { - _book_admin_table_tree($tree['below'], $form); + $hash = sha1(serialize($tree['below'])); + // Store the hash value as a hidden form element so that we can detect + // if another user changed the book hierarchy. + $form['tree_hash'] = array( + '#type' => 'hidden', + '#default_value' => $hash, + ); + $form['tree_current_hash'] = array( + '#type' => 'value', + '#value' => $hash, + ); + _book_admin_table_tree($tree['below'], $form['table']); } - return $form; } /**