Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
publishing/unpublishing more than one comment at the time is not working
only last round of query into comment_admin_overview_submit gets properly excuted
the whole method iterates properly
foreach ($form_state['values']['comments'] as $cid => $value) {
if ($value) {
// Perform the update action, then refresh node statistics.
$query
->condition('cid', $cid )
->execute(); // only achieves it purpose on the last iteration
PS: drupal-7.x-dev-2010.01.29
Comment | File | Size | Author |
---|---|---|---|
#21 | comment-admin_6.patch | 6.37 KB | mr.baileys |
#12 | comment-admin.patch | 6.37 KB | mr.baileys |
#9 | comment-admin.patch | 6.37 KB | mr.baileys |
#7 | comment-admin.patch | 4.78 KB | mr.baileys |
#3 | comment-admin.patch | 2.64 KB | mr.baileys |
Comments
Comment #1
mr.baileysHi arhak, thanks for reporting this!
I was able to reproduce this, although it's actually the first query that gets executed. Starting at the second iteration, the conditions are added to the ones already there, resulting in a queries like
UPDATE comment SET status = published WHERE
cid = 1 and cid = 2 and cid = 3 and
…I've spent some time looking into this, but haven't found a clean and simple way to alter or remove existing query conditions without resorting to hook_query_alter, which in this case would probably not be the best approach. In the end I've refactored
comment_admin_overview_submit
so that a new query object is generated for each individual comment operation. Probably not the best approach from a performance point of view, all suggestions to improve this are welcome.Since obviously publishing/unpublishing multiple comments is currently not tested, I've added a test case too.
Patch attached.
Comment #2
mr.baileysI think this is critical. Things don't break horribly, but being forced to publish/unpublish comments one by one is a UX WTF...
Comment #3
mr.baileysUpdated patch.
Comment #4
catchPlease re-roll with cvs diff -up - it's hard to see where changes are being made without that.
Also it ought to be possible to change this to WHERE cid IN ($cids) - but building in array in the foreach(), then adding the condition afterwards.
Comment #5
arhak CreditAttribution: arhak commentedregarding the approach: what about (un)publishing several nodes?
that works
what was the approach there?
was there any performance issue? (regarding several independent queries or soever @#1)
Comment #6
catchWithout checking, I think node mass operations does a node_save() on each node - this is to ensure anything which needs to act on publishing status changes (hooks, triggers etc.) gets fired. Comment mass updates should really do the same thing - it'd be slower but more correct.
Comment #7
mr.baileysYes - the node admin page uses callbacks in the submit handler's iteration, so doesn't suffer from the same problem. It looks like the comment admin screen was a straight conversion to DB:TNG without taking the peculiarities of query objects into account.
Attached is the same patch as #3, but with more context to make reviewing easier. I'd prefer to keep the logic (ie perform all actions on one comment, then move to the next comment) instead of using an array in the condition to first update the database for all comments and then handle the 'collateral' operations one-by-one.
Comment #8
catchThis should be $comment = comment_load($cid); $comment->status = 0; comment_save($comment);
Not using the API functions to update comments is in itself a critical bug.
Comment #9
mr.baileysTalked to catch in IRC, and agreed that the comment admin interface should use the existing comment api (comment_save and comment_delete_multiple) instead of doing the database and related updates itself.
Patch attached that:
Comment #10
mr.baileysstatus...
Comment #11
catchcomment_save() already calls cache_clear_all(), so it shouldn't be necessary to call it again. Otherwise this looks good.
Comment #12
mr.baileysMoved cache_clear_all to just after comment_delete_multiple. (As an aside, shouldn't comment_delete_multiple end with a cache_clear_all too?)
Comment #13
moshe weitzman CreditAttribution: moshe weitzman commentedNo, it shouldn't. Thats the callers job. API functions do not clear or cache or set messages.
Comment #14
catchThis is fine now.
Comment #15
willmoy CreditAttribution: willmoy commentedThis assumes comment_save() suceeds. Perhaps a follow-up issue could add some error handling (compare #704646: node_save() fails silently).
Comment #16
catchWell the problem with node_save() was an transaction / exception was added, without it actually doing anything useful when the exception was thrown, we didn't do that for comments yet. Putting it in a transaction might well be worth doing, but definitely a followup issue.
Comment #17
willmoy CreditAttribution: willmoy commentedNot sure that's correct: http://api.drupal.org/api/function/comment_save/7
Comment #18
catchOh wow, when did that happen! Opened #721378: comment_save() fails silently.
Comment #19
webchickThe only thing that looks a bit funny to me is we're doing === instead of == in places like:
Is there a reason?
Also, what's up with removing comment_operations()?
Comment #20
arhak CreditAttribution: arhak commentedComment #21
mr.baileysThe
'==='
's are unnecessary in this case, re-rolled without them.comment_operations
was removed since IMHO it serves little purpose: the database objects it returns can be used only once if criteria are added, which caused this issue (looping while re-using the object and adding criteria). Additionally, we should be using the comment API functions (comment_save
,comment_multiple_delete
) instead of directly executing the database statements. Since it's tailored specifically for the comment administration page ("Offer different update operations depending on which comment administration page is being viewed."), I don't think this will be an issue for contrib...Comment #22
yoroy CreditAttribution: yoroy commentedLet's see if that makes for a happy webchick :)
Comment #23
moshe weitzman CreditAttribution: moshe weitzman commentedcode looks good to me.
Comment #24
catchMarked #352895: comment_operations bypasses comment_save as duplicate.
Comment #25
andypost@mr.baileys take a look at #729628: Checkbox "select all" is broken on node and comment listing tables in /admin marked as duplicate.
I take a different approach - just to clear conditions in that loop, also changed a test.
I think this patch is better because using comment_save() which triggers hook_comment_presave() but a bit slowly.
My +1 to commit
Comment #26
Dries CreditAttribution: Dries commentedI'll leave this patch for webchick to review as she provided a number of reviews earlier on.
Comment #27
webchickThanks, Dries. Looks good here! Thanks for the vastly expanded test coverage!
Committed to HEAD.