Commit 4573af1f authored by drumm's avatar drumm

#80257 by Jaza. Add a hook for content type changes and use it for keeping vocabulary associations.

parent 12df7225
...@@ -275,16 +275,6 @@ function node_type_form_submit($form_id, $form_values) { ...@@ -275,16 +275,6 @@ function node_type_form_submit($form_id, $form_values) {
return 'admin/content/types/'. str_replace('_', '-', $type->old_type) .'/delete'; return 'admin/content/types/'. str_replace('_', '-', $type->old_type) .'/delete';
} }
if (!empty($form_values['old_type'])) {
if ($type->old_type != $type->type) {
$update_count = node_type_update_nodes($type->old_type, $type->type);
if ($update_count) {
drupal_set_message(t('Changed the content type of %update_count %posts from %old_type to %type.', array('%update_count' => $update_count, '%posts' => format_plural($update_count, 'post', 'posts'), '%old_type' => $type->old_type, '%type' => $type->type)));
}
}
}
$status = node_type_save($type); $status = node_type_save($type);
// Remove everything that's been saved already - whatever's left is assumed // Remove everything that's been saved already - whatever's left is assumed
...@@ -337,6 +327,21 @@ function node_type_form_submit($form_id, $form_values) { ...@@ -337,6 +327,21 @@ function node_type_form_submit($form_id, $form_values) {
return 'admin/content/types'; return 'admin/content/types';
} }
/**
* Implementation of hook_node_type().
*/
function node_node_type($op, $info) {
if (!empty($info->old_type) && $info->old_type != $info->type) {
$update_count = node_type_update_nodes($info->old_type, $info->type);
if ($update_count) {
$substr_pre = 'Changed the content type of ';
$substr_post = strtr(' from %old-type to %type.', array('%old-type' => theme('placeholder', $info->old_type), '%type' => theme('placeholder', $info->type)));
drupal_set_message(format_plural($update_count, $substr_pre .'@count post'. $substr_post, $substr_pre .'@count posts'. $substr_post));
}
}
}
/** /**
* Resets all of the relevant fields of a module-defined node type to their * Resets all of the relevant fields of a module-defined node type to their
* default values. * default values.
......
...@@ -282,10 +282,14 @@ function node_type_save($info) { ...@@ -282,10 +282,14 @@ function node_type_save($info) {
if ($is_existing) { if ($is_existing) {
db_query("UPDATE {node_type} SET type = '%s', name = '%s', module = '%s', has_title = %d, title_label = '%s', has_body = %d, body_label = '%s', description = '%s', help = '%s', min_word_count = %d, custom = %d, modified = %d, locked = %d WHERE type = '%s'", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $existing_type); db_query("UPDATE {node_type} SET type = '%s', name = '%s', module = '%s', has_title = %d, title_label = '%s', has_body = %d, body_label = '%s', description = '%s', help = '%s', min_word_count = %d, custom = %d, modified = %d, locked = %d WHERE type = '%s'", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $existing_type);
module_invoke_all('node_type', 'update', $info);
return SAVED_UPDATED; return SAVED_UPDATED;
} }
else { else {
db_query("INSERT INTO {node_type} (type, name, module, has_title, title_label, has_body, body_label, description, help, min_word_count, custom, modified, locked, orig_type) VALUES ('%s', '%s', '%s', %d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d, '%s')", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $info->orig_type); db_query("INSERT INTO {node_type} (type, name, module, has_title, title_label, has_body, body_label, description, help, min_word_count, custom, modified, locked, orig_type) VALUES ('%s', '%s', '%s', %d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d, '%s')", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $info->orig_type);
module_invoke_all('node_type', 'insert', $info);
return SAVED_NEW; return SAVED_NEW;
} }
} }
......
...@@ -813,6 +813,24 @@ function taxonomy_node_delete($nid) { ...@@ -813,6 +813,24 @@ function taxonomy_node_delete($nid) {
db_query('DELETE FROM {term_node} WHERE nid = %d', $nid); db_query('DELETE FROM {term_node} WHERE nid = %d', $nid);
} }
/**
* Implementation of hook_node_type().
*/
function taxonomy_node_type($op, $info) {
if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
if (db_num_rows(db_query("SELECT * from {vocabulary_node_types} WHERE type = '%s'", $info->old_type))) {
db_query("UPDATE {vocabulary_node_types} SET type = '%s' WHERE type = '%s'", $info->type, $info->old_type);
$num_updated = db_affected_rows();
if ($num_updated) {
$substr_pre = 'Changed the content type association of ';
$substr_post = strtr(' from %old-type to %type.', array('%old-type' => theme('placeholder', $info->old_type), '%type' => theme('placeholder', $info->type)));
drupal_set_message(format_plural($num_updated, $substr_pre .'1 vocabulary'. $substr_post, $substr_pre .'@count vocabularies'. $substr_post));
}
}
}
}
/** /**
* Find all term objects related to a given term ID. * Find all term objects related to a given term ID.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment