1 system.install system_update_1020()

Convert date settings to config.

Related topics

File

core/modules/system/system.install, line 2046
Install, update and uninstall functions for the system module.

Code

function system_update_1020() {
  // Safety check for date formats.
  if (!db_table_exists('date_format_type')) {
    return;
  }

  // Migrate variables if any.
  $config = config('system.date');
  $config->set('first_day', update_variable_get('date_first_day', 0));
  $config->set('default_country', update_variable_get('site_default_country', ''));
  $config->set('default_timezone', update_variable_get('date_default_timezone', ''));
  $config->set('user_configurable_timezones', update_variable_get('configurable_timezones', 1));
  $config->set('user_empty_timezone_message', update_variable_get('empty_timezone_message', 0));
  $config->set('user_default_timezone', update_variable_get('user_default_timezone', 0));

  // Delete variables.
  update_variable_del('site_default_country');
  update_variable_del('date_first_day');
  update_variable_del('date_default_timezone');
  update_variable_del('configurable_timezones');
  update_variable_del('empty_timezone_message');
  update_variable_del('user_default_timezone');

  // Migrate date formats. These are the defaults that must exist.
  $formats = array(
    'long' => array(
      'label' => 'Default Long Date',
      'pattern' => 'l, F j, Y - H:i',
      'module' => 'system',
    ),
    'medium' => array(
      'label' => 'Default Medium Date',
      'pattern' => 'D, m/d/Y - H:i',
      'module' => 'system',
    ),
    'short' => array(
      'label' => 'Default Short Date',
      'pattern' => 'm/d/Y - H:i',
      'module' => 'system',
    ),
    'html_datetime' => array(
      'label' => 'HTML Datetime',
      'pattern' => 'Y-m-d\\TH:i:sO',
      'module' => 'system',
      'hidden' => 1,
    ),
    'html_date' => array(
      'label' => 'HTML Date',
      'pattern' => 'Y-m-d',
      'module' => 'system',
      'hidden' => 1,
    ),
    'html_time' => array(
      'label' => 'HTML Time',
      'pattern' => 'H:i:s',
      'module' => 'system',
      'hidden' => 1,
    ),
    'html_yearless_date' => array(
      'label' => 'HTML Yearless date',
      'pattern' => 'm-d',
      'module' => 'system',
      'hidden' => 1,
    ),
    'html_week' => array(
      'label' => 'HTML Week',
      'pattern' => 'Y-\\WW',
      'module' => 'system',
      'hidden' => 1,
    ),
    'html_month' => array(
      'label' => 'HTML Month',
      'pattern' => 'Y-m',
      'module' => 'system',
      'hidden' => 1,
    ),
    'html_year' => array(
      'label' => 'HTML Year',
      'pattern' => 'Y',
      'module' => 'system',
      'hidden' => 1,
    ),
  );

  // Update/create custom formats.
  $result = db_query("SELECT * FROM {date_format_type}");
  foreach ($result as $row) {
    if ($pattern = update_variable_get('date_format_' . $row->type)) {
      $format = isset($formats[$row->type]) ? $formats[$row->type] : array();
      $format['label'] = $row->title;
      $format['pattern'] = $pattern;
      $formats[$row->type] = $format;
      update_variable_del('date_format_' . $row->type);
    }
  }

  // Copy over all locale-specific patterns for each date format.
  $locale_result = db_query("SELECT * FROM {date_format_locale}");
  foreach ($locale_result as $row) {
    if (array_key_exists($row->type, $formats)) {
      $formats[$row->type]['locales'][$row->language] = $row->format;
    }
  }

  $config->set('formats', $formats);
  $config->save();

  db_drop_table('date_formats');
  db_drop_table('date_format_type');
  db_drop_table('date_format_locale');
}