You are here

function date_update_7001 in Date 7.3

Same name and namespace in other branches
  1. 7.2 date.install \date_update_7001()

Get rid of the separate widgets for repeating dates.

The code now handles repeating dates correctly using the regular widgets.

File

./date.install, line 151
Install, update and uninstall functions for the Date module.

Code

function date_update_7001() {
  $query = db_select('field_config_instance', 'fci', array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  $query
    ->join('field_config', 'fc', 'fc.id = fci.field_id');
  $query
    ->fields('fci');
  $query
    ->condition(db_or()
    ->condition('fc.type', 'date')
    ->condition('fc.type', 'datestamp')
    ->condition('fc.type', 'datetime'));
  $results = $query
    ->execute();
  $allowed_types = array(
    'date_popup_repeat',
    'date_text_repeat',
    'date_select_repeat',
  );
  foreach ($results as $record) {
    $instance = unserialize($record['data']);
    if (in_array($instance['widget']['type'], $allowed_types)) {
      $instance['widget']['type'] = str_replace('_repeat', '', $instance['widget']['type']);
      db_update('field_config_instance')
        ->fields(array(
        'data' => serialize($instance),
      ))
        ->condition('field_name', $record['field_name'])
        ->condition('entity_type', $record['entity_type'])
        ->condition('bundle', $record['bundle'])
        ->execute();
    }
  }
  field_cache_clear();
  drupal_set_message(t('The widgets for repeating dates have changed. Please check the Display Fields page for each content type that has repeating date fields and confirm that the right widget has been selected.'), 'warning');
}