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.
I was trying to use the "Recent comments" block and got the following fatal error:
Fatal error: Call to a member function condition() on a non-object in /home/davereid/Projects/drupal-head/modules/comment/comment.module on line 338
Looked in the code and the following is the problem:
$result = db_select('comment', 'c')
->fields('c', array('nid', 'subject', 'cid', 'timestamp') )
->innerJoin('node', 'n', 'n.nid = c.nid')
->condition('c.nid', $nids, 'IN')
->condition('c.status', COMMENT_PUBLISHED)
->condition('n.status', 1)
->orderBy('c.cid', 'DESC')
->range(0, $number)
->execute();
Comment | File | Size | Author |
---|---|---|---|
#11 | 349823-comment-get-recent-D7.patch | 9.35 KB | Dave Reid |
#10 | 349823-comment-get-recent-D7.patch | 9.21 KB | Dave Reid |
#9 | 349823-comment-get-recent-D7.patch | 9.07 KB | Dave Reid |
#8 | 349823-comment-get-recent-D7.patch | 8.78 KB | Dave Reid |
#1 | 349823-comment-get-recent-D7.patch | 1.43 KB | Dave Reid |
Comments
Comment #1
Dave ReidAttached patch fixes the error by using
$query = db_select('comment', 'c');
and using the rest of the alterations with the $query object.Comment #2
lut4rp CreditAttribution: lut4rp commentedYep, it works all right now!
Comment #3
Dries CreditAttribution: Dries commentedLooks like we need a test here?
Comment #4
Dries CreditAttribution: Dries commentedComment #5
Dave ReidComment #6
webchickRan into this again today. Would be great to see this fixed. :)
Comment #7
catchComment #8
Dave ReidHere's my work on the patch with test so far. I found that the comment tests never tried to enter a comment without a subject, so I added that for good measure. This will probably come back with one fail because the block title is not saving correctly. I might have seen another issue for that somewhere...
Comment #9
Dave ReidOk yay...I figured it out. A block needs to be moved to a region first before you can edit the title. My only question is should the block test be more thorough? Should we directly test the output of theme('comment_block')?
The other changes in this patch:
- Test posting a comment without a subject (hadn't been done in the extensive comment tests)
- Move the tiny CommentNodePage tests into CommentInterfaceTest. It fits better there and it's one less test class that needs to be reset/run.
- Moves testCommentRSS out of CommentHelperCase and into its own test. Every time CommentHelperCase is extended, testCommentRSS is run. Not exactly expected or desired...
This should be ready for a full review!
Comment #10
Dave ReidRe-rolled with a quick DBTNG improvment using fetchAll() and doc blocks on the new test.
Comment #11
Dave ReidAdded missing phpdoc to the tests that were moved around. Nothing wrong with more documentation.
Comment #12
catchHad a look through this and nitpicked in irc, the tests pass. RTBC.
Comment #13
webchickExcellent, thanks! :) Committed to HEAD.