function menu_views_update_7200 in Menu Views 7.2
Same name and namespace in other branches
- 8.3 menu_views.install \menu_views_update_7200()
Upgrades existing menu items that have attached views. This is a major update for the 7.x-2.x branch.
File
- ./
menu_views.install, line 117 - Install and update functions for the menu_views module.
Code
function menu_views_update_7200(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_mlid'] = 0;
// Only count links that possibly have a key class with a string value in
// its serialized options array.
$sandbox['max'] = db_query("SELECT COUNT(DISTINCT mlid) FROM {menu_links}")
->fetchField();
}
// Process twenty links at a time.
$limit = 20;
// Fetch links
$links = db_query_range("SELECT * FROM {menu_links} WHERE mlid > :mlid ORDER BY mlid", 0, $limit, array(
':mlid' => $sandbox['current_mlid'],
))
->fetchAll();
foreach ($links as $link) {
$options = unserialize($link->options);
if (isset($options['menu_views'])) {
$item = _menu_views_default_values();
$item['mlid'] = $link->mlid;
$item['type'] = isset($options['menu_views']['name']) && !empty($options['menu_views']['name']) && (isset($options['menu_views']['display']) && !empty($options['menu_views']['display'])) ? 'view' : 'link';
$item['original_path'] = $link->link_path != '<view>' ? $link->link_path : '';
$item['view']['name'] = isset($options['menu_views']['name']) ? $options['menu_views']['name'] : '';
$item['view']['display'] = isset($options['menu_views']['display']) ? $options['menu_views']['display'] : '';
$item['view']['arguments'] = isset($options['menu_views']['arguments']) ? $options['menu_views']['arguments'] : '';
$options['menu_views'] = $item;
db_update('menu_links')
->fields(array(
'options' => serialize($options),
))
->condition('mlid', $link->mlid)
->execute();
}
$sandbox['progress']++;
$sandbox['current_mlid'] = $link->mlid;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
// To display a message to the user when the update is completed, return it.
// If you do not want to display a completion message, simply return nothing.
return t('All menu items that have attached views have been upgraded. This is a major update for the 7.x-2.x branch.');
}