You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
8.2 KiB
235 lines
8.2 KiB
4 years ago
|
<?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);
|
||
|
}
|
||
|
}
|
||
|
}
|