Hi,

I'm having an issue getting the "Available on current domain" filter to show nodes that are checked as 'Send to all affiliates' to show within a view that being accessed on a sub domain other than the domain the node is assigned to.

Here is the SQL generated by a view I'm using to try and figure out the issue...

SELECT node.created AS node_created, node.nid AS nid
FROM node node
LEFT JOIN domain_access domain_access ON node.nid = domain_access.nid AND domain_access.realm = 'domain_id'
WHERE (( (node.status = '1') AND (node.type IN  ('offer')) AND (((domain_access.realm = 'domain_id' AND domain_access.gid = 5) OR (domain_access.realm = 'domain_site' AND domain_access.gid = 0))) ))
ORDER BY node_created DESC
LIMIT 10 OFFSET 0

Could this be related to the domain_access join not including domain_access.realm = 'domain_site' records? When I alter the SQL to include these records it seems to work.

Comments

agentrickard’s picture

Yes. That JOIN is incorrect and needs to be removed. I wonder why it's there.

sepph’s picture

I've commented out the following lines 125 > 127 in domain_views.views.inc and it seems to work fine now.

  'extra' => array(
      array('field' => 'realm', 'value' => 'domain_id', 'numeric' => FALSE),
    ),

It looks as though this 'extra' item was added during the last release as version 7.x-1.3 doesn't have this. It looks as though this might have been added as a fix for this issue - http://drupal.org/node/1207936 - as the thread contains a patch adding in these lines (http://drupal.org/files/issues/1207936-bad-join.patch).

agentrickard’s picture

Priority: Normal » Major

Right, so there was some required logic for one use-case but not the other. Needs some review.

Thanks for the work on this.

agentrickard’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

Xomby’s picture

Assigned: Unassigned » Xomby
Status: Closed (fixed) » Needs work

@agentrickard - that didn't seem to fix the issue.
Your patches, which yield the following view sql:

SELECT node.created AS node_created, node.nid AS nid
FROM 
{node} node
LEFT JOIN {domain_access} domain_access ON node.nid = domain_access.nid AND domain_access.realm = 'domain_id'
WHERE (( (node.status = '1') AND (node.type IN  ('article')) AND (node.language IN  ('en', 'und')) AND (((domain_access.realm = 'domain_id' AND domain_access.gid = 2) OR (domain_access.realm = 'domain_site' AND domain_access.gid = 0))) ))
ORDER BY node_created DESC
LIMIT 5 OFFSET 0

which looks like it should work properly... however even running this manually through phpmyadmin is coming up with the same results I'm seeing in the view, just two articles instead of 12 (for me anyway).

The section: "AND domain_access.realm = 'domain_id'" right there in the left join is filtering out all of the "all affiliates" content before we can look for them.

By commenting out lines 125-127 of domain_views.views.inc resolves the issue

SELECT node.created AS node_created, node.nid AS nid
FROM 
node
LEFT JOIN domain_access ON node.nid = domain_access.nid
WHERE (( (node.status = '1') AND (node.type IN  ('article')) AND (node.language IN  ('en', 'und')) AND (((domain_access.realm = 'domain_id' AND domain_access.gid = 2) OR (domain_access.realm = 'domain_site' AND domain_access.gid = 0))) ))

The issue with doing this, however, is it returns duplicate rows.

The fix for THAT is already built into views.
Under the advanced drop down in your view, select query settings, and then distinct.
voila... problem solved...

Xomby’s picture

Assigned: Xomby » Unassigned
agentrickard’s picture

So, what are you suggesting we do?

Xomby’s picture

Well... There's a few options:

  1. Take that line of code out, and let the view return duplicates (knowing that DISTINCT can be turned on in query settings for the view)
  2. Take that line of code out, and force the "DISTINCT" argument for the select statement (may or may not want to do this, and just keep to #1)
  3. Leave that line in and keep things broken
  4. Find another way to form the select statement and achieve the same goals.
broeker’s picture

This one was driving me mad -- updated dev versions of Views, Domain, Domain Views, etc. and none of my Views filters were respecting the Domain Access: Available on current domain - All Affiliates setting. Even if a node was set to show on All Affiliates, it would only show up in the view if it was explicitly set in the "Publish to:" options.

I can confirm that fix above (commenting out those three lines) fixed my problem.

My bigger question is if this is normal, or if I've got something going on to prevent this from working as it should. This seems like a significant issue but there are very few other cases out there regarding this problem.

agentrickard’s picture

Right. We have to figure out how the two patches -- this one and #1207936: Views domain id no show -- interact.

Yuri’s picture

This issue is till not resolved in the latest dev.
By the way, those lines of #2 are now 194-196

Yuri’s picture

and solution #2 does not work any more (in my case)

agentrickard’s picture

Attaching a copy of your View would be helpful.

fox mulder’s picture

StatusFileSize
new5.88 KB

Hi everybody!

Here is the export of my view (domain_views.views.inc is original, not patched).

As Yuri wrote in #13 commenting out of lines 194-196 doesn't influence [UPDATE: see #16] the SQL query of view in 7.x-1.x-dev version.

fox mulder’s picture

Commenting out those certain lines works, but the correct line numbers are: 177-179 in $data['domain_access']['table']['join']['node'] array and than it should be clear all cache.

peacog’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new569 bytes

Commenting out those line works for me too, and I don't get any duplicates, so maybe this is ready to commit? I've rolled a patch against the current dev.

ericclaeren’s picture

The lines removing is one thing, I found out that the field (assigned to current domain) uses a boolean handler, this won't work because when it's from the domain_site realm the gid is 0, which is false, while domain_access says it's true.

So I have created a patch which adds an additional handler and removed the 3 lines, everything seems to work fine. Maybe the maintainer can look into to this problem.

There's another issue http://drupal.org/node/1207936 with this patch (http://drupal.org/files/1090618-query.patch). Don't know if the 3 extra lines are added on purpose, if they are needed for another field/filter then the solution below might be an option, but since I don't know if it's necessary, I'm not adding them.

   $data['domain_access']['table']['join']['node'] = array(
    'left_field' => 'nid',
    'field' => 'nid',
    'extra' => array(
      array('field' => 'realm', 'value' => 'domain_id', 'numeric' => FALSE),
      array('field' => 'realm', 'value' => 'domain_site', 'numeric' => FALSE),
    ),
    'extra type' => 'OR',
  );
  // Define the joins between {node_revision} and {domain_access}.
  $data['domain_access']['table']['join']['node_revision'] = array(
    'left_field' => 'nid',
    'field' => 'nid',
    'extra' => array(
      array('field' => 'realm', 'value' => 'domain_id', 'numeric' => FALSE),
      array('field' => 'realm', 'value' => 'domain_site', 'numeric' => FALSE),
    ),
    'extra type' => 'OR',
  );

I have created a new patch including the field handler for this issue. Could the maintainer look into this, it would be great is this is solved in the latest release since it's quite a large bug for this module, thanks!

ericclaeren’s picture

Crap I applied the wrong comment number, let's try this again.

ericclaeren’s picture

Sorry, I misunderstood something, removing the domain_id line creates duplicates. I am trying to create a fix for it.

* Edit: You have to use distinct, in your query settings.

agentrickard’s picture

I think it was trying to fix that duplicates issue that caused this problem in the first place.

ericclaeren’s picture

The fix is adding a group by on the query in the filter handler, but I found a weird problem, that you also need to add a having statement otherwise the group by (add_groupby) was not added to the query in views and when adding a having statement triggers other group by's are also activated.

Hard to explain this :) Does this sound familiar or made any sense?

bibo’s picture

I agree, this issue and #577008: "Domain Access: Available on current domain True" does not show results if not individually checked on node both seem to address the same problem (which IMO is pretty critical from this modules standpoint).

I believe patch in #19 would address both issues, havent tested yet.

bibo’s picture

Status: Needs review » Reviewed & tested by the community

#19 worked great, thank you! Please commit.

2pha’s picture

#19 worked for me too.

fonant’s picture

#19 works here, in that nodes published to all domains are included. However it does result in duplicate results (presumably nodes that are published to all domains and to the current domain) but that can be fixed by the view's query settings.

rosberg’s picture

patch from #19 works, thank you very much!

knalstaaf’s picture

RTBC I Guess, but what about the file domain_views_handler_field_domain_access_current_all.inc that should go in the includes folder on the Drupal root (#19)?

Is that file still necessary?

mautumn’s picture

Patch from #19 works, thank you very much!

4kant’s picture

#19 + the tipp from #27 helped me.
Thanks