I was trying to learn how contextual filters worked with the query object when filters were using OR, and it turns out it's broken.

- Added a filter of published and nid!=0
- Added an argument of content type

The view results were filtered by whatever was passed as the content type.

- Rearranged the filters to be joined with OR. (http://paste.pocoo.org/show/519019)

The view results ignored the argument.

- Rearranged the filters to be in separate filter groups, joined with OR. (http://paste.pocoo.org/show/519018/)

The view results ignored the argument.

Comments

tim.plunkett’s picture

Also, I'm curious to see how this affects programmatically added filters.

tim.plunkett’s picture

:(

dawehner’s picture

The solution would be probably really not easy as the group is part of the argument handler code. So maybe a special group should be used here which is always wrapped into an additional group which is always and AND group.

dawehner’s picture

StatusFileSize
new5.89 KB

So effective this would require to refactor the full add_where, set_where_group and build_condition part.

The build_condition part seems to be more or less ready, see attached patch.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new3.78 KB

So here is an approach which uses a simple 0 group, which wrapps all others with AND.

This patch should really really be reviewed

dawehner’s picture

StatusFileSize
new5.53 KB

This one is now much easier, but the defaults had to be fixed.

On existing views there might be problems with

* wrong group_id's
* wrong displayed group_operators
* maybe wrong queries group_operatores (though this one i didn't saw)

dawehner’s picture

StatusFileSize
new5.19 KB

One less dsm

dawehner’s picture

Status: Needs review » Needs work
StatusFileSize
new6.48 KB

Just some tracking of work

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new6.83 KB

Mh let's get this tested. It seems to work for me.

tim.plunkett’s picture

Priority: Normal » Major
Issue tags: -D7 stable release blocker
StatusFileSize
new6.57 KB

I added $has_filter = FALSE; to the top of views_plugin_query_default::build_condition() like the other booleans, to prevent notices.

I tested this with my example views, and once I rebuilt them they worked fine. Of course, it would be nice if there was a way to avoid rebuilding. I don't suppose using -1 instead of 0 is reasonable?

If using -1 is out of the question, is there any practical way to prevent all views from needing to be rebuilt manually?

dawehner’s picture

Well then you would have to rebuild ALL argument handlers

tim.plunkett’s picture

The last stable blocker for fullcalendar is blocked on this. I'm okay with telling everyone they'll need to rebuild their views if they're using OR filters, as long as merlinofchaos and dereine are both comfortable with it.

dawehner’s picture

Status: Needs review » Needs work
+++ b/plugins/views_plugin_query_default.incundefined
@@ -1030,13 +1030,23 @@ class views_plugin_query_default extends views_plugin_query {
+   * As views has to wrap the conditions from arguments with AND a special group is wrapped around all conditions.

Let's add a "," after AND

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new6.58 KB

Cleaned up the comment. I'm not sure that a better solution exists.

xjm’s picture

I noticed a grammatical error in the patch when @tim.plunkett linked the issue in IRC, so I said I'd do a code style review while I was at it. :)

+++ b/includes/admin.incundefined
@@ -3905,6 +3905,20 @@ function views_ui_rearrange_filter_form_submit($form, &$form_state) {
 /**
+ * Moves each key entry one further.
+ */

Hmm, one further? Not sure what this means exactly.

+++ b/plugins/views_plugin_query_default.incundefined
@@ -1030,13 +1030,24 @@ class views_plugin_query_default extends views_plugin_query {
+   * As views has to wrap the conditions from arguments with AND, a special
+   * group is wrapped around all conditions. This special group has the ID 0.
+   * There is other code in filters which makes sure that the group_id's are
+   * higher then 0.

Here group_ids should not have an apostrophe (one could just say "group IDs" even), and it should be "higher than zero."

dawehner’s picture

StatusFileSize
new6.64 KB

Thanks for the review!

Does this version makes it easier to understand what this part does?

tim.plunkett’s picture

StatusFileSize
new6.64 KB

Fixed the s/then/than and used xjm's suggestion for "group IDs".

dawehner’s picture

StatusFileSize
new7.04 KB
new20.43 KB

Just setup a view with two filters and using OR.

Then i applied the patch and looked at the or configuration, see screenshot

So thing change converts the filter groups on the fly, but i'm not sure whether we might convert
the groups of each filter as well


diff -u b/includes/admin.inc b/includes/admin.inc
--- b/includes/admin.inc
+++ b/includes/admin.inc
@@ -3567,6 +3567,12 @@
 
   $group_options = array();
 
+  // Update filter groups due to moving arguments to group 0 and filters to > 0.
+  if (isset($groups['groups'][0])) {
+    $groups['groups'] = views_ui_array_key_plus($groups['groups']);
+  }
+  dsm($groups['groups']);
+
   /**
    * Filter groups is an array that contains:
    * array(

tim.plunkett’s picture

Except the dsm in there, that's fine. I don't think it matters either way.

dawehner’s picture

StatusFileSize
new8.05 KB

Now existing views should be converted automatically.

dawehner’s picture

StatusFileSize
new8.15 KB

Here is a new version, which moves the add_key_plus function to views.module and marks the

dawehner’s picture

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Tried this with the two views in the OP and this works beautifully. It works dynamically for the views, and when the view is resaved, the groups are updated appropriately.

tim.plunkett’s picture

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

So finally committed, this might make sense to add to 6.x-3.x as well , though quite some of the ui changes would have to be rewritten.

dawehner’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new6.53 KB

Here is the first start of the port to drupal6.

I tested this with all kind of complexity (just arguments, just filters, combined, combinbed + multiple filter groups) it worked fine for me.

In general i would really like to create some simpletests here which checks the general functionality both in d6 and d7.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

I tried it out with the D6 equivalent of my test views from the OP, and the problem is very real before the patch, and very fixed afterward.

dawehner’s picture

Let's keep it open for a bit longer, because there are people which will definitive test this patch as well.

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Well sad, but let's get it in.

Status: Fixed » Closed (fixed)

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