function menu_node_update_6003 in Menu Node API 6
Same name and namespace in other branches
- 7 menu_node.install \menu_node_update_6003()
Correct for duplicate mlids with unique nids.
File
- ./
menu_node.install, line 108 - Install file for Menu Node API.
Code
function menu_node_update_6003() {
$return = array();
// Find any instances where more than one nid is mapped to an mlid.
$result = db_query("SELECT mn.mlid, mn.nid, ml.link_path FROM {menu_node} mn\n LEFT JOIN (SELECT mlid, count(mlid) AS count FROM {menu_node} GROUP BY mlid) mcount ON mn.mlid = mcount.mlid\n LEFT JOIN {menu_links} ml ON mn.mlid = ml.mlid WHERE mcount.count > 1 AND ml.router_path LIKE 'node/%%'");
// Walk through every row and test them based on nid.
while ($data = db_fetch_object($result)) {
$nid = str_replace('node/', '', $data->link_path);
// Does the stored nid match the menu_link path nid?
$check = (bool) $nid == $data->nid;
// If check failed we delete the row with this combination.
if (!$check) {
$return[] = update_sql("DELETE FROM {menu_node} WHERE mlid = {$data->mlid} AND nid = {$data->nid}");
}
}
return $return;
}