function nodehierarchy_update_6200 in Node Hierarchy 6.2
Same name and namespace in other branches
- 6.3 nodehierarchy.install \nodehierarchy_update_6200()
- 7.4 nodehierarchy.install \nodehierarchy_update_6200()
- 7.2 nodehierarchy.install \nodehierarchy_update_6200()
Update from the 5.x or 6.x-1.x branches.
File
- ./
nodehierarchy.install, line 52 - Install file for nodehierarchy module.
Code
function nodehierarchy_update_6200() {
require_once './' . drupal_get_path('module', 'nodehierarchy') . '/nodehierarchy.module';
$out = array();
$schema = nodehierarchy_schema();
db_create_table($ret, 'nodehierarchy_menu_links', $schema['nodehierarchy_menu_links']);
$result = db_query("SELECT nh.*, n.title FROM {nodehierarchy} nh LEFT JOIN {node} n ON n.nid = nh.nid ORDER BY nh.parent");
while ($node = db_fetch_object($result)) {
$plid = (int) _nodehierarchy_get_node_mlid($node->parent);
if ($menu_link = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE plid = %d AND link_path = 'node/%d'", $plid, $node->nid))) {
$menu_link = _nodehierarchy_prepare_menu_link($menu_link);
$menu_link['module'] = 'nodehierarchy';
}
else {
$menu_link = _nodehierarchy_default_menu_link($node->nid, $plid);
$menu_link['link_title'] = $node->title;
}
menu_link_save($menu_link);
_nodehierarchy_create_nodehierarchy_menu_link_reference($menu_link);
update_sql("DELETE FROM {nodehierarchy} WHERE nid = %d", $node->nid);
}
// Update the old can-be-parent can-be-child settings.
$types = node_get_types();
$can_be_children = array();
foreach ($types as $type => $info) {
if (variable_get('nh_child_' . $type, FALSE)) {
$can_be_children[$type] = $type;
}
variable_del('nh_child_' . $type);
}
foreach ($types as $type => $info) {
if (variable_get('nh_parent_' . $type, FALSE)) {
variable_set('nh_allowchild_' . $type, $can_be_children);
}
variable_del('nh_parent_' . $type);
}
// Update view handlers etc.
$view_translation = array(
'order_by' => array(
'nh_menu_links',
'weight',
),
'antecedent' => array(
'nh_ancestor',
'nid',
),
'parent' => array(
'nh_parent',
'nid',
),
'actions' => NULL,
);
if (module_exists('views')) {
$views = views_get_all_views();
foreach ($views as $view_name => $view) {
$changed = FALSE;
foreach ($view->display as $display_id => $display) {
foreach (array(
'arguments',
'filters',
'sorts',
'fields',
) as $item) {
foreach ((array) @$display->display_options[$item] as $key => $info) {
if ($info['table'] == 'nodehierarchy' && ($trans = @$view_translation[$info['id']])) {
if ($trans !== NULL) {
$info['table'] = $trans[0];
$info['id'] = $info['field'] = $trans[1];
unset($view->display[$display_id]->display_options[$item][$key]);
$view->display[$display_id]->display_options[$item][$info['id']] = $info;
}
else {
unset($view->display[$display_id]->display_options[$item][$key]);
}
$changed = TRUE;
}
}
}
}
if ($changed) {
$view
->save();
}
}
}
return $out;
}