function power_menu_update_7200 in Power Menu 7.2
Update version 6.x and 7.1 to 7.2 and migrate existing data to the new structure.
File
- ./
power_menu.install, line 77 - just containing the stuff for install and uninstall
Code
function power_menu_update_7200() {
// Add a new schema
$schema = power_menu_schema();
db_create_table('cache_power_menu', $schema['cache_power_menu']);
db_create_table('power_menu_fields', $schema['power_menu_fields']);
$settings = variable_get('power_menu_handlers_settings', array());
// Menu selection
$selected_menus = array();
$menus = variable_get('power_menu_menu', array());
foreach ($menus as $menu) {
if ($menu !== 0) {
$selected_menus[] = $menu;
}
}
variable_set('power_menu_handlers_menus', $selected_menus);
variable_del('power_menu_menu');
// Breadcrumb settings
variable_set('power_menu_handlers_breadcrumb_title', variable_get('power_menu_breadcrumb_title', FALSE));
variable_del('power_menu_breadcrumb_title');
// Set the selected navigation taxonomy
$vid = variable_get('power_menu_taxonomy_navigation', '');
$vocabulary = taxonomy_vocabulary_load($vid);
if ($vocabulary) {
$vocabulary = array(
'vid' => $vocabulary->vid,
'machine_name' => $vocabulary->machine_name,
);
variable_set('power_menu_taxonomy_vocabulary', $vocabulary);
}
variable_del('power_menu_taxonomy_navigation');
// Update taxonomy related menu_links
$result = db_select('power_menu', 'pm')
->fields('pm', array(
'mlid',
'tid',
))
->condition('pm.tid', 0, '<>')
->execute();
$terms = array();
foreach ($result as $item) {
$terms[$item->tid] = $item->mlid;
}
variable_set('power_menu_taxonomy_terms', $terms);
$settings['taxonomy']['enabled'] = count($terms) ? TRUE : FALSE;
$settings['taxonomy']['weight'] = 1;
// Update node related menu_links
$result = db_select('power_menu', 'pm')
->fields('pm', array(
'mlid',
'nodetype',
'tid',
))
->condition('pm.tid', 0, '=')
->execute();
$bundles = array();
foreach ($result as $item) {
$ml = menu_link_load($item->mlid);
$bundles['node|' . $item->nodetype] = array(
'mlid' => $ml['mlid'],
'link_path' => $ml['link_path'],
'menu_name' => $ml['menu_name'],
'router_path' => $ml['router_path'],
);
}
variable_set('power_menu_node_bundles', $bundles);
$settings['node']['enabled'] = count($bundles) ? TRUE : FALSE;
$settings['node']['weight'] = 2;
// Update path related content types
$paths = array();
foreach (variable_get('power_menu_path_content_types', array()) as $value) {
if ($value !== 0) {
$paths[] = 'node|' . $value;
}
}
variable_set('power_menu_path_bundles', $paths);
$settings['path']['enabled'] = count($paths) ? TRUE : FALSE;
$settings['path']['weight'] = 3;
variable_set('power_menu_handlers_settings', $settings);
// Remove schema 'power_menu'
db_drop_table('power_menu');
// Migrate the properties to fields
//db_drop_table('power_menu_properties');
}