You are here

function nodehierarchy_add_default_parents in Node Hierarchy 5

Same name and namespace in other branches
  1. 6 nodehierarchy.install \nodehierarchy_add_default_parents()
2 calls to nodehierarchy_add_default_parents()
nodehierarchy_install in ./nodehierarchy.install
nodehierarchy_update_1 in ./nodehierarchy.install

File

./nodehierarchy.install, line 31

Code

function nodehierarchy_add_default_parents() {
  $out = array();
  $result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {nodehierarchy} h ON n.nid = h.nid WHERE h.parent IS NULL ORDER BY n.nid");
  $order_by = 1;
  while ($node = db_fetch_object($result)) {
    if (function_exists("update_sql")) {
      $out[] = update_sql("INSERT INTO {nodehierarchy} VALUES ({$node->nid}, 0, {$order_by})");
    }
    else {
      db_query("INSERT INTO {nodehierarchy} VALUES ({$node->nid}, 0, {$order_by})");
    }
    $order_by++;
  }
  return $out;
}