You are here

function number_update_4 in Content Construction Kit (CCK) 5

Data is now stored in per-field tables.

File

./number.install, line 75

Code

function number_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 'number_integer':
        $columns = array(
          'value' => array(
            'type' => 'int',
            'not null' => TRUE,
            'default' => 0,
          ),
        );

        // the following line will trigger (negligible) warnings if content_update_5 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_int FROM {node_field_int_data} WHERE field_name = '" . $field['field_name'] . "'");
        }
        else {
          $ret[] = update_sql('INSERT INTO {' . $table . '} (vid, nid, ' . $field['field_name'] . "_value) SELECT vid, nid, field_int FROM {node_field_int_data} WHERE field_name = '" . $field['field_name'] . "'");
        }
        break;
      case 'number_decimal':
        $columns = array(
          'value' => array(
            'type' => 'float',
            'not null' => TRUE,
            'default' => 0,
          ),
        );

        // the following line will trigger (negligible) warnings if content_update_5 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_float FROM {node_field_float_data} WHERE field_name = '" . $field['field_name'] . "'");
        }
        else {
          $ret[] = update_sql('INSERT INTO {' . $table . '} (vid, nid, ' . $field['field_name'] . "_value) SELECT vid, nid, field_float FROM {node_field_float_data} WHERE field_name = '" . $field['field_name'] . "'");
        }
        break;
    }
  }
  $ret[] = update_sql('DROP TABLE {node_field_int_data}');
  $ret[] = update_sql('DROP TABLE {node_field_float_data}');
  db_query('DELETE FROM {cache}');
  return $ret;
}