#54910, Forum and taxonomy term delete work only superficially, patch by Zen

4.7.x
Gerhard Killesreiter 2006-03-23 21:46:35 +00:00
parent 667298972f
commit d11c07502d
4 changed files with 50 additions and 24 deletions

View File

@ -148,17 +148,28 @@ function forum_nodeapi(&$node, $op, $teaser, $page) {
/** /**
* Implementation of hook_taxonomy(). * Implementation of hook_taxonomy().
*/ */
function forum_taxonomy($op, $type, $object = NULL) { function forum_taxonomy($op, $type, $term = NULL) {
if ($op == 'delete' && $type == 'term' && $object->vid == _forum_get_vid()) { if ($op == 'delete' && $term->vid == _forum_get_vid()) {
$results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $object->tid); switch ($type) {
case 'term':
$results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $term->tid);
while ($node = db_fetch_object($results)) { while ($node = db_fetch_object($results)) {
// node_delete will also remove any association with non-forum vocabularies.
node_delete($node->nid); node_delete($node->nid);
} }
// For containers, remove the tid from the forum_containers variable.
$containers = variable_get('forum_containers', array());
if ($key = array_search($term->tid, $containers)) {
unset($containers[$key]);
} }
elseif ($op == 'delete' && $type == 'vocabulary' && $object->vid == _forum_get_vid()) { variable_set('forum_containers', $containers);
break;
case 'vocabulary':
variable_del('forum_nav_vocabulary'); variable_del('forum_nav_vocabulary');
} }
} }
}
/** /**
* Implementation of hook_settings * Implementation of hook_settings
@ -517,7 +528,7 @@ function _forum_confirm_delete($tid) {
$form['tid'] = array('#type' => 'value', '#value' => $tid); $form['tid'] = array('#type' => 'value', '#value' => $tid);
$form['name'] = array('#type' => 'value', '#value' => $term->name); $form['name'] = array('#type' => 'value', '#value' => $term->name);
return confirm_form('forum_confirm_delete', $form, t('Are you sure you want to delete the forum %name?', array('%name' => theme('placeholder', $term->name))), 'admin/forums', t('Deleting a forum or container will delete all sub-forums as well. This action cannot be undone.'), t('Delete'), t('Cancel')); return confirm_form('forum_confirm_delete', $form, t('Are you sure you want to delete the forum %name?', array('%name' => theme('placeholder', $term->name))), 'admin/forums', t('Deleting a forum or container will delete all sub-forums and associated posts as well. This action cannot be undone.'), t('Delete'), t('Cancel'));
} }
/** /**
@ -525,7 +536,8 @@ function _forum_confirm_delete($tid) {
*/ */
function forum_confirm_delete_submit($form_id, $form_values) { function forum_confirm_delete_submit($form_id, $form_values) {
taxonomy_del_term($form_values['tid']); taxonomy_del_term($form_values['tid']);
drupal_set_message(t('The forum %term has been deleted.', array('%term' => theme('placeholder', $form_values['name'])))); drupal_set_message(t('The forum %term and all sub-forums and associated posts have been deleted.', array('%term' => theme('placeholder', $form_values['name']))));
watchdog('content', t('forum: deleted %term and all its sub-forums and associated posts.', array('%term' => theme('placeholder', $form_values['name']))));
return 'admin/forum'; return 'admin/forum';
} }

View File

@ -148,17 +148,28 @@ function forum_nodeapi(&$node, $op, $teaser, $page) {
/** /**
* Implementation of hook_taxonomy(). * Implementation of hook_taxonomy().
*/ */
function forum_taxonomy($op, $type, $object = NULL) { function forum_taxonomy($op, $type, $term = NULL) {
if ($op == 'delete' && $type == 'term' && $object->vid == _forum_get_vid()) { if ($op == 'delete' && $term->vid == _forum_get_vid()) {
$results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $object->tid); switch ($type) {
case 'term':
$results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $term->tid);
while ($node = db_fetch_object($results)) { while ($node = db_fetch_object($results)) {
// node_delete will also remove any association with non-forum vocabularies.
node_delete($node->nid); node_delete($node->nid);
} }
// For containers, remove the tid from the forum_containers variable.
$containers = variable_get('forum_containers', array());
if ($key = array_search($term->tid, $containers)) {
unset($containers[$key]);
} }
elseif ($op == 'delete' && $type == 'vocabulary' && $object->vid == _forum_get_vid()) { variable_set('forum_containers', $containers);
break;
case 'vocabulary':
variable_del('forum_nav_vocabulary'); variable_del('forum_nav_vocabulary');
} }
} }
}
/** /**
* Implementation of hook_settings * Implementation of hook_settings
@ -517,7 +528,7 @@ function _forum_confirm_delete($tid) {
$form['tid'] = array('#type' => 'value', '#value' => $tid); $form['tid'] = array('#type' => 'value', '#value' => $tid);
$form['name'] = array('#type' => 'value', '#value' => $term->name); $form['name'] = array('#type' => 'value', '#value' => $term->name);
return confirm_form('forum_confirm_delete', $form, t('Are you sure you want to delete the forum %name?', array('%name' => theme('placeholder', $term->name))), 'admin/forums', t('Deleting a forum or container will delete all sub-forums as well. This action cannot be undone.'), t('Delete'), t('Cancel')); return confirm_form('forum_confirm_delete', $form, t('Are you sure you want to delete the forum %name?', array('%name' => theme('placeholder', $term->name))), 'admin/forums', t('Deleting a forum or container will delete all sub-forums and associated posts as well. This action cannot be undone.'), t('Delete'), t('Cancel'));
} }
/** /**
@ -525,7 +536,8 @@ function _forum_confirm_delete($tid) {
*/ */
function forum_confirm_delete_submit($form_id, $form_values) { function forum_confirm_delete_submit($form_id, $form_values) {
taxonomy_del_term($form_values['tid']); taxonomy_del_term($form_values['tid']);
drupal_set_message(t('The forum %term has been deleted.', array('%term' => theme('placeholder', $form_values['name'])))); drupal_set_message(t('The forum %term and all sub-forums and associated posts have been deleted.', array('%term' => theme('placeholder', $form_values['name']))));
watchdog('content', t('forum: deleted %term and all its sub-forums and associated posts.', array('%term' => theme('placeholder', $form_values['name']))));
return 'admin/forum'; return 'admin/forum';
} }

View File

@ -485,7 +485,7 @@ function taxonomy_del_term($tid) {
} }
} }
$term = (array) taxonomy_get_term($tid); $term = taxonomy_get_term($tid);
db_query('DELETE FROM {term_data} WHERE tid = %d', $tid); db_query('DELETE FROM {term_data} WHERE tid = %d', $tid);
db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $tid); db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $tid);
@ -494,13 +494,14 @@ function taxonomy_del_term($tid) {
db_query('DELETE FROM {term_node} WHERE tid = %d', $tid); db_query('DELETE FROM {term_node} WHERE tid = %d', $tid);
module_invoke_all('taxonomy', 'delete', 'term', $term); module_invoke_all('taxonomy', 'delete', 'term', $term);
return SAVED_DELETED;
} }
$tids = $orphans; $tids = $orphans;
} }
cache_clear_all(); cache_clear_all();
return SAVED_DELETED;
} }
function _taxonomy_confirm_del_term($tid) { function _taxonomy_confirm_del_term($tid) {

View File

@ -485,7 +485,7 @@ function taxonomy_del_term($tid) {
} }
} }
$term = (array) taxonomy_get_term($tid); $term = taxonomy_get_term($tid);
db_query('DELETE FROM {term_data} WHERE tid = %d', $tid); db_query('DELETE FROM {term_data} WHERE tid = %d', $tid);
db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $tid); db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $tid);
@ -494,13 +494,14 @@ function taxonomy_del_term($tid) {
db_query('DELETE FROM {term_node} WHERE tid = %d', $tid); db_query('DELETE FROM {term_node} WHERE tid = %d', $tid);
module_invoke_all('taxonomy', 'delete', 'term', $term); module_invoke_all('taxonomy', 'delete', 'term', $term);
return SAVED_DELETED;
} }
$tids = $orphans; $tids = $orphans;
} }
cache_clear_all(); cache_clear_all();
return SAVED_DELETED;
} }
function _taxonomy_confirm_del_term($tid) { function _taxonomy_confirm_del_term($tid) {