array( 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'parent' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') ), 'indexes' => array( 'parent' => array('parent') ), 'primary key' => array('nid'), ); $schema['book'] = drupal_get_schema_unprocessed('book', 'book'); _drupal_initialize_schema('book', $schema); db_create_table($ret, $schema['book_temp']); $ret[] = update_sql("INSERT INTO {book_temp} bt (bt.nid, bt.parent, bt.weight) SELECT b.nid, b.parent, b.weight FROM {book} b INNER JOIN {node} on b.vid = n.vid"); $ret[] = update_sql("DROP TABLE {book}"); db_create_table($ret, $schema['book']); $_SESSION['book_update_6000'] = array(); $r = db_query("SELECT nid from {book_temp} WHERE parent = 0"); // Collect all books - top-level nodes while ($a = db_fetch_array($r)) { $_SESSION['book_update_6000'][] = $a['nid']; } $ret['#finished'] = FALSE; return $ret; } else { // no exising nodes in the hierarchy $ret[] = update_sql("DROP TABLE {book}"); $schema['book'] = drupal_get_schema_unprocessed('book', 'book'); _drupal_initialize_schema('book', $schema); db_create_table($ret, $schema['book']); return $ret; } } if (!empty($_SESSION['book_update_6000'])) { $ret['#finished'] = FALSE; } //TODO batched updates - the hard part. Pop each book's nid off the session // variable when all it's chlidren have been updated? $finished = empty($_SESSION['book_update_6000']); if ($finished) { $ret[] = update_sql("DROP TABLE {book_temp}"); unset($_SESSION['book_update_6000']); unset($_SESSION['book_update_6000_stack']); } $ret['#finished'] = $finished; return $ret; }