block.install 5.21 KB
Newer Older
1
2
<?php

3
4
/**
 * @file
5
 * Install, update and uninstall functions for the block module.
6
7
 */

8
/**
9
 * Implements hook_schema().
10
11
 */
function block_schema() {
12

13
  $schema['cache_block'] = drupal_get_schema_unprocessed('system', 'cache');
14
  $schema['cache_block']['description'] = 'Cache table for the Block module to store already built blocks, identified by module, delta, and various contexts which may change the block, such as theme, locale, and caching mode defined for the block.';
15
16

  return $schema;
17
18
}

19
/**
20
 * Implements hook_install().
21
22
 */
function block_install() {
23
24

  // Block should go first so that other modules can alter its output
25
26
  // during hook_page_alter(). Almost everything on the page is a block,
  // so before block module runs, there will not be much to alter.
27
  module_set_weight('block', -5);
28
}
29
30

/**
31
 * @addtogroup updates-7.x-to-8.x
32
33
34
 * @{
 */

35
36
37
38
39
40
41
42
/**
 * Implements hook_update_dependencies().
 */
function block_update_dependencies() {
  // Convert role IDs after User module converted {role}.
  $dependencies['block'][8002] = array(
    'user' => 8002,
  );
43
44
45
46
  // Migrate users.data after User module prepared the tables.
  $dependencies['block'][8005] = array(
    'user' => 8011,
  );
47
48
49
  return $dependencies;
}

50
51
/**
 * Block cache is always enabled in 8.x.
52
53
 *
 * @ingroup config_upgrade
54
55
 */
function block_update_8000() {
56
  update_variable_del('block_cache');
57
58
}

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * Creates table {block_language} for language visibility settings per block.
 */
function block_update_8001() {
  $schema = array(
    'description' => 'Sets up display criteria for blocks based on langcode.',
    'fields' => array(
      'module' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'description' => "The block's origin module, from {block}.module.",
      ),
      'delta' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => "The block's unique delta within module, from {block}.delta.",
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => "Language type name. Applied to filter the block by that type.",
      ),
      'langcode' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => "The machine-readable name of this language from {language}.langcode.",
      ),
    ),
    'primary key' => array('module', 'delta', 'type', 'langcode'),
  );
  db_create_table('block_language', $schema);
}

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
 * Replace serial role IDs with machine name strings.
 *
 * @see user_update_8002()
 */
function block_update_8002() {
  // Change serial rid column into string.
  $column = array(
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'description' => "The user's role ID from {users_roles}.rid.",
  );
  db_change_field('block_role', 'rid', 'rid', $column);

  // Rename the built-in serial role IDs into the hardcoded machine names.
  db_update('block_role')
    ->fields(array('rid' => DRUPAL_ANONYMOUS_RID))
    ->condition('rid', 1)
    ->execute();
  db_update('block_role')
    ->fields(array('rid' => DRUPAL_AUTHENTICATED_RID))
    ->condition('rid', 2)
    ->execute();
}

122
123
124
125
126
127
128
129
130
/**
 * Increase {block}.title length to 255 characters.
 */
function block_update_8003() {
  db_change_field('block', 'title', 'title', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
131
    'description' => 'Custom title for the block. (Empty string will use block default title, - None - will remove the title, text will cause block to use specified title.)',
132
133
134
135
136
    'translatable' => TRUE,
    )
  );
}

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
 * Rename default menu names.
 */
function block_update_8004() {
  // System menu's new block deltas are prefixed with 'menu-'.
  $map = array(
    'navigation' => 'menu-tools',
    'management' => 'menu-admin',
    'user-menu' => 'menu-account',
    'main-menu' => 'menu-main',
  );
  foreach ($map as $old => $new) {
    db_update('block')
      ->condition('module', 'system')
      ->condition('delta', $old)
      ->fields(array('delta' => $new))
      ->execute();
    db_update('block_language')
      ->condition('module', 'system')
      ->condition('delta', $old)
      ->fields(array('delta' => $new))
      ->execute();
    db_update('block_role')
      ->condition('module', 'system')
      ->condition('delta', $old)
      ->fields(array('delta' => $new))
      ->execute();
  }
}

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
 * Migrate {users}.data into {users_data}.
 */
function block_update_8005() {
  $query = db_select('_d7_users_data', 'ud');
  $query->addField('ud', 'uid');
  $query->addExpression("'block'", 'module');
  $query->addExpression("'block'", 'name');
  // Take over the extracted and serialized value in {_d7_users_data} as-is.
  $query->addField('ud', 'value');
  $query->addExpression('1', 'serialized');
  $query->condition('name', 'block');

  db_insert('users_data')
    ->from($query)
    ->execute();

  db_delete('_d7_users_data')
    ->condition('name', 'block')
    ->execute();
}

189
190
191
192
193
194
195
/**
 * Enable the Custom Block module.
 */
function block_update_8006() {
  update_module_enable(array('custom_block'));
}

196
/**
197
 * @} End of "addtogroup updates-7.x-to-8.x".
198
199
 * The next series of updates should start at 9000.
 */