-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrooms.install
161 lines (146 loc) · 4.56 KB
/
rooms.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
<?php
/**
* @file
* Install, update and uninstall functions for the rooms module.
*/
/**
* Implements hook_field_schema().
*/
function rooms_field_schema($field) {
if ($field['type'] == 'rooms_options') {
return array(
'columns' => array(
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'quantity' => array(
'type' => 'int',
'not null' => FALSE,
),
'operation' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'value' => array(
'type' => 'float',
'not null' => FALSE,
),
'type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
);
}
}
/**
* Implements hook_requirements().
*/
function rooms_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'runtime':
if (!rooms_library_loaded('fullcalendar', 'minified')) {
$description = array();
$fullcalendar_library = libraries_detect('fullcalendar');
if (!$fullcalendar_library['installed']) {
$description[] = $t('Could not load the FullCalendar Library');
}
$requirements['fullcalendar'] = array(
'title' => $t('FullCalendar'),
'description' => implode('<br />', $description),
'value' => 'FullCalendar Missing',
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['fullcalendar'] = array(
'title' => $t('FullCalendar'),
'description' => $t('The FullCalendar Library is installed'),
'value' => 'FullCalendar Installed',
'severity' => REQUIREMENT_OK,
);
}
}
return $requirements;
}
/**
* Utility function: rename a set of permissions.
*/
function rooms_update_rename_permissions($map) {
// Easy part: rename the permissions in {role_permission}.
foreach ($map as $old_name => $new_name) {
db_update('role_permission')
->fields(array('permission' => $new_name))
->condition('permission', $old_name)
->execute();
}
// Trickier: rename the permission for the in-database Views.
foreach (views_get_all_views() as $view) {
if ($view->type == t('Default')) {
continue;
}
$save_view = FALSE;
foreach ($view->display as $display_name => $display) {
if (!empty($display->display_options['access']['type']) && $display->display_options['access']['type'] == 'perm') {
$permission_name = $display->display_options['access']['perm'];
if (isset($map[$permission_name])) {
$display->display_options['access']['perm'] = $map[$permission_name];
$save_view = TRUE;
}
}
}
if ($save_view) {
$view->save();
}
}
}
/**
* Converts the booking option price value columns from integer to float.
*/
function rooms_update_7001() {
$spec = array(
'type' => 'float',
'not null' => FALSE,
);
$fields = array_filter(field_info_fields(), function($item) {
return $item['type'] == 'rooms_options';
});
foreach ($fields as $field_definition) {
$data_table = 'field_data_' . $field_definition['field_name'];
$revision_table = 'field_revision_' . $field_definition['field_name'];
$field = $field_definition['field_name'] . '_value';
db_change_field($data_table, $field, $field, $spec);
db_change_field($revision_table, $field, $field, $spec);
}
return t('Field structure updated.');
}
/**
* Add the booking option Type column.
*/
function rooms_update_7002() {
$fields = field_info_fields();
foreach ($fields as $field) {
if ($field['type'] == 'rooms_options') {
$revision_table = key($field['storage']['details']['sql']['FIELD_LOAD_REVISION']);
$field_name = $field['storage']['details']['sql']['FIELD_LOAD_REVISION'][$revision_table]['type'];
if (!db_field_exists($revision_table, $field_name)) {
$field_spec = $field['columns']['type'];
$field_spec['initial'] = 'optional';
db_add_field($revision_table, $field_name, $field_spec);
}
$current_table = key($field['storage']['details']['sql']['FIELD_LOAD_CURRENT']);
$field_name = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT'][$current_table]['type'];
if (!db_field_exists($current_table, $field_name)) {
$field_spec = $field['columns']['type'];
$field_spec['initial'] = 'optional';
db_add_field($current_table, $field_name, $field_spec);
}
}
}
}