// Insert each node in the old table into the temporary table.
$ret[]=update_sql("INSERT INTO {book_temp} (nid, parent, weight) SELECT b.nid, b.parent, b.weight FROM {book} b INNER JOIN {node} n on b.vid = n.vid");
$ret[]=update_sql("DROP TABLE {book}");
db_create_table($ret,'book',$schema['book']);
$_SESSION['book_update_6000_orphans']['from']=0;
$_SESSION['book_update_6000']=array();
$result=db_query("SELECT * from {book_temp} WHERE parent = 0");
// Collect all books - top-level nodes.
while($a=db_fetch_array($result)){
$_SESSION['book_update_6000'][]=$a;
}
$ret['#finished']=FALSE;
return$ret;
}
else{
// No exising nodes in the hierarchy, so drop the table and re-create it.
$ret[]=update_sql("DROP TABLE {book}");
db_create_table($ret,'book',$schema['book']);
return$ret;
}
}
elseif($_SESSION['book_update_6000_orphans']){
// Do the first batched part of the update - collect orphans.
$update_count=400;// Update this many at a time
$result=db_query_range("SELECT * FROM {book_temp}",$_SESSION['book_update_6000_orphans']['from'],$update_count);
$has_rows=FALSE;
// Go through the next $update_count book pages and locate the orphans.
while($book=db_fetch_array($result)){
$has_rows=TRUE;
// Orphans are defined as nodes whose parent does not exist in the table.
if($book['parent']&&!db_result(db_query("SELECT COUNT(*) FROM {book_temp} WHERE nid = %d",$book['parent']))){
// Insert each node in the old table into the temporary table.
$ret[]=update_sql("INSERT INTO {book_temp} (nid, parent, weight) SELECT b.nid, b.parent, b.weight FROM {book} b INNER JOIN {node} n on b.vid = n.vid");