From fcfdafdd2df7f9280f6b323927e59fb7e6694624 Mon Sep 17 00:00:00 2001 From: CollectiveAccess Date: Thu, 17 Oct 2024 22:34:31 -0400 Subject: [PATCH] Force cached search builder list values to objects to ensure they are encoded in JSON as objects and don't lose their keys --- app/helpers/searchHelpers.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/helpers/searchHelpers.php b/app/helpers/searchHelpers.php index 4b9cc17d11..549154841c 100644 --- a/app/helpers/searchHelpers.php +++ b/app/helpers/searchHelpers.php @@ -2108,7 +2108,16 @@ function caGetSearchBuilderFilters(BaseModel $t_subject, Configuration $search_b $show_container_in_labels = caGetOption('showContainerInLabel', $options, false); $key = 'filters_'.$t_subject->tableName().caMakeCacheKeyFromOptions($options ?? [], $t_user ? $t_user->getUserID() : ''); - if (!caGetOption('noCache', $options, false) && CompositeCache::contains($key, 'SearchBuilder') && is_array($cached_data = CompositeCache::fetch($key, 'SearchBuilder'))) { return $cached_data; } + if (!caGetOption('noCache', $options, false) && CompositeCache::contains($key, 'SearchBuilder') && is_array($cached_data = CompositeCache::fetch($key, 'SearchBuilder'))) { + // Values come out of the cache as arrays, but QueryBuilder wants them to be objects in the encoded JSON + // so we cast them to objects here + foreach($cached_data as $k => $v) { + if(isset($v['values']) && is_array($v['values'])) { + $cached_data[$k]['values'] = (object)$cached_data[$k]['values']; + } + } + return $cached_data; + } $table = $t_subject->tableName(); $t_search_form = new ca_search_forms();