You are here

function menu_badges_update_7102 in Menu Badges 7

Updates existing badges to new specification format.

File

./menu_badges.install, line 11
Install file for Menu Badges.

Code

function menu_badges_update_7102(&$sandbox = NULL) {

  // Update menu tab definitions to new format.
  $tab_badges = variable_get('menu_badges_tab_callbacks', array());
  foreach ($tab_badges as $path => $info) {
    if (is_string($info)) {
      $tab_badges[$path] = _menu_badges_7102_fix_deprecated_callback($info);
    }
  }
  variable_set('menu_badges_tab_callbacks', $tab_badges);

  // Update normal menu links to the new format.
  $results = db_select('menu_links', 'ml')
    ->fields('ml', array(
    'mlid',
    'options',
  ))
    ->condition('options', '%menu_badges%', 'LIKE')
    ->execute();
  foreach ($results as $record) {
    $item = menu_link_load($record->mlid);
    $arguments = !empty($item['options']['link_badge']['arguments']) ? $item['options']['link_badge']['arguments'] : array();
    $item['options']['link_badge'] = _menu_badges_7102_fix_deprecated_callback($item['options']['link_badge']['callback'], $arguments);
    menu_link_save($item);
  }
  cache_clear_all(NULL, 'cache_menu');
  cache_clear_all('variables', 'cache_bootstrap');
  menu_rebuild();
  return;
}