You are here

function availability_calendars_update_7201 in Availability Calendars 7.2

Same name and namespace in other branches
  1. 6.2 availability_calendars.install \availability_calendars_update_7201()

Optimize storage for Availability Calendars (issue #1083198).

File

./availability_calendars.install, line 383
Install, update and uninstall functions for the Availability Calendars module.

Code

function availability_calendars_update_7201(&$sandbox) {

  // Change datetime field to date (text on sqlite).
  // Assumption is that the conversion will be executed nicely by the database, keeping the date part...
  db_change_field('availability_calendars_day', 'date', 'date', array(
    'description' => 'Date of availability state.',
    'mysql_type' => 'DATE',
    'pgsql_type' => 'DATE',
    'sqlite_type' => 'TEXT',
    // SQLite does not have a DATE type
    'not null' => TRUE,
  ));

  // Add primary key on nid, date.
  // Drop first: people might already have added a primary key themselves (e.g. to edit the table in a db-tool).
  db_drop_primary_key('availability_calendars_day');
  db_add_primary_key('availability_calendars_day', array(
    'nid',
    'date',
  ));

  // Remove fields year, month, day. Do this after changing the type of the datetime field,
  // and after setting the primary key (possibly removing it from these fields if set manually earlier).
  // We will only get here if the prior operations succeeded and thus we can be quite sure that we will not
  // loose any availability data.
  db_drop_field('availability_calendars_day', 'day');
  db_drop_field('availability_calendars_day', 'month');
  db_drop_field('availability_calendars_day', 'year');

  // Warn about a change that needs a regeneration of the CSS file
  $link = l(st('Availability Calendars') . ' ' . st('Styling'), 'admin/config/content/availability-calendars/styling');
  drupal_set_message(st("Please visit the '!link' page to regenerate the CSS file.", array(
    '!link' => $link,
  )), 'warning');
}