function content_type_update in Content Construction Kit (CCK) 5
Same name and namespace in other branches
- 6.3 includes/content.crud.inc \content_type_update()
- 6 includes/content.crud.inc \content_type_update()
- 6.2 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
- ./
content_crud.inc, line 144 - 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 {node_field_instance} 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)) {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("RENAME TABLE {" . $old_name . "} TO {" . $new_name . "}");
break;
case 'pgsql':
db_query("ALTER TABLE {" . $old_name . "} RENAME TO {" . $new_name . "}");
break;
}
drupal_set_message(t('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,
)));
}
}
// reset all content type info.
content_clear_type_cache();
}