You are here

function date_update_3 in Date 5

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

Data is now stored in per-field tables.

File

./date.install, line 99

Code

function date_update_3() {
  $ret = array();
  if (!db_table_exists('node_field_date_data')) {
    return $ret;
  }
  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' => 17,
            'not null' => TRUE,
            'default' => "'00010101T00:00:00'",
          ),
        );

        // the following line will trigger (negligible) warnings if content_update_3 was run before
        // (column already exists)
        @content_alter_db_field(array(), array(), $field, $columns);
        $db_info = content_database_info($field);
        $table = $db_info['table'];
        if ($field['multiple']) {
          $ret[] = update_sql('INSERT INTO {' . $table . '} (vid, delta, nid, ' . $field['field_name'] . "_value) SELECT vid, delta, nid, field_date FROM {node_field_date_data} WHERE field_name = '" . $field['field_name'] . "'");
        }
        else {
          $ret[] = update_sql('INSERT INTO {' . $table . '} (vid, nid, ' . $field['field_name'] . "_value) SELECT vid, nid, field_date FROM {node_field_date_data} WHERE field_name = '" . $field['field_name'] . "'");
        }
        break;
    }
  }
  $ret[] = update_sql('DROP TABLE {node_field_date_data}');
  db_query('DELETE FROM {cache}');
  return $ret;
}