Projet

Général

Profil

Paste
Télécharger (3,21 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / taxonomy_menu / taxonomy_menu.install @ 6d8023f2

1
<?php
2

    
3
/**
4
 * @file
5
 * Install and uninstall all required databases. Also do incremental database updates.
6
 */
7

    
8
/**
9
 * Implements hook_uninstall().
10
 */
11
function taxonomy_menu_uninstall() {
12
  // Remove menu items.
13
  db_delete('menu_links')->condition('module', 'taxonomy_menu', '=')->execute();
14

    
15
  // Rebuild the menus.
16
  variable_set('menu_rebuild_needed', TRUE);
17

    
18
  // Gets array of more specific variables set by Taxonomy Menu module.
19
  // This prevents known issue https://www.drupal.org/node/1966684
20
  // where uninstalling Taxonomy Menu will delete variables related
21
  // to the Taxonomy Menu Block module.
22
  $variable_suffixes = array(
23
    'vocab_menu',
24
    'vocab_parent',
25
    'voc_item',
26
    'display_num',
27
    'hide_empty_terms',
28
    'expanded',
29
    'rebuild',
30
    'path',
31
    'menu_end_all',
32
    'display_descendants',
33
    'voc_name',
34
    'sync',
35
    'end_all',
36
    'flat',
37
    'max_depth',
38
    'term_item_description',
39
  );
40

    
41
  // Delete variables.
42
  $query = db_select('variable', 'v')
43
           ->fields('v', array('name', 'value'))
44
           ->condition('name', '%' . db_like('taxonomy_menu') . '%', 'LIKE')
45
           ->execute();
46
  $variables = $query->fetchAll();
47
  foreach ($variables as $variable) {
48
    // Add check to make sure we only delete variables for Taxonomy Menu,
49
    // not variables for Taxonomy Menu Block.
50
    foreach ($variable_suffixes as $suffix) {
51
      $taxonomy_menu_variable_name = 'taxonomy_menu_' . $suffix;
52
      if (strpos($variable->name, $taxonomy_menu_variable_name) !== FALSE) {
53
        variable_del($variable->name);
54
      }
55
    }
56
  }
57
}
58

    
59
/**
60
 * Implements hook_schema().
61
 */
62
function taxonomy_menu_schema() {
63
  $schema['taxonomy_menu'] = array(
64
    'description' => 'Links a taxonomy term to a menu item.',
65
    'fields' => array(
66
      'mlid' => array(
67
        'type' => 'int',
68
        'unsigned' => TRUE,
69
        'not null' => TRUE,
70
        'default' => 0,
71
        'description' => 'The taxonomy terms {menu_link}.mlid.',
72
      ),
73
      'tid' => array(
74
        'type' => 'int',
75
        'unsigned' => TRUE,
76
        'not null' => TRUE,
77
        'default' => 0,
78
        'description' => 'Tid that is linked to the mlid.',
79
      ),
80
      'vid' => array(
81
        'type' => 'int',
82
        'unsigned' => TRUE,
83
        'not null' => TRUE,
84
        'default' => 0,
85
        'description' => 'Vid for the tid.',
86
      ),
87
    ),
88
    'primary key' => array('mlid', 'tid'),
89
    'indexes' => array(
90
      'vid' => array('vid'),
91
    ),
92
  );
93

    
94
  return $schema;
95
}
96

    
97
/**
98
 * Convert vocabulary ids into vocabulary machine names.
99
 */
100
function taxonomy_menu_update_7000() {
101
  $variable_prefixes = array(
102
    'vocab_menu',
103
    'vocab_parent',
104
    'voc_item',
105
    'display_num',
106
    'hide_empty_terms',
107
    'expanded',
108
    'rebuild',
109
    'path',
110
    'menu_end_all',
111
    'display_descendants',
112
    'voc_name',
113
    'sync',
114
  );
115

    
116
  $vocabularies = taxonomy_get_vocabularies();
117
  foreach ($vocabularies as $vocabulary) {
118
    foreach ($variable_prefixes as $prefix) {
119
      $old_name = 'taxonomy_menu_' . $prefix . '_' . $vocabulary->vid;
120
      $new_name = 'taxonomy_menu_' . $prefix . '_' . $vocabulary->machine_name;
121
      if (($value = variable_get($old_name)) !== NULL) {
122
        variable_set($new_name, $value);
123
        variable_del($old_name);
124
      }
125
    }
126
  }
127
}