-2

menu_link_save() fails; I'm manually updating "plid," "p1," and "depth."

$sql =  "UPDATE menu_links SET plid=" . $parent . ", depth=2, p1=" . $parent . ", p2=19072 WHERE mlid=" . $child->mlid ;
$query = Database::getConnection('default');
$query->query( $sql );

$sql =  "UPDATE menu_links SET has_children=1 WHERE mlid=" . $parent;
$query = Database::getConnection('default');
$query->query( $sql );
  • 2
    The question is not very clear - you did not explain what you are trying to accomplish, nor what "fail" means in this context. Did you get an SQL exception? Was the row updated but did not have the effect you expected? What version of Drupal are you using? – Dylan Tack Sep 30 '11 at 17:17
1

In general, it's not safe to manipulate individual rows of the menu_links table directly. Since it's a tree structure, changes in one row can affect other rows. You should use the API function menu_link_save.

If you have accidentally corrupted your tree, the following code should repair it (for Drupal 6):

// Recursively crawl menus and repair the tree structure.
menu_repair(0);
function menu_repair($parent) {
  $result = db_query("SELECT mlid from menu_links WHERE plid = %d", $parent);
  while ($row = db_fetch_object($result)) {
    print "repair: $row->mlid\n";
    $menu = menu_link_load($row->mlid);
    menu_link_save($menu);
    menu_repair($row->mlid);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.