Updated: Comment #68
Problem/Motivation
A fatal PHP error occurs when publishing a comment and a "Unpublish comments with keywords" action is enabled.
PHP Fatal error: Cannot use object of type stdClass as array in /.../includes/common.inc on line 5672
This is a major issue as it would cause blank comments to be saved.
Steps to reproduce issue:
1. Create some node.
2. Enable Trigger module.
3. Create "Unpublish comments with keywords" action. Set 2 or more keywords. for example "http://, www., mailto:"
4. Set action to trigger on "New comment saved" event.
5. Type a comment on a node and click "preview"
6. Submit comment.
7. WSOD. Comment saved without body.
The issue is traced to the comments module in /core/modules/comment/comment.module
, inside the comment_unpublish_by_keyword_action
function.
This function is making a call for drupal_render($comment) but $comments is a comment object and not render array.
Proposed resolution
Proposed solution is to get a renderable array of the comment and not the comment object, using the comment_view function.
For Drupal 8 there is a patch in #56
https://drupal.org/files/1461732-56.patch
Remaining tasks
Needs to be backported for Drupal 7.
User interface changes
None
API changes
None
Related Issues
Not sure
Comment | File | Size | Author |
---|---|---|---|
#111 | interdiff.txt | 687 bytes | dcam |
#111 | 1461732-111-comment-action.patch | 3.76 KB | dcam |
#89 | interdiff-[1461732]-[84]-[89].txt | 1.62 KB | filijonka |
#89 | 1461732-89-comment-action.patch | 3.77 KB | filijonka |
#76 | 1461732-76-comment-action.patch | 856 bytes | filijonka |
Comments
Comment #1
xjmThanks for the report. Could you post specific steps to reproduce this issue on a clean install of D7?
Comment #2
fasdalf@fasdalf.ru CreditAttribution: fasdalf@fasdalf.ru commentedThat's how it happened:
1. Create some node.
2. Enable Trigger module.
3. Create "Unpublish comments with keywords" action. Set 2 or more keywords. for example "http://, www., mailto:"
4. Set action to trigger on "New comment saved" event.
5. Type a comment on a node and click "preview"
6. Submit comment.
7. WSOD. Comment saved without body.
Comment #3
xjmThanks @fasdalf@fasdalf.ru! Does this happen if you follow those steps on a clean install?
Comment #4
fasdalf@fasdalf.ru CreditAttribution: fasdalf@fasdalf.ru commentedYes. I have reproduced this bug in 2 existing install and 1 new install.
Comment #5
xjmThat's a bona fide major bug then, unfortunately. Filing against 7.x since trigger has been removed from core in D8.
Comment #6
xjmTagging novice to add an automated test, since the steps in #2 can be used to write a functional test fairly easily.
Comment #7
filijonka CreditAttribution: filijonka commentedhi
hopefully I can give a solution for this but first some thoughts.
The error is in comment_unpublish_by_keyword_action.
This function is making a call for drupal_render($comment) but $comments is a commentobject and not render array
first try:
first line is added and second line is changed.
first line isn't good imho due to sending a null for a variable is wrongly and also creates an error in log.
it also seems that the comment, even though the status is corretly set to COMMENT_NOT_PUBLISHED,is published.
Comment #8
filijonka CreditAttribution: filijonka commentedhi
the php error of this issolved but
Comment #9
filijonka CreditAttribution: filijonka commentedok hopefully that will solve it now
Comment #10
xjmThanks @filijonka. Looks like a nice simple fix, although having to do a full
node_load()
is a little worrisome. I wonder if we can mock the node object? It just looks like it's being used to determine how the comment form and links will be displayed, which may not be relevant.First though let's see what the bot thinks and write a test for it.
Comment #12
cdracars CreditAttribution: cdracars commented#9: drupal-trigger_comment_by_keywords-1461732.patch queued for re-testing.
Comment #13
filijonka CreditAttribution: filijonka commentedyes you're right about the node_load and it's quite sufficient to just initialize an object.
Comment #14
star-szrHere's a test, it fails without the patch in #9 and passes with it. Improvements welcome, especially since this is my first attempt at writing an automated test.
Comment #16
xjmThe test looks great, and the correct test failure is exposed on testbot. The only things I'd change are two minor points about the assertion message (and in both case the rest of
trigger.test
is providing the bad example):Most of our assertion messages just indicate the expected result, so in this case I'd go with simply "A comment can be added when...". The second thing is that (unlike almost any other text string) assertion messages do not need to be translated; see http://drupal.org/simpletest-tutorial-drupal7#t. (And yeah, the rest of the module's tests doesn't follow either of these suggestions.)
Want to reroll with those changes, and then upload both the test patch by itself and another patch with the test combined with #9? I'd still prefer to work around the
node_load()
but we can at least confirm that #9 causes #14 to pass.Thanks!
Comment #17
filijonka CreditAttribution: filijonka commentedignore #9 and use this one instead.
We actuallydon't need a node for this one,we just need an object.
Comment #18
star-szrThanks for the review @xjm!
Re: #17
I believe there should be a space between the two arguments here.
Should there be a blank line between these two lines?
I'll do a re-roll this evening.
Comment #19
filijonka CreditAttribution: filijonka commentedblank line?
sorry for the mistake,felt so bad i hadn't ul the patch so made it in a hurry
Comment #20
star-szrHere's the revised test, with a better assertion message and not wrapped in t() - thanks @xjm.
Two patches, one with the test only and one with the patch in #19. The first should fail, the second should pass.
Comment #21
star-szrUh oh, the test seems to be failing on my local sandbox with
Undefined property: stdClass::$comment
.Comment #23
filijonka CreditAttribution: filijonka commentedhey
kind realised now that this has been marked component trigger.module but the error is actually in comment.module and we should have done this for 8.x, not7.x and backporting to 7.x.
so remarking and will do new patch for 8.x
The patch for7.x is still valid and should be tested for.
Comment #24
filijonka CreditAttribution: filijonka commentedComment #25
udaksh CreditAttribution: udaksh commentedComment #26
udaksh CreditAttribution: udaksh commentedComment #27
filijonka CreditAttribution: filijonka commentedcould you please explain why this new patch?
Comment #28
xjmIt looks like #26 is a performance fix. #24 (and the current code) is performing the same render repeatedly for every comment, which is unnecessary.
However, #26 has several code style errors which should be fixed. Also, we need to figure out a way to test this in Drupal 8 with trigger removed; maybe the actions module has some tests we could extend? Finally, I'm concerned about the exception that was exposed when the test was added in #20; we need to fix that as well.
Comment #29
filijonka CreditAttribution: filijonka commentedsorry @xjm but you're for once wrong, the rendering in #24 is only done once,it's not declared within the foreachloop.
Comment #30
xjm@filijonka ^ Sorry, that is what I meant. And you're right, I guess the deletion is in the earlier patch as well. I have no idea what the additional patch is for, then. :) We still need to get it passing the test, though.
Comment #31
filijonka CreditAttribution: filijonka commented@xjm that's alright,i'm just happy you're wrong for once:)
and yes I'll take a look at whenI got the time.probably gonna need to ask Q though.
Comment #32
ZenDoodles CreditAttribution: ZenDoodles commentedComment #35
cweagansUpdating tags per http://drupal.org/node/1517250
Comment #36
marcingy CreditAttribution: marcingy commentedOk patch with test only, combined patch to follow shortly.
Comment #37
marcingy CreditAttribution: marcingy commentedAnd combined version.
Comment #39
marcingy CreditAttribution: marcingy commented#37: 1461732.patch queued for re-testing.
Comment #41
marcingy CreditAttribution: marcingy commented#37: 1461732.patch queued for re-testing.
Comment #42
BerdirThis looks good and has test coverage. Changing to RTBC and will trigger a re-test to set it back if it doesn't apply anymore but I doubt that code has changed.
Comment #43
Berdir#37: 1461732.patch queued for re-testing.
Comment #44
catchThis looks fine except one hunk in the tests:
So $this->postComment) doesn't return a real comment, not introduced by this patch though.
However the code comment doesn't appear to be an actual sentence. Should it be "Load the full comment so that status is available."?
Comment #45
marcingy CreditAttribution: marcingy commentedYes that is what it should be.
Comment #47
marcingy CreditAttribution: marcingy commented#45: 1461732.patch queued for re-testing.
Comment #48
swentel CreditAttribution: swentel commentedLooks good now, RTBC and will trigger retest just to be sure.
Comment #49
swentel CreditAttribution: swentel commented#45: 1461732.patch queued for re-testing.
Comment #50
catch#45: 1461732.patch queued for re-testing.
Comment #52
swentel CreditAttribution: swentel commentedRerolled
Comment #53
swentel CreditAttribution: swentel commentedSetting to RTBC again, will come back NW in case there's something wrong.
Comment #55
swentel CreditAttribution: swentel commentedThis should do it - commentEntityNG conversion made the new test crash.
Comment #56
star-szr#55 looks good, just tweaked the test method and docblock.
Comment #57
BerdirLooks good.
Comment #58
catchLooks great. Committed/pushed to 8.x, moving to 7.x for backport.
Comment #59
danielgmc CreditAttribution: danielgmc commentedWorking on the 7.x backport.
Comment #60
danielgmc CreditAttribution: danielgmc commentedComment #61
dcam CreditAttribution: dcam commentedBackported #56 to D7.
It wasn't the most straightforward backport since the Action module and its functions which are used in the D8 patch don't exist in D7, at least as far as I know. I'm not familiar with actions or their code, so I maybe I don't know what I'm doing. I did what I could to replicate the missing functionality.
Comment #63
dcam CreditAttribution: dcam commentedSwitched back to using comment_build_content() instead of comment_view(). Set node->comment = 0 in order to prevent the exception in comment_links() which was mentioned in #21.
Comment #65
dcam CreditAttribution: dcam commented#63: 1461732-63-comment-action-test.patch queued for re-testing.
Comment #66
BerdirThat looks like a rather ugly hack. Why not do a $node = node_load($comment->nid)?
Comment #67
dcam CreditAttribution: dcam commentedSee #10, #13, #16, and #17. xjm preferred this hack to loading an entire node object.
Comment #68
dcam CreditAttribution: dcam commentedhttp://drupal.org/node/1427826 contains instructions for updating the issue summary with the summary template.
The summary may need to be updated with information from comments.
Comment #69
webwarrior CreditAttribution: webwarrior commentedIssue summary updated
Comment #69.0
webwarrior CreditAttribution: webwarrior commentedIssue summary updated (webwarrior)
Comment #70
martin107 CreditAttribution: martin107 commentedpatch no longer applies.
Comment #71
filijonka CreditAttribution: filijonka commented#70 can you give some more information than that it doesn't applies? in what way doesn't it applies any longer?
Comment #72
ZenDoodles CreditAttribution: ZenDoodles commented63: 1461732-63-comment-action-test.patch queued for re-testing.
Comment #73
xjmFor the record, the xjm of two years ago was prematurely optimizing, and it's possible folks should instead listen to Berdir.
Comment #74
filijonka CreditAttribution: filijonka commentedI've been testing this now for awhile and the patch #63 solves the issue but it seems that the comment is posted anyway even if the action is triggered
Comment #75
filijonka CreditAttribution: filijonka commentedComment #76
filijonka CreditAttribution: filijonka commentedafter reading through this issue carefully, taking in all opinions and debugging the system with patch #63 i came to conclusion that patch weren't correct so I rewrote it.
there is no test with this but it will come. The main problem with the earlier patches (even the d8 one which is no longer interesting since comment is rewritten) is that it only sets the comment as unpublished but it actually never saves it.
Comment #77
filijonka CreditAttribution: filijonka commentedA test for previous patch
Comment #79
filijonka CreditAttribution: filijonka commentedsorry ehm forgott that I made changes...
Comment #81
filijonka CreditAttribution: filijonka commentedComment #82
filijonka CreditAttribution: filijonka commentedComment #84
filijonka CreditAttribution: filijonka commentedok got a bit wiser thanks to berdir..needed a combined patch and not a test only patch
Comment #85
filijonka CreditAttribution: filijonka commentedComment #86
secretsayan CreditAttribution: secretsayan commentedThanks!!
The patch is working fine...
Comment #87
filijonka CreditAttribution: filijonka commentedComment #88
Gaelan CreditAttribution: Gaelan commentedRemoved double issue summary template.
Comment #89
filijonka CreditAttribution: filijonka commentedComment #90
dawehnerShould we typehint \Drupal\comment\CommentInterface?
It feels a bit wrong to use all that old methods instead of using the proper alternative already.
Comment #91
filijonka CreditAttribution: filijonka commentedignore prev comment, chat with @dawehner and he had missed this is a D7 patch
Comment #92
joshi.rohit10079: 1461732-78-comment-action.patch queued for re-testing.
Comment #94
filijonka CreditAttribution: filijonka commentedwhy just retest this without any comments on why or changin tags or anything @joshi.rohit100?
Comment #95
joshi.rohit100@filijonka, sorry for that. But it was by mistake.
Comment #96
filijonka CreditAttribution: filijonka commented89: 1461732-89-comment-action.patch queued for re-testing.
retesting to confirm if it really needs reroll.
Comment #98
mrjmd CreditAttribution: mrjmd commentedWorking on a reroll.
Comment #99
mrjmd CreditAttribution: mrjmd commentedI was able to cleanly apply the patch in #89 to HEAD, don't think this needs a reroll.
Comment #100
filijonka CreditAttribution: filijonka commented89: 1461732-89-comment-action.patch queued for re-testing.
Comment #101
filijonka CreditAttribution: filijonka commentedComment #102
Rick Hood CreditAttribution: Rick Hood commentedFollowed steps to reproduce 1-6 (from original issue above) with 1461732-89-comment-action.patch applied and confirm there is no error now.
Comment #106
filijonka CreditAttribution: filijonka commentedComment #107
wranvaud CreditAttribution: wranvaud commentedThe patch works, no errors, comments get correctly published/unpublished, THX!
Comment #108
David_Rothstein CreditAttribution: David_Rothstein commentedSorry, I'm not clear why this is using comment_build_content() rather than comment_view() like the Drupal 8 patch did...
The difference could (in some cases) be important because comment_view() invokes some hooks that allow the data it returns to be changed.
I see there were some PHP notices and such when that was tried in one of the earlier patches, but it should be possible to track down why....? comment_view() really seems like the correct way to get the same version of the rendered comment that users actually see on the site.
Comment #109
filijonka CreditAttribution: filijonka commentedhmm ok it's a change by dcam between comment/patch in 61 and 63 done two years back.
question is if this is such a significant problem and if so how to prove it so we have to do yet another patch and wait yet another x months/years.
Comment #110
dcam CreditAttribution: dcam commentedI don't remember why I did that. My suspicion is that comment_view() wouldn't work with the $node parameter being an empty stdClass object, but comment_build_content() did. As @Berdir mentioned in #66, this was all just an ugly hack which I attempted to implement because @xjm didn't want to load an entire node object. She later retracted that in #73. So, there probably isn't any reason why we can't load the node object and use comment_view() now.
Comment #111
dcam CreditAttribution: dcam commentedSince we're loading the node now, let's see if it works with comment_view().
Comment #112
chx CreditAttribution: chx commentedGood we are adding a test to cover this now. It's quite odd that we tried to render a comment object like that...
Comment #115
filijonka CreditAttribution: filijonka commentednothing chnaged so setting back this to green per #112
Comment #118
filijonka CreditAttribution: filijonka commentedComment #119
filijonka CreditAttribution: filijonka commentedComment #122
filijonka CreditAttribution: filijonka commentedper #112
Comment #125
filijonka CreditAttribution: filijonka commentedComment #128
filijonka CreditAttribution: filijonka commentedComment #131
filijonka CreditAttribution: filijonka commentedComment #134
dcam CreditAttribution: dcam commentedComment #137
dcam CreditAttribution: dcam commentedComment #138
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks!
I fixed a few small issues in the test on commit (removed an unused $result variable, and fixed a few code style issues):