Best practice forum (Archived)

Audience rules for user fields not working correctly

 
Brian King
Audience rules for user fields not working correctly
by Brian King - Monday, 16 September 2013, 6:25 AM
 

Hi,

for an audience that should include all users whose country is 'Austria' and whose language is 'German', the audience is being populated with the users who do *not* match these criteria.

SQL like this is being generated:

SELECT userid AS id, MAX(inrules) AS addme, MAX(inmembers) AS deleteme
FROM (
SELECT u.id as userid, 1 AS inrules, 0 AS inmembers
FROM mdl_user u
WHERE u.username <> 'guest'
and u.deleted = 0
and u.confirmed = 1 AND (1=1
AND ( 1=1
AND ((u.country) IS NULL OR u.country NOT ILIKE '%AT%' ESCAPE E'\\')
AND ((u.lang) IS NULL OR u.lang NOT ILIKE '%de' ESCAPE E'\\')
)
) UNION ALL
SELECT cm.userid AS userid, 0 AS inrules, 1 AS inmembers
FROM mdl_cohort_members cm
WHERE cm.cohortid = 25 ) q
GROUP BY userid
HAVING MAX(inrules) <> MAX(inmembers)

It appears that cohort_rule_sqlhandler_in::get_query_base_operator(($operator, $query, $lov) is not working quite the way it should.  It's getting passed a value of 1 for the $operator (which is, by the way COHORT_RULES_OP_IN_EQUAL, which = 1 ).  However, it's not looking for COHORT_RULES_OP_IN_EQUAL in the switch statement.  It finds COHORT_RULES_OP_IN_NOTCONTAIN, which = 1, and returns SQL based on that.

 

Brian King
Re: Audience rules for user fields not working correctly
by Brian King - Monday, 16 September 2013, 8:50 AM
 

I've reported this on support.totaralms.com, where it belongs, I guess.

Simon Coggins
Re: Audience rules for user fields not working correctly
by Simon Coggins - Wednesday, 18 September 2013, 6:31 PM
Group Totara

Hi Brian,

Yes we discovered this one ourselves. It looks like it was introduced in 2.4.8 and we now have a fix out in 2.4.10.

Simon