Forum module:

  • forum_taxonomy wasn't receiving the right arguments from taxonomy_del_term (see below). This meant that only the (topmost) forum term was being deleted - sub-fora and nodes remained intact, open and accessible.
  • forum_taxonomy wasn't deleting containers from the forum_containers variable.
  • Also amended the confirm delete message to highlight the fact that all posts will be deleted as well.

Taxonomy module: taxonomy_del_term:

  • The term passed to module_invoke_all was being cast as an array, when it needed to remain as an object. The forum module is the only module in core that uses hook_taxonomy as far as I can tell - so no harm done anywhere else.
  • Due to the return call _inside_ the loop, only the top most term was being deleted in any taxonomy_del_term call. Orphaned terms still remained in the database and continued to be accessible, editable etc.

Node module:

  • node_delete() - Added a switch that turns off status and watchdog messages when necessary. In the case of forum deletions, this ensures that a status and watchdog message isn't printed for every node deleted.

Please review with care,
-K

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

profix898’s picture

Its not easy to test all aspects of deleting forums/containers/... , so I spent the
last 1 hour on playing with this one.

forum.module:
- all (sub)forums, forums in containers, all associated nodes and comments
seem to be removed correctly with this patch
- when deleting containers they are removed from 'forum_containers'
- new confirm message looks appropriate

taxonomy.module:
- removing the (cast) seems to work for me, but I can't estimate what this
means to other modules ...
- terms are removed correctly

node.module:
- Its a good idea to turn off 'delete' status messages for every node. BUT there
should be at least one message to reflect the forum which has been deleted
and I think there should be a message for every subforum in watchdog. For the
message that shows up on the page one message saying 'forum xyz and all
associated subforums/nodes/comments have been deleted' is sufficient.
At the moment not any message is posted to watchdog when a forum is
deleted.

profix898’s picture

FileSize
2.69 KB

Maybe I should add that all my testings have been driven from
admin/forum and not from admin/taxonomy. On my install
forums are hidden in categories because of the patch we
discussed in http://drupal.org/node/28625

Zen’s picture

Hi Thilo :)

-Thanks for reviewing :) Much appreciated.
-Please don't mix issues.

Your points of concern:

removing the (cast) seems to work for me, but I can't estimate what this means to other modules ...

The cast is only used for hook_taxonomy's delete op. A quick grep revealed that the forum module is the only module in core that uses it. The cast is rather wasteful at any rate.

Its a good idea to turn off 'delete' status messages for every node. BUT there should be at least one message to reflect the forum which has been deleted and I think there should be a message for every subforum in watchdog. For the message that shows up on the page one message saying 'forum xyz and all associated subforums/nodes/comments have been deleted' is sufficient. At the moment not any message is posted to watchdog when a forum is deleted.

I agree. But doing this in the forum module would have involved x extra queries to get the term names and doing this in the taxonomy module would have had the same issue besides the fact that vocabularies frequently have 1000s of terms. A minor issue that (in the interests of getting this patch in) I let slide.

If you've tested things to your satisfaction, please set this issue to RTC.

Gracias,
-K

profix898’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
5.02 KB

What do you think about adding a simple watchdog() to function
forum_confirm_delete_submit. Look at the patch. With it there will
be at least one message refering to the deleted forum term.
Apart from that the patch look good to me.

Zen’s picture

FileSize
5.33 KB

Agreed. I've just reworded the watchdog message for consistency and also amended the drupal_set_message above.

-K

Zen’s picture

FileSize
4.11 KB

Apparently, the "silent mode" will make Baby Jesus Cry (tm). So here's a patch without it :)

-K

Zen’s picture

Status: Reviewed & tested by the community » Needs review

Forgot to set it back to review.

Thanks.
-K

Steven’s picture

Deleting all nodes in a forum seems a bit too destructive to me. Not to mention, it could be a very long operation which might time-out.

cog.rusty’s picture

If I am allowed a non-php-coder opinion, the taxonomy module would look much cleaner without this "special treatment" of the forum module. Instead, it could have an API function to allow a module (any module) to hardwire its taxonomy choices and to gray out the corresponding form elements.

cog.rusty’s picture

Sorry, that was intended for a forum vocabulary issue which I had left open in another browser tab.

nedjo’s picture

Status: Needs review » Needs work

Thanks for identifying and tackling this issue.

At this late point for 4.7 bugs we need to be focusing on the bug part. Deleting the nodes in a forum seems like a distinct issue, and new functionality rather than bug fixing.

Is this a critical issue? It's a bug, but will most users even notice it?

I suggest:

* strip this patch down to the minimum needed to fix the identified bug(s) in term deletion
* open a new feature request issue if desired for the node handling.

Zen’s picture

Status: Needs work » Needs review

Hi Nedjo,

Thanks for reviewing :) As I explained to Steven on #drupal (and failed to update this issue), this patch is _not_ introducing any new functionality. The node_delete is existing functionality but was just being called incorrectly (with an incorrectly cast parameter) via a hook.

An explanation of the current situation in HEAD:

  • When *any* taxonomy term is deleted, taxonomy_del_term is called. This function deletes the parent term and then checks if any child terms have been orphaned as a result (have no other parents). It stores all orphans in an array, and cycles through the same delete procedure until all orphaned terms have been deleted.
  • The above functionality is broken in HEAD as there is a misplaced return() call _inside_ the loop. Therefore, after the parent term is deleted, the function never attends to the child terms as it encounters the return() before that and exits the loop and the function. This basically means that if I delete a term with a 1000 children, there will be a 1000 orphaned terms in the database that will still be accessible, modifiable and possibly rendering any access control mechanism (on the now defunct parent term) moot.
  • taxonomy_del_term also makes a module_invoke('taxonomy'); during each iteration of the above loop. The forum module is the only module in core that utilises this hook. This module_invoke was was being passed an incorrectly cast parameter, thus nullifying the forum_taxonomy hook implementation.
  • The same situation with orphaned terms applies to orphaned forum nodes as well. They are still accessible, modifiable and possibly slip out of any preexisting access control mechanism. This is besides the fact that there will potentially be thousands of "dead" nodes and terms in the database.
  • forum_taxonomy()'s existing functionality is that it will delete all nodes associated with the taxonomy term passed to it. This wasn't being carried out because of the above mentioned mis-cast.
  • forum_taxonomy() was not removing any deleted containers from the forum_containers vocabulary.

The (small) patch in this issue:

  • Fixes the cast issue in taxonomy_del_term().
  • Fixes the errant return() call in taxonomy_del_term.
  • Addresses the forum_containers issue.

To sum up, no new features are being introduced. Only existing functionality is being fixed. And yes, I believe this is critical.

Please only consider the above fixes for this issue. The following related issues will need to be addressed in a *separate* task:

  • forum_taxonomy deletes the nodes associated with a term individually so as to trigger related hooks. I am unaware of any option to delete all nodes en masse.
  • taxonomy_del_term makes a separate module_invoke call for each term. The numer of terms involved here can be very high.
  • Due to the above restriction, there really is no efficient method to collate all the nids in question to display any statistics. I don't believe the forum pages provide similar stats for nested fora either.
  • The current functionality is that for each node deleted, a status message will be displayed on the screen and a watchdog message logged. There can be _many_ nodes..
  • There is currently no functionality to log all the terms being deleted (in taxonomy_del_term) as everything works based on tids.
  • There is a possibility that the script might time out for large fora.

I believe that covers everything. In the interests of getting this patch in, I've created a separate task for these incidental issues at http://drupal.org/node/55331 .

Thanks :)
-K

nedjo’s picture

Ah, right you are, I hadn't read the patch closely enough to see that we already had node deletion :)

Robin Monks’s picture

+1

Although, when applied, please make sure
if ($op == 'delete' && $term->vid == _forum_get_vid()) {

becomes:

if ($op == 'delete' && $term->vid == _forum_get_vid()) {

IRC always says these things best:

How grevious an error!
Two, count 'em! *TWO* spaces before the opening bracket
This is indeed a sad day :(
chx: Heh, really though, that's the only problem.

Robin

Robin Monks’s picture

+1

Although, when applied, please make sure
if ($op == 'delete' && $term->vid == _forum_get_vid()) {

becomes:

if ($op == 'delete' && $term->vid == _forum_get_vid()) {

IRC always says these things best:

How grevious an error!
Two, count 'em! *TWO* spaces before the opening bracket
This is indeed a sad day :(
chx: Heh, really though, that's the only problem.

Robin

Zen’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
4.11 KB
killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

applied

Zen’s picture

Status: Fixed » Closed (fixed)