You are here

function date_update_4 in Date 5

Same name and namespace in other branches
  1. 5.2 date/date.install \date_update_4()

File

./date.install, line 143

Code

function date_update_4() {
  $ret = array();
  include_once drupal_get_path('module', 'content') . '/content.module';
  include_once drupal_get_path('module', 'content') . '/content_admin.inc';
  content_clear_type_cache();
  $fields = content_fields();
  foreach ($fields as $field) {
    switch ($field['type']) {
      case 'date':
        $columns = array(
          'value' => array(
            'type' => 'varchar',
            'length' => 20,
            'not null' => TRUE,
            'default' => "'0001-01-01T00:00:00'",
          ),
          'timezone' => array(
            'type' => 'varchar',
            'length' => 50,
            'not null' => TRUE,
            'default' => "'GMT'",
          ),
        );
        $db_info = content_database_info($field);
        if ($db_info['columns']['value']['default'] != "'0001-01-01T00:00:00'") {
          content_alter_db_field(array(), array(), $field, $columns);
        }
        $id = $field['field_name'] . '_value';
        $ret[] = update_sql("UPDATE {" . $db_info['table'] . "} SET {$id} = CONCAT(SUBSTRING({$id},1,4), '-', SUBSTRING({$id},5,2), '-', SUBSTRING({$id},7)) WHERE SUBSTRING({$id}, 5, 1) <> '-'");
    }
  }
  db_query('DELETE FROM {cache}');
  return $ret;
}