-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroom_reservations.install
234 lines (217 loc) · 8.23 KB
/
room_reservations.install
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
* Implements hook_schema().
*
* Required Nodes (TODO use Entities:
* - room category (possibly should be a taxonomy)
* - room
* - reservation
*
*/
function room_reservations_schema() {
$schema['room_reservations_variables'] = array(
'description' => '',
'fields' => array(
'id' => array(
'description' => '',
'type' => 'serial',
'not null' => TRUE,
),
'name' => array(
'description' => '',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
),
'value' => array(
'description' => '',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
),
),
'primary key' => array('id'),
'indexes' => array(
'name' => array('name'),
),
);
return $schema;
}
/**
* The information that the module should remove includes:
*
* variables that the module has set using variable_set() or system_settings_form()
* modifications to existing tables
*
* The module should not remove its entry from the {system} table. Database tables defined by hook_schema() will be removed automatically.
*
* NOTE - but our tables are node tables and not created via hook_schema so must be cleaned out here
*
*/
function room_reservations_uninstall() {
/*
db_query("DELETE FROM {node_type} WHERE type LIKE 'room_reservations_%'");
db_query("DELETE FROM {field_config} WHERE field_name LIKE 'rooms_%'");
db_query("DELETE FROM {field_config_instance} WHERE bundle LIKE 'room_reservations_category'");
db_query("DELETE FROM {field_config_instance} WHERE bundle LIKE 'room_reservations_room'");
db_drop_table('{field_data_rooms_room_category}');
db_drop_table('{field_data_rooms_room_capacity}');
db_drop_table('{field_revision_rooms_room_category}');
db_drop_table('{field_revision_rooms_room_capacity}');
db_drop_table('{field_data_reservation_room}');
db_drop_table('{field_revision_reservation_room}'); */
// remove reservation type
db_query("DELETE FROM {node_type} WHERE type LIKE 'room_reservations_%'");
db_query("DELETE FROM {field_config} WHERE field_name LIKE 'reservation%'");
db_query("DELETE FROM {field_config} WHERE field_name IN ('room_category', 'room_capacity')");
db_query("DELETE FROM {field_config_instance} WHERE bundle LIKE 'room_reservations_%'");
// remove our custom fields - this means all RR content will be removed including room nodes
$fields = array(
'reservation_block_title',
'reservation_date',
'reservation_length',
'reservation_repeat_type',
'reservation_repeat_until',
'reservation_room',
'reservation_series_id',
'reservation_time',
'reservations_display_order',
'room_capacity',
'room_category',
);
foreach ($fields as $field) {
db_drop_table('field_data_' . $field);
db_drop_table('field_revision_' . $field);
}
}
/**
* attempt to clean up the mess of field names
*/
function room_reservations_update_7000() {
db_change_field('field_data_room_capacity', 'room_capacity_value', 'reservations_room_capacity_value', array(
'type' => 'int',
'length' => 11,
'description' => 'Number of people the room can accommodate.'));
db_change_field('field_revision_room_capacity', 'room_capacity_value', 'reservations_room_capacity_value', array(
'type' => 'int',
'length' => 11,
'description' => 'Number of people the room can accommodate.'));
db_change_field('field_data_room_category', 'room_category_target_id', 'reservations_room_category_target_id', array(
'type' => 'int',
'length' => 10,
'description' => 'Which category the room is in.'));
db_change_field('field_revision_room_category', 'room_category_target_id', 'reservations_room_category_target_id', array(
'type' => 'int',
'length' => 10,
'description' => 'Which category the room is in.'));
db_change_field('field_data_reservation_display_order', 'reservation_display_order_value', 'reservations_display_order_value', array(
'type' => 'int',
'length' => 11,
'description' => 'Order to display rooms and categories.'));
db_change_field('field_revision_reservation_display_order', 'reservation_display_order_value', 'reservations_display_order_value', array(
'type' => 'int',
'length' => 11,
'description' => 'Order to display rooms and categories.'));
db_rename_table('field_data_room_capacity', 'field_data_reservations_room_capacity');
db_rename_table('field_data_room_category', 'field_data_reservations_room_category');
db_rename_table('field_revision_room_capacity', 'field_revision_reservations_room_capacity');
db_rename_table('field_revision_room_category', 'field_revision_reservations_room_category');
db_rename_table('field_data_reservation_display_order', 'field_data_reservations_display_order');
db_rename_table('field_revision_reservation_display_order', 'field_revision_reservations_display_order');
db_drop_table('field_data_room_reservations_room_capacity');
db_drop_table('field_data_room_reservations_room_category');
db_drop_table('field_data_rooms_room_capacity');
db_drop_table('field_data_rooms_room_category');
db_drop_table('field_revision_room_reservations_room_capacity');
db_drop_table('field_revision_room_reservations_room_category');
db_drop_table('field_revision_rooms_room_capacity');
db_drop_table('field_revision_rooms_room_category');
db_drop_table('field_data_reservation_carrier');
db_drop_table('field_data_reservation_email_addresses');
db_drop_table('field_data_reservation_phone');
db_drop_table('field_data_reservation_txtmsg');
db_drop_table('field_revision_reservation_carrier');
db_drop_table('field_revision_reservation_email_addresses');
db_drop_table('field_revision_reservation_phone');
db_drop_table('field_revision_reservation_txtmsg');
db_update('field_config')
->fields(array(
'field_name' => 'reservations_room_capacity',
))
->condition('field_name', 'room_capacity', '=')
->execute();
db_update('field_config')
->fields(array(
'field_name' => 'reservations_room_category',
))
->condition('field_name', 'room_category', '=')
->execute();
db_update('field_config')
->fields(array(
'field_name' => 'reservations_display_order',
))
->condition('field_name', 'reservation_display_order', '=')
->execute();
db_update('field_config_instance')
->fields(array(
'field_name' => 'reservations_room_capacity',
))
->condition('field_name', 'room_capacity', '=')
->execute();
db_update('field_config_instance')
->fields(array(
'field_name' => 'reservations_room_category',
))
->condition('field_name', 'room_category', '=')
->execute();
db_update('field_config_instance')
->fields(array(
'field_name' => 'reservations_display_order',
))
->condition('field_name', 'reservation_display_order', '=')
->execute();
}
/**
* fix a couple of the Notices - due to incomplete node defs
*/
function room_reservations_update_7001() {
foreach (_room_reservations_installed_fields_room() as $field) {
field_update_field($field);
}
foreach (_room_reservations_installed_instances_room() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = 'room_reservations_room';
field_update_instance($instance);
}
}
/**
* Add Cateogry field Minimum Advanced Booking,
* Add Cateogry field Setup time,
* Add Cateogry field Takedown time
*/
function room_reservations_update_7002() {
$existing = field_info_field_map();
$create = array(
'reservations_minadvbooking',
'reservations_prebuffer',
'reservations_postbuffer',
);
foreach (_room_reservations_installed_fields_category() as $field) {
if (isset($existing[$field['field_name']])) {
continue;
}
if (in_array($field['field_name'], $create)) {
field_create_field($field);
}
}
foreach (_room_reservations_installed_instances_category() as $instance) {
if (isset($existing[$instance['field_name']])) {
continue;
}
$instance['entity_type'] = 'node';
$instance['bundle'] = 'room_reservations_category';
if (in_array($instance['field_name'], $create)) {
field_create_instance($instance);
}
}
}