While setting up a view today, I suddenly discovered 200 forum posts from a forum I deleted over year ago (on a 5.x site). This is because forum.module doesn't delete posts when you delete a forum, even though it says it does, leaving potentially thousands of orphaned nodes in the database (and otherwise difficult to find - none of the filter settings in admin/content/content will find them for example because they're not in a term to be filtered by).

To reproduce. Create one forum. Post one forum topic in it. Delete the forum in admin/content/forum/edit/forum/1 and see this message:

Deleting a forum or container will also delete its sub-forums and posts, if any. This action cannot be undone.
After you delete, go back to admin/content/node and your post will still be there.

http://api.drupal.org/api/function/forum_confirm_delete_submit/6 doesn't make any attempt to delete any nodes at all, and hasn't since it was introduced.

If this is by design, then the message shouldn't say "delete [...] posts" because it's not doing that. But really, if you delete a forum, you ought to be able to delete all the posts at the same time rather than go separately to admin/content/node beforehand. The main issue though, is you can't go back and delete those forum posts all together once you've deleted the forum not possible afterwards because you can no longer filter by that term.

At this stage in the release cycle, and especially now there's multiple node types in forums, I'm tempted to just submit a patch for the string and revisit in D7. Since this has led to 200 stale nodes languishing somewhere in the depths of my db, and only a custom view to get rid of them, I'm marking as critical though. It'll be a trivial fix to the string, probably not straightforward to sort out a delete action.

Comments

catch’s picture

Title: Deleting a forum doesn't delete posts » Deleting a forum doesn't delete posts, as claimed.
Priority: Normal » Critical
catch’s picture

Status: Active » Needs review
StatusFileSize
new1.18 KB

OK here's a patch to just change the string.

t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/content/forum', t('Deleting a forum or container will also delete its sub-forums if any.  To delete posts in this forum, visit <a href="@content_admin">content administration</a> first. This action cannot be undone.', array('@content-admin' => 'url(admin/content/node)')),

For D7, rather than changing the function to actually delete the posts (since a forum could include all kinds of content types now), it might be better to force the user to reassign posts to another forum if there's any nodes associated with the one they're deleting - this is an option with a couple of different forum packages I think. That's a feature request though.

chx’s picture

Status: Needs review » Reviewed & tested by the community

I agree. The delete would be quite difficult esp that if there is a shadow copy then it does not need to be deleted... Also it's not entirely impossible that there are other navigation means leading to said nodes (you can tag them for eg) so deleting might not be desired at all.

keith.smith’s picture

Status: Reviewed & tested by the community » Needs work

I can't roll a patch right now, unfortunately, but there is a double space between sentences in this string (and is it missing a comma near "if any")?

catch’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.18 KB

Thanks Keith, both fixed in this one.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Agreed that we'd rather document this good now, and revisit this in D7. Even if this is a string change for translators, oh well. Committed this one.

catch’s picture

Version: 6.x-dev » 7.x-dev
Status: Fixed » Active

Thanks Gabor, glad my 3am bug report made some sense.

Since this still leaves admins with no (easy) way to find all their 'deleted' forum topics even with the string change, I'm changing the status back to active and bumping to D7 for continuity.

catch’s picture

Title: Deleting a forum doesn't delete posts, as claimed. » Deleting a forum doesn't delete posts
Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new1.05 KB

Patch to modify message and watchdog strings to remove verbiage stating that posts were deleted as well, since well, they're not.

catch’s picture

Damn, missed that one. Since it only removes words from a string, any chance this could be backported to 6.x?

edit: and the string changes look fine to me.

Anonymous’s picture

I'm willing to write a patch that will give the option to a) delete posts from a deleted forum or b) move the posts to another forum if others desire this behavior. One or two +1s should give be convincing enough for me :)

catch’s picture

@boydjd - a) is going to be tricky now we have multiple content types in forums, and some of them may also be represented outside forums as well. It's going to be very hard to tell what should be considered 'inside' a forum. b) is what I currently do direct in the database when deleting forums, and it's also a feature of a couple different forum packages, so +2 ;)

However, we should get #9 RTBCed and committed first

dries’s picture

Priority: Critical » Normal

I committed the help text fixes to D7. I'm not sure this is critical so lowering the priority to 'normal'.

There is no good or wrong here -- the solution will be non-trivial if we want to take into account all the use cases. Posts can belong to multiple forums (or multiple taxonomy terms), different node types can be in a forum, etc. We can investigate this more, but I'm tempted to suggest that we should focus our efforts on the mass node administration pages. They already allow complex filtering and mass-deletion. There is room for improvement there that might make this particular issue easier to deal with as well. Food for thought, huh.

catch’s picture

Priority: Normal » Critical
Status: Needs review » Active

I'm pretty sure posts can't belong to multiple forums - that ought to be pretty much impossible given forum_form_alter apart from shadow forum topics no?

The way I see forum deletion working would be you go to delete a forum, and if there's any posts in it, you get a required select form with all forums in it (apart from the one being deleted) and some help text explaining that all forum topics will be moved to the new forum, alongside a pointer to admin/content/node.

When you submit the form it does UPDATE {forum} SET tid = $tid WHERE tid = $old_tid; then the same in {term_node} - with probably some special handling for shadow forum topics to avoid duplicates. As noted - this is what I currently do with deleted forums by hand to avoid orphaned topics. Once that's done, taxonomy_del_term() handles the rest as now.

That way - actual deletion is down to the administrator in admin/content/node, but we prevent the orphaning of forum topics.

Also, as far as I know taxonomy_del_term() doesn't touch records in the {forum} table, and I can't see anything to correct this elsewhere in forum module, which means a whole bunch of stale data in there. So marking back to critical on that basis, and active, since there's no patch here with the string corrections committed.

catch’s picture

Title: Deleting a forum doesn't delete posts » Deleting forums leaves stale data

Retitling since we' no longer dealing with the actual deletion of posts in this issue.

Anonymous’s picture

@catch What would be the suggested handling for deleting a forum when no other forum exists?

I think we should develop some use cases/scenarios here for forum deletion. Off the top of my head:

1) Delete a forum, with no posts
2) Delete a forum, with posts, no other forums exist
3) Delete a forum, with posts, other forums exist

david strauss’s picture

beginner’s picture

I don't understand, #0 claims that deleting a forum does not delete the associated nodes.
#90202: Tests for deleting forums and http://api.drupal.org/api/function/forum_taxonomy indicate otherwise!

catch’s picture

I just manually created a forum and forum topic, then deleted the forum, and the forum topic still shows up at admin/content/node. So this is still valid, but I'm not sure why that's the case..

alexanderpas’s picture

wait a minute... moved topics get deleted... and non-moved topics doesn't get deleted... does someone sees a pattern there???

JamesAn’s picture

The issue here is not about the fact that forum topics persist after their forum or container is deleted. The issue is how do we handled these orphaned nodes.

The choices are summed up well in #16:

1) Delete a forum, with no posts
2) Delete a forum, with posts, no other forums exist
3) Delete a forum, with posts, other forums exist

1) No change need. Forum is deleted without a problem.
2) Confirm with user that posts will be deleted too. There shouldn't be an alternative like moving them to another forum, they're deleting the only forum and making a new one would be synonymous with just editting the original one.
3) Give the user the choice to either delete the posts or move them to a forum of their choosing.

Do these approaches sound reasonable?

JamesAn’s picture

Status: Active » Needs work
JamesAn’s picture

Status: Needs work » Needs review
StatusFileSize
new19.67 KB
new17.01 KB
new11.6 KB
new13.11 KB
new10.47 KB

This patch creates a forum overview area in the delete forum confirmation form to give admins a chance to move topics in the forum they're going to delete. It also affects forum deletion so that all topics in that forum are deleted along with the forum so topics are not orphaned without a forum; that seems to be the normal and expected behaviour.

Looking at in from the 3 scenarios from #16:

  1. Deleting a forum with no posts doesn't really change.
  2. Deleting a forum with posts, where no other forums exist, displays a table of topics that will be deleted along with the forum; admins can't move it anywhere since there is no forum to which these topics can be moved.
  3. Deleting a forum with posts, where other forums do exist, displays the same table of topics and provides checkboxes and a move section to allow admins to move topics to other forums before deleting.

There is still some work to be done:

  • The patch doesn't support nested forums and containers yet. Deleting containers and forums will delete topics of these forums and sub-forums, but not the topics in these sub-forums.
  • It also doesn't detect topics in these sub-forums so they can be moved. The patch also incorrectly allows topics to be moved into containers, which are only allowed to contain forums (not topics).

The patch is accompanied by screenshots. There's a before shot, and after shots for the 3 scenarios.

Status: Needs review » Needs work

The last submitted patch failed testing.

alexanderpas’s picture

Status: Needs work » Needs review

stupid bot.

Status: Needs review » Needs work

The last submitted patch failed testing.

deekayen’s picture

Status: Needs work » Needs review

naughty pifr bot again

dddave’s picture

Just want to point to another forums problem that might be connected with this (it is marked duplicate because of the underlying taxonomy issues). Maybe this can/has to be solved in one wash because deleting forums often includes deleting the vocabulary and that results in such mishaps.

#24274: Accidentally Deleting Forums Vocabulary in Categories Breaks Forums?

I am currently struggling with this in D6 and this is definitely a critical showstopper for noobs.

If this is not connected or already dealt with please don't hit me.

JamesAn’s picture

Thanks for bringing up the other issue. I'll have to find some time to look into it. At a glance, I don't think #24274 is related to this issue, although they both affect forum administration.

@dddave, just to clarify, are you currently struggling with this issue (#206820) or the one you mentioned (#24274)?

I was apprehensive about my patch in #23 as it changes the way forums and containers are removed, but I think it's for the better. Someone, or - preferably - some people, need to review it.

If we get a green light, I'll backport the patch to 6.x.

dddave’s picture

Sorry for the ambigious formulation. I am struggling with (#24274).
I posted it here http://drupal.org/node/509604, got some valuable input from Michelle and I am going to try two solutions I found during my resarch (any progress will be posted there so I don't polute this issue here). Anyways, if "my" issue still exists (that means I didn't mess it up myself) it should definitly be solved in D7 as it is a brick wall for inexperienced users.

Good luck with the problem at hand.

Status: Needs review » Needs work

The last submitted patch failed testing.

Status: Needs work » Needs review

Re-test of 206820-23.patch from comment #23 was requested by nvanhove.

Status: Needs review » Needs work

The last submitted patch, 206820-23.patch, failed testing.

sun.core’s picture

Version: 7.x-dev » 8.x-dev

I had the exact same problem these days (forum posts without assigned forum). However, I fear that it's too late to rush in such a large change into D7.

catch’s picture

Priority: Critical » Major

Downgrading all D8 criticals to major per http://drupal.org/node/45111

damien tournoud’s picture

Version: 8.x-dev » 7.x-dev

Bugs cannot target D8, as the tree is not open yet.

steinmb’s picture

Version: 7.x-dev » 8.x-dev

OK, I think we can safely move this the D7 tree now.

pillarsdotnet’s picture

Title: Deleting forums leaves stale data » Relocate or delete topics on forum deletion to avoid leaving stale data in database.
Status: Needs work » Needs review
StatusFileSize
new13.02 KB

Re-rolled patch in #23 for current 8.x checkout, and fixed some problems identified by coder.

Also, better title, I think.

Status: Needs review » Needs work

The last submitted patch, Relocate_or_delete_topics_on_forum_deletion-206820-38.patch, failed testing.

sun’s picture

Category: bug » feature
Priority: Major » Normal

The original bug was fixed in #13. Back then, a new issue should have been created for the remaining feature request. But anyway, let's move on here.

+++ b/modules/forum/forum.admin.inc
@@ -182,26 +182,213 @@ function forum_form_container($form, &$form_state, $edit = array()) {
+  $question = t('Are you sure you want to delete the forum %name?', array('%name' => $term->name));
+  $description = format_plural(count($topics), 'This forum contains 1 topic. Deleting a forum or container will also delete its sub-forums and topics. This action cannot be undone.', 'This forum contains @count topics. Deleting a forum or container will also delete its sub-forums and topics. This action cannot be undone.');
+  $yes = t('Delete');
+  $cancel = l(t('Cancel'), 'admin/build/forum');
+
+  drupal_set_title($question, PASS_THROUGH);
...
+  $form['description'] = array('#markup' => $description);
...
-  return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/structure/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit <a href="@content">content administration</a> first. This action cannot be undone.', array('@content' => url('admin/content'))), t('Delete'), t('Cancel'));
...
+  $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
+  $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
+  $form['actions']['cancel'] = array('#markup' => $cancel);
+  $form['#theme'] = 'forum_confirm_delete';

I don't see why confirm_form() needs to be entirely re-implemented here. Simply call

$form = confirm_form($form, ...);

and work off the result. This is the form constructor that owns the form, so it is perfectly valid to call the generic helper to get 90% done and revert/adjust/tweak the remaining to its liking.

That said, note that in D7, confirm_form() only sets #theme if it isn't set already. Thus, set it before calling it.

+++ b/modules/forum/forum.admin.inc
@@ -182,26 +182,213 @@ function forum_form_container($form, &$form_state, $edit = array()) {
+    $multilanguage = (module_exists('translation') || db_query("SELECT COUNT(*) FROM {node} WHERE language <> ''")->fetchField());

Should be

db_query_range('SELECT 1 FROM {node} ...', 0, 1)->fetchField();

+++ b/modules/forum/forum.admin.inc
@@ -182,26 +182,213 @@ function forum_form_container($form, &$form_state, $edit = array()) {
+    if (isset($topic->forum_tid) && $topic->forum_tid!= $tid)
+      unset($topics[$nid]);

Coding standards violation.

+++ b/modules/forum/forum.admin.inc
@@ -182,26 +182,213 @@ function forum_form_container($form, &$form_state, $edit = array()) {
+    print_r($topics);
+    print_r($term_dst);
...
+    print_r($topics);

debugging code.

+++ b/modules/forum/forum.admin.inc
@@ -182,26 +182,213 @@ function forum_form_container($form, &$form_state, $edit = array()) {
+function theme_forum_confirm_delete($form) {

D6-style theme function.

+++ b/modules/forum/forum.module
@@ -80,6 +80,10 @@ function forum_theme() {
+    'forum_confirm_delete' => array(
+      'arguments' => array('form' => NULL),

Should use 'render element' instead of 'variables' (again, D6 style here).

+++ b/modules/forum/forum.module
@@ -995,7 +999,7 @@ function template_preprocess_forums(&$variables) {
-  drupal_set_title($title);
+  drupal_set_title(check_plain($title));

Bogus, please revert.

Powered by Dreditor.

pillarsdotnet’s picture

Re-rolled with most of the suggested changes, but someone else is going to have to take over maintenance of this patch because I'm frankly out of my depth and don't use forums anyway.

  • Simply call $form = confirm_form($form, ...); and work off the result.

    Only partially done.

  • +++ b/modules/forum/forum.admin.inc
    @@ -182,26 +182,213 @@ function forum_form_container($form, &$form_state, $edit = array()) {
    +function theme_forum_confirm_delete($form) {

    D6-style theme function.

    Not done.

Naming patch file to avoid re-test and leaving at "needs work" because it does.

jojonaloha’s picture

I'm attaching a patch for D7. It's mostly a re-roll of the one in #41, but I had several errors when I applied it (or #23) to a D7 site. I'm also attaching an interdiff between the two, but I had a little trouble applying the patch, and had to apply it manually, so the interdiff might not be perfect.

I'll try to work on a D8 version soon.

jojonaloha’s picture

There were a few issues I saw with the previous patch.

  • Pager isn't actually used
  • Even when I changed to use the pager, it doesn't make sense in context of delete confirmation because the confirmation form is at the same url as the edit form, and only visible due to the form (POST) state. As soon as you click a link you have left the delete confirmation form. I suggest moving confirmation form to a new page callback.
  • There is still nothing to delete topics that aren't moved. I suggest it should delete topics in a batch process.
  • When there are no other forums the table doesn't have the right number of columns in the rows
  • The select all checkbox in the header is missing

The attached patch should address all those things.

EDIT: Attached patch is for D7

andypost’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Gábor Hojtsy committed b571a82 on 8.3.x
    #206820 by catch, keith.smith: forum delete confirm form was saying it...
  • Dries committed 2526e41 on 8.3.x
    - Patch #206820 by boydjd: corrected the forum deletion help text/...

  • Gábor Hojtsy committed b571a82 on 8.3.x
    #206820 by catch, keith.smith: forum delete confirm form was saying it...
  • Dries committed 2526e41 on 8.3.x
    - Patch #206820 by boydjd: corrected the forum deletion help text/...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Gábor Hojtsy committed b571a82 on 8.4.x
    #206820 by catch, keith.smith: forum delete confirm form was saying it...
  • Dries committed 2526e41 on 8.4.x
    - Patch #206820 by boydjd: corrected the forum deletion help text/...

  • Gábor Hojtsy committed b571a82 on 8.4.x
    #206820 by catch, keith.smith: forum delete confirm form was saying it...
  • Dries committed 2526e41 on 8.4.x
    - Patch #206820 by boydjd: corrected the forum deletion help text/...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

  • Gábor Hojtsy committed b571a82 on 9.1.x
    #206820 by catch, keith.smith: forum delete confirm form was saying it...
  • Dries committed 2526e41 on 9.1.x
    - Patch #206820 by boydjd: corrected the forum deletion help text/...

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed

Forum is approved for removal. See #1898812: [policy] Deprecate forum module for removal in Drupal 11

This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

It will be moved to the contributed extension once the Drupal 11 branch is open.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » Forum
Version: 11.x-dev » 1.0.1
Component: forum.module » Code
Status: Postponed » Needs work

I think this is outdated but

larowlan’s picture

Version: 1.0.1 » 2.x-dev