You are here

function date_update_5200 in Date 5.2

Same name and namespace in other branches
  1. 6 date/date.install \date_update_5200()

Version 5.2 updates.

File

date/date.install, line 332

Code

function date_update_5200() {
  $ret = array();
  module_enable(array(
    'date_timezone',
  ));

  // Make sure date module loads after date_api.
  $ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'date'");

  // No longer using the cached formats.
  cache_clear_all('date_formats', 'cache', TRUE);
  drupal_load('module', 'content');

  // Granularity names have been changed to conform with keys used in date arrays.
  $replace = array(
    'Y' => 'year',
    'M' => 'month',
    'D' => 'day',
    'H' => 'hour',
    'N' => 'minute',
    'S' => 'second',
  );
  $fields = content_fields();
  foreach ($fields as $field) {
    if (strstr($field['type'], 'date')) {
      $field_settings = unserialize(db_result(db_query("SELECT global_settings from {node_field} where field_name = '%s'", $field['field_name'])));
      $granularity = array();
      foreach ((array) $field_settings['granularity'] as $item) {
        $granularity[] = strtr($item, $replace);
      }
      $field_settings['granularity'] = $granularity;

      // Save the new settings.
      db_query("UPDATE {node_field} SET global_settings = '%s' WHERE field_name='%s'", serialize($field_settings), $field['field_name']);
    }
  }
  date_install_clear();
  content_clear_type_cache();
  return $ret;
}