[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/menu_block/ -> menu_block.install (source)

   1  <?php
   2  // $Id: menu_block.install,v 1.18 2010/03/22 07:12:51 johnalbin Exp $
   3  
   4  /**
   5   * @file
   6   * Provides install, upgrade and un-install functions for menu_block.
   7   */
   8  
   9  /**
  10   * Implements hook_uninstall().
  11   */
  12  function menu_block_uninstall() {
  13    // Delete menu block variables.
  14    foreach (variable_get('menu_block_ids', array()) AS $delta) {
  15      variable_del("menu_block_{$delta}_title_link");
  16      variable_del("menu_block_{$delta}_admin_title");
  17      variable_del("menu_block_{$delta}_parent");
  18      variable_del("menu_block_{$delta}_level");
  19      variable_del("menu_block_{$delta}_follow");
  20      variable_del("menu_block_{$delta}_depth");
  21      variable_del("menu_block_{$delta}_expanded");
  22      variable_del("menu_block_{$delta}_sort");
  23    }
  24    variable_del('menu_block_ids');
  25    variable_del('menu_block_menu_order');
  26    // Remove block configurations.
  27    db_query("DELETE FROM {blocks} WHERE module = 'menu_block'");
  28    db_query("DELETE FROM {blocks_roles} WHERE module = 'menu_block'");
  29    cache_clear_all();
  30  }
  31  
  32  /**
  33   * Implements hook_enable().
  34   */
  35  function menu_block_enable() {
  36    drupal_set_message(t('To use menu blocks, find the "Add menu block" tab (or button) on the <a href="@url">administer blocks page</a>.', array('@url' => url('admin/build/block'))));
  37  }
  38  
  39  /**
  40   * Implements hook_install().
  41   */
  42  function menu_block_install() {
  43    // No-op.
  44  }
  45  
  46  /**
  47   * Implements hook_update_N().
  48   *
  49   * Pre-1.0 versions used a different naming convention for block names. Convert
  50   * the old names to the new format. An unfortunate side effect of this renaming
  51   * is that it disables all the previously enabled blocks.
  52   */
  53  function menu_block_update_5100() {
  54    $delta = 0;
  55    $enabled_blocks = array();
  56  
  57    // Find the old enabled blocks.
  58    foreach (variable_get('menu_block_enabled_blocks', array()) AS $old_delta => $enabled) {
  59      list($mid, $level) = explode('-', $old_delta);
  60      if ($enabled) {
  61        $enabled_blocks[++$delta] = TRUE;
  62        variable_set("menu_block_{$delta}_mid", $mid);
  63        variable_set("menu_block_{$delta}_level", $level);
  64        variable_set("menu_block_{$delta}_depth", variable_get("menu_block_depth_{$mid}_{$level}", 0));
  65        variable_set("menu_block_{$delta}_expanded", variable_get("menu_block_expanded_{$mid}_{$level}", 0));
  66      }
  67      // Remove any of the old-style variables.
  68      variable_del("menu_block_depth_{$mid}_{$level}");
  69      variable_del("menu_block_expanded_{$mid}_{$level}");
  70    }
  71    variable_set('menu_block_enabled_blocks', $enabled_blocks);
  72  
  73    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.')));
  74  }
  75  
  76  /**
  77   * Implements hook_update_N().
  78   *
  79   * Converts $menu_block_enabled_blocks to $menu_block_ids and
  80   * $menu_block_DELTA_mid to $menu_block_DELTA_menu_name. Also deletes un-enabled
  81   * menu blocks.
  82   */
  83  function menu_block_update_5200() {
  84    $block_ids = array();
  85    foreach (variable_get('menu_block_enabled_blocks', array()) AS $delta => $enabled) {
  86      if ($enabled) {
  87        $block_ids[] = $delta; // Build new $menu_block_ids.
  88        // Convert $menu_block_DELTA_mid to $menu_block_DELTA_menu_name.
  89        $mid = variable_get("menu_block_{$delta}_mid", 1);
  90        variable_set("menu_block_{$delta}_menu_name", $mid);
  91        // If we weren't upgraded to 5.x-2.x before the Drupal 6 upgrade, the
  92        // mid-to-menu_name conversion is not possible.
  93        variable_set("menu_block_{$delta}_title", $mid == 2 ? 'primary-links' : 'navigation');
  94        variable_del("menu_block_{$delta}_mid");
  95      }
  96      else {
  97        // Delete un-enabled menu block.
  98        variable_del("menu_block_{$delta}_mid");
  99        variable_del("menu_block_{$delta}_level");
 100        variable_del("menu_block_{$delta}_depth");
 101        variable_del("menu_block_{$delta}_expanded");
 102        db_query("DELETE FROM {blocks} WHERE module = 'menu_block' AND delta = %d", $delta);
 103      }
 104    }
 105    // Finish conversion of $menu_block_enabled_blocks to $menu_block_ids.
 106    sort($block_ids);
 107    variable_set('menu_block_ids', $block_ids);
 108    variable_del('menu_block_enabled_blocks');
 109    cache_clear_all();
 110  
 111    return array(0 => array('success' => TRUE, 'query' => t('A 5.x-1.x version of Menu block has been detected and an attempt was made to upgrade it. Unfortunately, you should have upgraded to Menu block 5.x-2.x before your upgrade to Drupal 6. You may need to re-configure all your menu blocks. To use menu blocks in Drupal 6, find the "Add menu block" tab (or button) on the <a href="@url">administer blocks page</a>.', array('@url' => url('admin/build/block')))));
 112  }
 113  
 114  /**
 115   * Implements hook_update_N().
 116   *
 117   * Converts the mids to menu names using the D5-stored menu_title variable.
 118   */
 119  function menu_block_update_6200() {
 120    $menus = menu_get_menus();
 121    foreach (variable_get('menu_block_ids', array()) AS $delta) {
 122      // Drupal 6 uses the menu title to create the new menu_name.
 123      $menu_name = preg_replace('/[^a-zA-Z0-9]/', '-', strtolower(variable_get("menu_block_{$delta}_title", '')));
 124      // If we can't find the new menu_name, default to the navigation menu.
 125      if (empty($menus[$menu_name])) {
 126        $menu_name = 'navigation';
 127      }
 128      variable_set("menu_block_{$delta}_menu_name", $menu_name);
 129      variable_del("menu_block_{$delta}_title");
 130    }
 131    return array(0 => array('success' => TRUE, 'query' => t('The 5.x-2.x version of Menu block has been upgraded. To use menu blocks in Drupal 6, find the "Add menu block" tab (or button) on the <a href="@url">administer blocks page</a>.', array('@url' => url('admin/build/block')))));
 132  }
 133  
 134  /**
 135   * Implements hook_update_N().
 136   *
 137   * Converts the menu names to parent items.
 138   */
 139  function menu_block_update_6201() {
 140    $menus = menu_get_menus();
 141    foreach (variable_get('menu_block_ids', array()) AS $delta) {
 142      variable_set("menu_block_{$delta}_parent", variable_get("menu_block_{$delta}_menu_name", 'navigation') . ':0');
 143      variable_del("menu_block_{$delta}_menu_name");
 144    }
 145    return array(0 => array('success' => TRUE, 'query' => t('The 6.x-2.0 version of Menu block has been upgraded. To use menu blocks in Drupal 6, find the "Add menu block" tab (or button) on the <a href="@url">administer blocks page</a>.', array('@url' => url('admin/build/block')))));
 146  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7