Hello,

I've just updated featured content on Shared PHP hosting with PHP 5.5, and got this error when opening node with featured content block:

Fatal error: Call to undefined method SelectQuery::setCountQuery() in /home/MYUSER/domains/MYDOMAIN/public_html/sites/all/modules/featured_content/featured_content.module on line 1948

Aaaand I'm in panick now :-)

Comments

Shefa’s picture

I get this error message only when I sort the result by one of these options:
"Closest match...", "Furthest match...", "Vocabulary..."

Talkless’s picture

Yes, in my case it's "Closest match to Current Page by Terms".
What to Display in the Block: Linked titles.
Display style: Unordered list.
Type: Filtered content.

Block is shown inside Display Suite field.

Talkless’s picture

Could someone please check how to fix this error?

eluchel’s picture

I am getting the same error with the same set up as you Talkless

kristen pol’s picture

Status: Active » Postponed (maintainer needs more info)

The code is using:

    $count_query = db_select('taxonomy_index', 'ti');
    $count_query->addExpression('COUNT(ti.tid)', 'count');
    $query = db_select('taxonomy_index', 'ti');
    $query->setCountQuery($count_query);
    $query->fields('ti', array('nid'));
    $query->condition('ti.nid', $nids);
    $query->join('taxonomy_index', 'ti2', 'ti.tid = ti2.tid');
    $query->condition('ti2.nid', arg(1));
    $query->groupBy('ti.nid');
    $query->orderBy('count', $order);
    $results = $query->execute();

The error is on this line:

    $query->setCountQuery($count_query);

yet this is what is used for examples here:

http://drupal.stackexchange.com/questions/52431/how-do-i-add-a-pager-for...

So... it's unclear how to proceed.

What database are you using?

Talkless’s picture

In shared hosting status page reports '5.5.5-10.0.16-MariaDB-log", in virtual Ubuntu 12.04 testing machine "5.5.41-0ubuntu0.12.04.1" (mysql).

Please have in mind that Featured Content 1.5 works fine, error occurs just after upgrade to 1.6, maybe something's hidden withint these changes..?

Talkless’s picture

Kristen, I could send you stripped-down version of our site where you could reproduce this error, would it help?

Talkless’s picture

Looks like
$query = $query->extend('PagerDefault');
is needed, but then different error pops up:

"Unknown column 'count' in 'order clause':"

Nodz’s picture

Talkless is right, SelectQuery/db_select() doesn't have a setCountQuery() method, so we have to extend it up as a PagerDefault.

Unknown column count comes from the last part of the code, count is not actually part of the query fields. Commenting it out solves the error:

    $query = db_select('taxonomy_index', 'ti');
    $count_query = $query->countQuery();
    $query = $query->extend('PagerDefault');
    $query->setCountQuery($count_query);
    $query->fields('ti', array('nid'));
    $query->condition('ti.nid', $nids);
    $query->join('taxonomy_index', 'ti2', 'ti.tid = ti2.tid');
    $query->condition('ti2.nid', arg(1));
    $query->groupBy('ti.nid');
    //$query->orderBy('count', $order);

However I'm assuming the orderBy has a specific purpose so the final result without it might no longer be correct.

Also I'm wondering if the Pager query is actually needed since no pagination is done here.

Nodz’s picture

I looked at this again today and compared it to the code in the previous version. It doesn't help to use the PagerDefault or the count query, what's actually needed is the result of the SQL count() function but on a single field (ti.tid).

I found a way to make it work with $query->addExpression('count(ti.tid)', 'count'); instead of $query->setCountQuery($count_query);

This affects both affect both featured_content_sort_nodes_by_terms and featured_content_sort_nodes_by_vocab, i have one of them working for now, I'll try to add a patch when i have both working using the SelectQueries.

Talkless’s picture

Thank you Nodz very much!

Looking forward to your patch!

Nodz’s picture

About the patch:
I've tested the changes for featured_content_sort_nodes_by_terms it seems to work for me. I've added lots of comments as well explaining the parts should be pretty easy to understand.

I don't have a good way to test featured_content_sort_nodes_by_vocab on the site i'm working on. I've changed the count to work like in the other call and fixed another problem i saw with fields being selected from the wrong table.

So both would need testing, but especially the second one.

Talkless’s picture

I have just checked your patch, and it works nicely in my case.

No WSOD, and generated "featured" list is same as it was before.

EDIT: I've tried many different options, but non of them WSOD any more!

pontus.froden’s picture

Upgraded to 1.6 and got this error. The patch in #12 solved my problems.

Thank you