You are here

function menu_block_update_5100 in Menu Block 5.2

Same name and namespace in other branches
  1. 5 menu_block.install \menu_block_update_5100()
  2. 6.2 menu_block.install \menu_block_update_5100()
  3. 7.3 menu_block.install \menu_block_update_5100()
  4. 7.2 menu_block.install \menu_block_update_5100()

Implements hook_update_N().

Pre-1.0 versions used a different naming convention for block names. Convert the old names to the new format. An unfortunate side effect of this renaming is that it disables all the previously enabled blocks.

File

./menu_block.install, line 48
Provides install, upgrade and un-install functions for menu_block.

Code

function menu_block_update_5100() {
  $delta = 0;
  $enabled_blocks = array();

  // Find the old enabled blocks.
  foreach (variable_get('menu_block_enabled_blocks', array()) as $old_delta => $enabled) {
    list($mid, $level) = explode('-', $old_delta);
    if ($enabled) {
      $enabled_blocks[++$delta] = TRUE;
      variable_set("menu_block_{$delta}_mid", $mid);
      variable_set("menu_block_{$delta}_level", $level);
      variable_set("menu_block_{$delta}_depth", variable_get("menu_block_depth_{$mid}_{$level}", 0));
      variable_set("menu_block_{$delta}_expanded", variable_get("menu_block_expanded_{$mid}_{$level}", 0));
    }

    // Remove any of the old-style variables.
    variable_del("menu_block_depth_{$mid}_{$level}");
    variable_del("menu_block_expanded_{$mid}_{$level}");
  }
  variable_set('menu_block_enabled_blocks', $enabled_blocks);
  return array(
    0 => array(
      'success' => TRUE,
      'query' => t('A pre-release version of Menu block has been detected. All menu blocks from the pre-release version have been given a new delta and are no longer placed in any block regions; their block placement should be re-configured immediately.'),
    ),
  );
}