You are here

function content_type_update in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 5 content_crud.inc \content_type_update()
  2. 6.3 includes/content.crud.inc \content_type_update()
  3. 6 includes/content.crud.inc \content_type_update()

Make changes needed when an existing content type is updated.

Parameters

$info: value supplied by hook_node_type()

1 call to content_type_update()
content_node_type in ./content.module
Implementation of hook_node_type() React to change in node types

File

includes/content.crud.inc, line 633
Create/Read/Update/Delete functions for CCK-defined object types.

Code

function content_type_update($info) {
  if (!empty($info->old_type) && $info->old_type != $info->type) {

    // Rename the content type in all fields that use changed content type.
    db_query("UPDATE {" . content_instance_tablename() . "} SET type_name='%s' WHERE type_name='%s'", array(
      $info->type,
      $info->old_type,
    ));

    // Rename the content fields table to match new content type name.
    $old_type = content_types($info->old_type);
    $old_name = _content_tablename($old_type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
    $new_name = _content_tablename($info->type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
    if (db_table_exists($old_name)) {
      $ret = array();
      db_rename_table($ret, $old_name, $new_name);
      watchdog('content', 'Content fields table %old_name has been renamed to %new_name and field instances have been updated.', array(
        '%old_name' => $old_name,
        '%new_name' => $new_name,
      ));
    }

    // Rename the variable storing weights for non-CCK fields.
    if ($extra = variable_get('content_extra_weights_' . $info->old_type, array())) {
      variable_set('content_extra_weights_' . $info->type, $extra);
      variable_del('content_extra_weights_' . $info->old_type);
    }
  }

  // Reset all content type info.
  // Menu needs to be rebuilt as well, but node types need to be rebuilt first.
  // node_type_form_submit() takes care of this.
  content_clear_type_cache(TRUE);
}