array( 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'parent' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'weight' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), ), 'primary key' => array('nid'), 'name' => 'book_temp', 'module' => 'book', ); db_create_table($ret, $schema['book_temp']); $_SESSION['book_update_6000']['step']++; // Only very little here, because the next step is expensive break; case 2: $current_batch = $_SESSION['book_update_6000']['move_batch'] = ($_SESSION['book_update_6000']['move_batch']? $_SESSION['book_update_6000']['move_batch'] : 0); $next_batch = $_SESSION['book_update_6000']['move_batch'] + 1; // If it hasn't gone through every node if(db_num_rows(db_query_range("SELECT nid FROM {book}", $current_batch * $batch)) != 0) { db_query_range("INSERT INTO {book_temp} (nid, parent, weight) SELECT nid, parent, weight FROM {book}", $current_batch * $batch, $next_barch * $batch); } else { $_SESSION['book_update_6000']['step']++; } $_SESSION['book_update_6000']['move_batch']++; break; case 3: $current_batch = $_SESSION['book_update_6000']['process_1_batch'] = ($_SESSION['book_update_6000']['process_1_batch']? $_SESSION['book_update_6000']['process_1_batch'] : 0); $next_batch = $_SESSION['book_update_6000']['process_1_batch'] + 1; // If it hasn't gone through every node if(db_num_rows(db_query_range("SELECT nid FROM {book}", $current_batch * $batch, $next_barch * $batch)) != 0) { $book_nodes = db_query_range("SELECT b.nid, b.weight, b.parent, n.title FROM {book_temp} b INNER JOIN {node} n ON b.nid = n.nid", $current_batch * $batch, $next_barch * $batc); while($book_node = db_fetch_object($book_nodes)) { $nodes[$book_node->nid] = $book_node; $nodes[$book_node->nid]->depth = 1; } $_SESSION['book_update_6000']['nodes'] = $nodes; } else { $_SESSION['book_update_6000']['step']++; } $_SESSION['book_update_6000']['process_1_batch']++; break; case 4: $current_batch = $_SESSION['book_update_6000']['process_2_batch'] = ($_SESSION['book_update_6000']['process_2_batch']? $_SESSION['book_update_6000']['process_2_batch'] : 0); $next_batch = $current_batch + 1; $nodes = $_SESSION['book_update_6000']['nodes']; // If it hasn't gone through every node if(count($nodes) < $current_batch * $batch) { $nodes = array_slice($nodes, $current_batch * $batch, $next_batch * $batch); foreach($nodes as $node) { $node->book_id = _book_get_top_level($node, $nodes, $flag); $node = $nodes[$node->nid]; unset($nodes[$node->nid]); if ($flag) { $nodes[$node->nid] = $node; } } $_SESSION['book_update_6000']['nodes'] = $nodes; } else { $_SESSION['book_update_6000']['step']++; } $_SESSION['book_update_6000']['process_2_batch']++; break; case 5: $current_batch = $_SESSION['book_update_6000']['process_2_batch'] = ($_SESSION['book_update_6000']['process_2_batch']? $_SESSION['book_update_6000']['process_2_batch'] : 0); $next_batch = $current_batch + 1; $nodes = $_SESSION['book_update_6000']['nodes']; // If it hasn't gone through every node if(count($node) < $current_batch * $batch) { $nodes = array_slice($nodes, $current_batch * $batch, $next_batch * $batch); foreach($nodes as $node) { $node->book_id = _book_get_top_level($node, $nodes, $flag); if (!$flag) { unset($nodes[$node->nid]); } } $_SESSION['book_update_6000']['nodes'] = $nodes; } else { $_SESSION['book_update_6000']['step']++; } $_SESSION['book_update_6000']['process_2_batch']++; break; case 6: // Update the schema $ret[] = update_sql("DROP TABLE {book}"); include_once './modules/book/book.schema'; $schema = book_schema(); _drupal_initialize_schema('book', $schema); db_create_table($ret, $schema['book']); case 7: foreach($nodes as $node) { if($node->depth == 1) { $plid = 0; } else { $mlid = db_fetch_array(db_query("SELECT mlid FROM {book} WHERE nid = %d", $node->book_id)); $plid = $mlid['mlid']; } $link = array('link_title' => $node->title, 'link_path' => 'node/'. $node->nid, 'router_path' => 'node/%', 'menu_name' => 'book-toc-'. $node->book_id, 'module' => 'book', 'plid' => $plid, ); if(menu_link_save($link)) { $ret[] = update_sql("INSERT INTO {book} (nid, mlid, book_id, child_type) VALUES (%d, %d, %d, '%s')", $node->nid, $link['mlid'], $node->book_id, 'book'); } } } return $ret; } function _book_get_top_level($node, $nodes, &$flag) { $flag = FALSE; if($node->parent == 0) { return $node->nid; } else { $node->depth++; if(in_array($node->parent, $nodes)) { return _book_get_top_level($nodes[$node->parent], $nodes); } else { $flag = TRUE; return $node->nid; } } } include_once './modules/node/node.module'; include_once './modules/node/content_types.inc'; $book_node_type = array( 'type' => 'book', 'name' => t('Book page'), 'module' => 'node', // This is cheating, but it works 'description' => t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it."), 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, ); $book_node_type = (object) _node_type_set_defaults($book_node_type); node_type_save($book_node_type);