In apachesolr_get_parent_terms(), a call to db_rewrite_sql() declares the primary table as "t". This is assumed by other modules to be an alias for the table term_data.

That in turn means that other modules hook_db_rewrite_sql() understandably add conditions on database columns like t.vid, which doesn't exist on the term_hierarchy table.

An example is Domain Taxonomy Access, which generates the following error:

User warning: Unknown column "t.vid" in "where clause" query: SELECT DISTINCT t.tid, t.parent FROM term_hierarchy t LEFT JOIN domain_taxonomy_access dta ON dta.tid = t.tid WHERE ((dta.grant_view >= 1 AND ((dta.gid = 0 AND dta.realm = "domain_site") OR (dta.gid = 6 AND dta.realm = "domain_id"))) OR t.vid IN(2,3,4,5,1,7,6,8)) AND ( t.tid IN (97)) in _db_query() (line 147 of /var/www/drupal6-wrap/includes/database.mysqli.inc).

This can be fixed by re-aliasing the term_hierarchy table as e.g. "th", which DTA doesn't know about.

Comments

jp.stacey’s picture

Please find attached a patch against 6.x-1.2 (It's an older version, but it's the one we're currently using on this client site.)

(This work sponsored by Torchbox.)

pwolanin’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Status: Needs work » Needs review
jpmckinney’s picture

Status: Needs review » Fixed

Harmless. Committing. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Yaron Tal’s picture

Status: Closed (fixed) » Active

Wouldn't it be better to add the term_data table to the query and keep t as the primary table? That way db_rewrite_sql still would make a difference. By using th modules like Domain Taxonomy Access will need to either add th to their hook or won't work on the Solr block.

Making it:

 $result = db_query(db_rewrite_sql("SELECT th.tid, th.parent FROM {term_data} t INNER JOIN {term_hierarchy} th ON th.tid = t.tid WHERE th.tid IN (". db_placeholders($new_tids) .")", 't', 'tid'), $new_tids);
nick_vh’s picture

Do you have a patch and a way for us to reproduce the issue? This issue was already fixed and closed so re-opening without a good intro is hard for others to follow.
So :
Show the limitations from the current implementations
Show a way to reproduce a problem
Show your proposed solution

Yaron Tal’s picture

StatusFileSize
new779 bytes

Well the limitation is that by using term_hierarchy (th) as the primary table instead of term_data (t) modules like Domain Taxonomy Access will need to either add th to their hook or won't work on the Solr block. By not working on the block, I mean that they won't be able to filter out the terms, and thus leave terms visible to users who shouldn't have access to them.

To reproduce the problem:
Install the Apache Solr module and Domain Taxonomy Access. Enable a taxonomy filter, and disallow users to see some of the terms.
The terms will still be visible in the block, because the apache solr module is using th as the primary table, and DTA expects all modules that select terms to use t as the primary table.

A solution would be to patch the DTA module and all modules that use hook_db_rewrite_sql() to add their changes if the main table is th.

Another solution which I proposed 2 comments up would be to patch the apache solr module to use t as the primary table instead of th. This would need a JOIN in the query, which is a bit of overhead, but it would make rewriting the sql a lot easier.

I attached a patch to demonstrate what I meant.

nick_vh’s picture

Status: Active » Needs review
nick_vh’s picture

Status: Needs review » Closed (won't fix)

This should be fixed in 6.x-3.x. Closing the issue, better to maintain a new version

Yaron Tal’s picture

6.x-1.x: Maintained. The version shipped with Acquia Drupal. Best tested version available.

Then I guess 1.x will soon be updated to get the status un-maintained? And the 3.x beta-1 version will become stable?

If bugfixes like this don't even make it to the 1.x range.