function menu_node_update_6003 in Menu Node API 7
Same name and namespace in other branches
- 6 menu_node.install \menu_node_update_6003()
Correct for duplicate mlids with unique nids.
File
- ./
menu_node.install, line 114 - 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.
foreach ($result as $data) {
$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) {
db_delete('menu_node')
->condition('mlid', $data->mlid)
->condition('nid', $data->nid)
->execute();
}
}
return t('Erased bad records from the {menu_node} table.');
}