/[drupal]/contributions/modules/menu_block/menu_block.install
ViewVC logotype

Contents of /contributions/modules/menu_block/menu_block.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (show annotations) (download) (as text)
Mon Dec 1 09:56:56 2008 UTC (11 months, 4 weeks ago) by johnalbin
Branch: MAIN
CVS Tags: DRUPAL-6--2-1, DRUPAL-6--2-2, HEAD
Changes since 1.14: +2 -1 lines
File MIME type: text/x-php
#300086: Add option to make starting level follow active menu item.
1 <?php
2 // $Id: menu_block.install,v 1.14 2008/12/01 02:39:10 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}_parent");
16 variable_del("menu_block_{$delta}_level");
17 variable_del("menu_block_{$delta}_follow");
18 variable_del("menu_block_{$delta}_depth");
19 variable_del("menu_block_{$delta}_expanded");
20 variable_del("menu_block_{$delta}_sort");
21 }
22 variable_del('menu_block_ids');
23 // Remove block configurations.
24 db_query("DELETE FROM {blocks} WHERE module = 'menu_block'");
25 db_query("DELETE FROM {blocks_roles} WHERE module = 'menu_block'");
26 cache_clear_all();
27 }
28
29 /**
30 * Implements hook_enable().
31 */
32 function menu_block_enable() {
33 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'))));
34 }
35
36 /**
37 * Implements hook_install().
38 */
39 function menu_block_install() {
40 // No-op.
41 }
42
43 /**
44 * Implements hook_update_N().
45 *
46 * Pre-1.0 versions used a different naming convention for block names. Convert
47 * the old names to the new format. An unfortunate side effect of this renaming
48 * is that it disables all the previously enabled blocks.
49 */
50 function menu_block_update_5100() {
51 $delta = 0;
52 $enabled_blocks = array();
53
54 // Find the old enabled blocks.
55 foreach (variable_get('menu_block_enabled_blocks', array()) AS $old_delta => $enabled) {
56 list($mid, $level) = explode('-', $old_delta);
57 if ($enabled) {
58 $enabled_blocks[++$delta] = TRUE;
59 variable_set("menu_block_{$delta}_mid", $mid);
60 variable_set("menu_block_{$delta}_level", $level);
61 variable_set("menu_block_{$delta}_depth", variable_get("menu_block_depth_{$mid}_{$level}", 0));
62 variable_set("menu_block_{$delta}_expanded", variable_get("menu_block_expanded_{$mid}_{$level}", 0));
63 }
64 // Remove any of the old-style variables.
65 variable_del("menu_block_depth_{$mid}_{$level}");
66 variable_del("menu_block_expanded_{$mid}_{$level}");
67 }
68 variable_set('menu_block_enabled_blocks', $enabled_blocks);
69
70 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.')));
71 }
72
73 /**
74 * Implements hook_update_N().
75 *
76 * Converts $menu_block_enabled_blocks to $menu_block_ids and
77 * $menu_block_DELTA_mid to $menu_block_DELTA_menu_name. Also deletes un-enabled
78 * menu blocks.
79 */
80 function menu_block_update_5200() {
81 $block_ids = array();
82 foreach (variable_get('menu_block_enabled_blocks', array()) AS $delta => $enabled) {
83 if ($enabled) {
84 $block_ids[] = $delta; // Build new $menu_block_ids.
85 // Convert $menu_block_DELTA_mid to $menu_block_DELTA_menu_name.
86 $mid = variable_get("menu_block_{$delta}_mid", 1);
87 variable_set("menu_block_{$delta}_menu_name", $mid);
88 // If we weren't upgraded to 5.x-2.x before the Drupal 6 upgrade, the
89 // mid-to-menu_name conversion is not possible.
90 variable_set("menu_block_{$delta}_title", $mid == 2 ? 'primary-links' : 'navigation');
91 variable_del("menu_block_{$delta}_mid");
92 }
93 else {
94 // Delete un-enabled menu block.
95 variable_del("menu_block_{$delta}_mid");
96 variable_del("menu_block_{$delta}_level");
97 variable_del("menu_block_{$delta}_depth");
98 variable_del("menu_block_{$delta}_expanded");
99 db_query("DELETE FROM {blocks} WHERE module = 'menu_block' AND delta = %d", $delta);
100 }
101 }
102 // Finish conversion of $menu_block_enabled_blocks to $menu_block_ids.
103 sort($block_ids);
104 variable_set('menu_block_ids', $block_ids);
105 variable_del('menu_block_enabled_blocks');
106 cache_clear_all();
107
108 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')))));
109 }
110
111 /**
112 * Implements hook_update_N().
113 *
114 * Converts the mids to menu names using the D5-stored menu_title variable.
115 */
116 function menu_block_update_6200() {
117 $menus = menu_get_menus();
118 foreach (variable_get('menu_block_ids', array()) AS $delta) {
119 // Drupal 6 uses the menu title to create the new menu_name.
120 $menu_name = preg_replace('/[^a-zA-Z0-9]/', '-', strtolower(variable_get("menu_block_{$delta}_title", '')));
121 // If we can't find the new menu_name, default to the navigation menu.
122 if (empty($menus[$menu_name])) {
123 $menu_name = 'navigation';
124 }
125 variable_set("menu_block_{$delta}_menu_name", $menu_name);
126 variable_del("menu_block_{$delta}_title");
127 }
128 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')))));
129 }
130
131 /**
132 * Implements hook_update_N().
133 *
134 * Converts the menu names to parent items.
135 */
136 function menu_block_update_6201() {
137 $menus = menu_get_menus();
138 foreach (variable_get('menu_block_ids', array()) AS $delta) {
139 variable_set("menu_block_{$delta}_parent", variable_get("menu_block_{$delta}_menu_name", 'navigation') . ':0');
140 variable_del("menu_block_{$delta}_menu_name");
141 }
142 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')))));
143 }

  ViewVC Help
Powered by ViewVC 1.1.2