block_class.install
4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* @file
* Install, update and uninstall functions for the block_class module.
*/
/**
* Implements hook_install().
*/
function block_class_install() {
$schema['block'] = array();
block_class_schema_alter($schema);
foreach ($schema['block']['fields'] as $field => $spec) {
if (db_field_exists('block', $field)) {
watchdog('system', 'Module install: Attempt to recreate field: "%field", when it already exists.', array('%field' => $field), WATCHDOG_WARNING);
}
else {
db_add_field('block', $field, $spec);
}
}
}
/**
* Implements hook_uninstall().
*/
function block_class_uninstall() {
$schema['block'] = array();
block_class_schema_alter($schema);
foreach ($schema['block']['fields'] as $field => $specs) {
db_drop_field('block', $field);
}
}
/**
* Implements hook_schema_alter().
*
* Other modules, such as i18n_block also modify the block database table.
*/
function block_class_schema_alter(&$schema) {
if (isset($schema['block'])) {
$schema['block']['fields']['css_class'] = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'String containing the classes for the block.',
);
}
}
/**
* Alters the structure of {block_class} schema.
*/
function block_class_update_7100() {
// Check if the block_class table exists to prevent installation profiles
// from running this update for versions without the block_class table.
if (db_table_exists('block_class')) {
// Update the schema.
db_drop_primary_key('block_class');
db_change_field('block_class', 'module', 'module',
array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'The module to which the block belongs.',
)
);
db_change_field('block_class', 'delta', 'delta',
array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => "The ID of the module's block.",
)
);
db_change_field('block_class', 'css_class', 'css_class',
array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'String containing the classes for the block.',
)
);
// Restore the primary key.
db_add_primary_key('block_class', array('module', 'delta'));
}
}
/**
* Fix too long primary key length in {block_class}.
*/
function block_class_update_7101() {
// Ensure the block_class table exists, which is not true for all versions.
if (db_table_exists('block_class')) {
// Drop current primary key.
db_drop_primary_key('block_class');
db_change_field('block_class', 'module', 'module', array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'The module to which the block belongs.',
));
db_change_field('block_class', 'delta', 'delta', array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => "The ID of the module's block.",
));
// Create new primary key.
db_add_primary_key('block_class', array('module', 'delta'));
}
}
/**
* Migration from block_class table to new field css_class in core block table.
*/
function block_class_update_7103() {
if (!db_field_exists('block', 'block_class')) {
$schema['block'] = array();
block_class_schema_alter($schema);
foreach ($schema['block']['fields'] as $field => $specs) {
db_add_field('block', $field, $specs);
}
}
if (db_table_exists('block_class')) {
// Migrate all existing records from block_class table to block table.
$result = db_query('SELECT css_class, module, delta FROM {block_class}');
while ($record = $result->fetchObject()) {
db_update('block')
->fields(array('css_class' => $record->css_class))
->condition('module', $record->module)
->condition('delta', $record->delta)
->execute();
}
// Remove the block_class table.
db_drop_table('block_class');
}
}