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
Comment #1
tim.plunkettAlso, I'm curious to see how this affects programmatically added filters.
Comment #2
tim.plunkett:(
Comment #3
dawehnerThe 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.
Comment #4
dawehnerSo 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.
Comment #5
dawehnerSo here is an approach which uses a simple 0 group, which wrapps all others with AND.
This patch should really really be reviewed
Comment #6
dawehnerThis 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)
Comment #7
dawehnerOne less dsm
Comment #8
dawehnerJust some tracking of work
Comment #9
dawehnerMh let's get this tested. It seems to work for me.
Comment #10
tim.plunkettI added
$has_filter = FALSE;to the top ofviews_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?
Comment #11
dawehnerWell then you would have to rebuild ALL argument handlers
Comment #12
tim.plunkettThe 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.
Comment #13
dawehnerLet's add a "," after AND
Comment #14
tim.plunkettCleaned up the comment. I'm not sure that a better solution exists.
Comment #15
xjmI 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. :)
Hmm, one further? Not sure what this means exactly.
Here group_ids should not have an apostrophe (one could just say "group IDs" even), and it should be "higher than zero."
Comment #16
dawehnerThanks for the review!
Does this version makes it easier to understand what this part does?
Comment #17
tim.plunkettFixed the s/then/than and used xjm's suggestion for "group IDs".
Comment #18
dawehnerJust 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
Comment #19
tim.plunkettExcept the dsm in there, that's fine. I don't think it matters either way.
Comment #20
dawehnerNow existing views should be converted automatically.
Comment #21
dawehnerHere is a new version, which moves the add_key_plus function to views.module and marks the
Comment #22
dawehnerHere is a followup regarding the $view->changed #1400230: Decide whether the view should be marked as changed if any kind of converting happened
Comment #23
tim.plunkettTried 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.
Comment #24
tim.plunkettOpened #1400240: Changes made in views_plugin_display::init() that update the view should notify the user as a follow-up.
Comment #25
dawehnerSo 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.
Comment #26
dawehnerHere 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.
Comment #27
tim.plunkettI 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.
Comment #28
dawehnerLet's keep it open for a bit longer, because there are people which will definitive test this patch as well.
Comment #29
dawehnerWell sad, but let's get it in.