Closed (fixed)
Project:
Flag
Version:
6.x-2.x-dev
Component:
Flag core
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Anonymous (not verified)
Created:
23 May 2012 at 12:32 UTC
Updated:
14 Dec 2018 at 07:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
quicksketchThanks for the report. Looks like you're correct and Flag does not clean up its data for comments. It does implement hook_user_cancel() and hook_node_delete(), it's only comments that have this problem.
Comment #2
rafamatito commentedFirst of all, sorry for my bad english. I have fixed the problem implementing hook_comment_delete and doing a little refactorization on hook_node_delete.
Comment #3
Anonymous (not verified) commentedThe patch works. I've also tested deleting a comment using the Entity API (via Rules), which indeed falls back to hook_comment_delete(). This is a great example of how neat Drupal is :)
Very nice and clean work, rafamatito.
Comment #4
andypostRe-roll with fixed doc-block and indent
Comment #5
andypostThis is a bug.
Comment #6
andypostThis require hook_update_n
with
Comment #7
andypostComment #8
istryker commentedYou have actually fixed 2 bugs with #7. See #1650810: flag_node_delete() does not delete nodes. I've included a patch there that would clean-up and fix both issues.
Comment #9
andypostFixed patch:
- added cleanup for nodes from #1650810: flag_node_delete() does not delete nodes
- comment module could be disabled so we need to check for it's table.
- fixed table name {comment}
- wrong $cid changed to $content_id parameter
Credits to iStryker for update function for {node}
Comment #10
rafamatito commentedThank you for change and update the patch, this was my first patch and I didn't know the rules for patches, sorry.
Comment #11
rwilson0429 commentedThanks for the patch. The patch did not apply cleanly for me. I got the following errors trying to apply the patch:
patch:9: Trailing white space.
patch:10: Trailing white space.
/**
patch:11: Trailing white space.
* Clean-up flag records for deleted nodes and comments.
patch:12: Trailing white space.
*/
patch:12: Trailing white space.
function flag_update_7202() {
fatal: corrupt patch at line 89
Comment #12
andypost@rwilson0429 do you trying to apply patch against 7.x-2.x-dev?
Comment #13
rwilson0429 commented@andypost, yes I am trying to apply the patch against 7.x-2.x-dev.
When I tried to apply the patch on Windows7 using cgywin, I got the error messages in #11.
When I tried to apply the patch on a Lynux server, I didn't get the whitespace or function errors but, I did get the 'fatal: corrupt patch at line 89' error.
Comment #14
Anonymous (not verified) commentedThe patch of #9 applies cleanly, just tested on Windows XP + Git Bash/MINGW32:
I didn't test it for function again, but a previous patch worked for me (see above).
Comment #15
joachim commentedLooks pretty good! A few problems though:
db_query() can only be used for SELECT. These should be http://api.drupal.org/api/drupal/includes!database!database.inc/function...
Given we're about to go to any entity, let's keep this comment generic about content types!
Ditto.
And here too.
That's a separate problem, shouldn't be in this patch.
Also, we should refactor flag_user_account_removal() to make use of the new helper -- but that can be done as a follow-on, or we do all the the refactoring to _flag_content_delete() first as a task of its own.
Comment #16
andypostNot sure that it's possible to hook all entities by the same way because for nodes and users we need special handlers :( So I changed signature
patch should have to user db_query() to delete records because of core limits, see #1267508: Subselects don't work in DBTNG conditions, except when used as value for IN
Filed RTBC'ed #1686644: Chnge php-doc hook_node_type() to hook_node_type_delete()
Comment #17
andypostLet's fix this bug and start unification in #1035410: Flag any entity
Comment #18
joachim commentedAgreed.
Though I don't know how much of a clean-up this issue should be, as I've just spotted this:
I can't find any hook that matches either hook_translation_change() or hook_node_translation_change().
So this comment is a lie:
But I'm happy for that to be another issue.
Comment #19
andypost@joachim this hook related to i18n staff, and implemented by http://drupal.org/project/translation_helpers not sure how this works but prefere do not touch that places see #318328: Hook to respond to change of source translation
EDIT Let's fix the bug and then continue unification and clean-up in follow-ups, they are out of scope for this patch
Comment #20
joachim commented> patch should have to user db_query() to delete records because of core limits, see #1267508: Subselects don't work in DBTNG conditions, except when used as value for IN
I added a note about this to the update hook, and also fixed the spacing in the queries there.
Committed the slightly tweaked version. Thanks for everyone's work on this!
Issue #1596492 by andypost, rafamatito: Fixed flag database data not cleaned up on comment & node delete.
Comment #21
joachim commentedChanging the version for backporting this.
Comment #22
joachim commentedThe patch is going to be significantly different on D6:
- implement http://api.drupal.org/api/drupal/developer!hooks!core.php/function/hook_... to delete a comment's flagging records
- in hook_nodeapi, find the node's comments and clean those up too (which may prove problematic if http://api.drupal.org/api/drupal/modules!comment!comment.module/function... has fired first... gee thanks comment module for not firing hook_comment() there!
- clean up data from the table in an update hook
I'd say let's not bother with the refactoring to a helper.
Comment #23
joachim commentedThis blocks beta 8 if the both 2.x branches' releases are to remain in sync.
Comment #24
socketwench commentedWhat if we schedule a cron job to delete any "orphaned" comment flags? That will take care of anything that hook_comment() doesn't bring to our attention?
Comment #25
joachim commentedThat seems a bit heavy-handed to me.
Here's how another module that adds stuff to comments tackles it:
http://drupalcode.org/project/comment_upload.git/blob/refs/heads/6.x-1.x...
Given this is in use on d.org too, I think we can safely assume it's the Right Way(TM) :)
Comment #26
socketwench commentedUnderstood. Here's my first stab at the patch for 6.x-2.x. (Universe; I hope I did that right.)
Comment #27
joachim commentedThanks for working on this!
Patch is looking good, just a few small tweaks:
Needs a final full stop.
Needs a space either side of the '='.
Some whitespace errors here.
No need to give parameters for a hook implementation.
I'm not sure these queries are so long they warrant this, but it's your call. But if you do wrap them, these two lines need to be indented. The others should maybe be 2 rather than 4 spaces? But check with core / other modules.
Comment #28
socketwench commentedFound out my IDE was still using tabs for tabs instead of spaces. Should be fixed now as well as all above issues.
The SQL statements are wrapped as they are as that's how a Enterprise DBA taught me. It's a hard habit to break, but it really keeps things clean for longer queries. Hopefully the spaces are preserved correctly in this version.
Comment #29
joachim commentedI'm all in favour of readability, so keep the habit :)
Whitespace here.
Whitespace is a bane. I use a text editor that has a command to trim it, I use a git gui that shows me whitespace in uncommitted changes, and for patch reviews, dreditor which shows them too. And still they creep in!
Missing full stop.
That's very diligent of you, making a one-case switch() block. I'd have been lazy and made it an if(). ;)
Comment #30
wjaspers commentedI'm not sure that the nodeapi call to query for all comment ID's attached to node X is ideal ... unless there needs to be an event attached to this.
Although this will work, looping over every comment attached to delete it could be exceptionally slow.
http://www.postgresql.org/docs/8.2/static/sql-delete.html
http://dev.mysql.com/doc/refman/5.0/en/delete.html
I think this style query may be more appropriate:
Comment #31
socketwench commented@joachim Hopefully I fixed the whitespace issue this. Stop should be added. As for the switch statement, I guess I just got back into the habit back from the few times I tried to write modules.
@wjaspers That is a great idea! In the attached patch.
Comment #32
joachim commentedI have a splitting headache this morning so I honestly can't tell what's changed with the query, but the whitespace is fixed.
Issue #1596492 by socketwench, andypost, rafamatito: Fixed flag database data not cleaned up on comment & node delete.