function date_update_7004

cis7 date.install date_update_7004()
cle7 date.install date_update_7004()
elmsmedia7 date.install date_update_7004()
icor7 date.install date_update_7004()
meedjum_blog7 date.install date_update_7004()
mooc7 date.install date_update_7004()

Date text widgets should always use an increment of 1.

File

sites/all/modules/ulmus/date/date.install, line 167
Install, update and uninstall functions for the Date module.

Code

function date_update_7004() {

  // Select date fields.
  $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();

  // Find the ones that use the date_text widget.
  foreach ($results as $record) {
    $instance = unserialize($record['data']);
    if (in_array($instance['widget']['type'], array('date_text'))) {
      $instance['widget']['settings']['increment'] = 1;
      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('Date text widgets have been updated to use an increment of 1.'));
}