bricoleurs / bricolage

Content management and publishing system
http://www.bricolagecms.org/
111 stars 51 forks source link

Fatal error when switching between Jobs and Document search #48

Open brewt opened 10 years ago

brewt commented 10 years ago

Don't know if this is just an issue with the Bricolage install I'm working on, but if I go to perform a Document search, then go to Jobs and search, then go back to the Document search, I get a fatal error:

Can't use string ("%") as an ARRAY ref while "strict refs" in use at bricolage/comp/widgets/listManager/listManager.mc line 681.

And that's happening because $crit = '%'. Didn't dig deep enough to find out why that being set to that.

My fix was to check $crit and $crit_field:

diff --git a/comp/widgets/listManager/listManager.mc b/comp/widgets/listManager/listManager.mc
index 47f7cc6..04b2801 100755
--- a/comp/widgets/listManager/listManager.mc
+++ b/comp/widgets/listManager/listManager.mc
@@ -679,7 +679,9 @@ my $build_constraints = sub {
     my $list_arg   = {};

     # If any criteria were passed then we need to constrain our list.
-    if ($crit && $crit_field) {
+    if ($crit && $crit_field &&
+        ref $crit eq 'ARRAY' && ref $crit_field eq 'ARRAY' &&
+        @$crit == @$crit_field) {
         # If field is an array, build a hash with the fields as the keys and
         # $crit for vals
         if (ref $crit_field) {

But there's obviously some underlying code that's causing the search state to be messed up and should get fixed.

brewt commented 10 years ago

Updated patch since there are some cases (eg. User search) where $crit and $crit_field aren't refs:

diff --git a/comp/widgets/listManager/listManager.mc b/comp/widgets/listManager/listManager.mc
index 216a4e4..3067411 100644
--- a/comp/widgets/listManager/listManager.mc
+++ b/comp/widgets/listManager/listManager.mc
@@ -677,7 +677,8 @@ my $build_constraints = sub {
     if ($crit && $crit_field) {
         # If field is an array, build a hash with the fields as the keys and
         # $crit for vals
-        if (ref $crit_field) {
+        if (ref $crit eq 'ARRAY' && ref $crit_field eq 'ARRAY' &&
+            @$crit == @$crit_field) {
             @{$list_arg}{@$crit_field} = @$crit;
         } else {
             $crit_field = $def_sort_field if $crit_field eq '_default';