When a form element of type options
is submitted Drupal will insert a 'key' => 0
entry for options that are left unselected. The function oa_core_user_spaces_render()
does not handle this correctly when reading $conf['types']
.
In my case $conf['types']
contains the following values when only Spaces are selected:
array(
'oa_space' => 'oa_space',
'oa_group' => 0,
);
The loop foreach ($group_types as $type) {
also loops over this zero value, invoking oa_core_get_groups_by_user_access()
with $type = (int) 0
.
This, in turn causes a cache polution because the result of oa_core_get_groups_by_user_access(..., $type = 0)
is empty but the cache id $cid
used in this function is exactly the same were the oa_core_get_groups_by_user_access()
function called without $type
parameter. As such, once oa_core_get_groups_by_user_access(..., $type = 0)
is called, oa_core_get_groups_by_user_access()
will return an empty result even when the user has spaces.
Steps to reproduce:
Requirements:
- devel module
- current user has one or more oa_space memberships
- Execute the following code in /devel/php:
dpm(oa_core_get_groups_by_user_access());
- Notice that there are results.
- Clear the cache at /admin/config/development/performance
- Go to /spaces (this page contains the panel that contains the bug, the cache is now poluted)
- Execute the following code in /devel/php:
dpm(oa_core_get_groups_by_user_access());
- Notice that there are no results.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2867021-oa_core-cachepolution-1.patch | 1.78 KB | Jorrit |
Comments
Comment #2
Jorrit CreditAttribution: Jorrit at nCode for DOM Digital Online Media GmbH commentedThe attached patch does the following things:
array_filter()
to the options array, stripping the 0 value.oa_core_get_groups_by_user_access()
fromisset()
to!empty()
, fixing any other situations where$type = 0
.$cid
initialization code. In this way, the same cache entry is used regardless ifoa_core_get_groups_by_user_access()
is called with NULL parameters or with their actual default values.For example, currently the following two invocations use different cache entries (with the same contents):
Comment #3
mpotter CreditAttribution: mpotter at Phase2 commentedNice job tracking this down! I confirmed the issue and the fix(es) and committed this to 188c1db in oa_core. Thanks again for your help!
Comment #4
Jorrit CreditAttribution: Jorrit at nCode for DOM Digital Online Media GmbH commentedThanks you!