Through the following error. it may break the functionality. if field_name is not defined

Notice: Undefined variable: field_name in apachesolr_search_nested_facet_items() (line 797 of /var/www/ifood/sites/all/modules/contrib/apachesolr/apachesolr_search.module).

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -783,6 +783,16 @@
       $sortpre = 1000000 - $field['#count'];
     }
 
+    $field_name = $field['#name'];
+    if (function_exists('taxonomy_get_term')) {
+      // Taxonomy filters in the query string use the tid field.
+      if ($field_name == 'tid') {
+        // Each taxonomy vocabulary in the Solr index uses its own field.
+        $term = taxonomy_get_term($field['#value']);
+        $field_name = 'im_vid_' . $term->vid;
+      }
+    }
+
     // Only display children if the block enables it or the parent is clicked.
     if ((isset($facet_show_children['apachesolr_search'][$field_name]) && $facet_show_children['apachesolr_search'][$field_name]) || (!empty($field['#children']) && $field['#active'] == TRUE)) {
       $link['children'] = apachesolr_search_nested_facet_items($query, $field['#children'], $num_found, $sort);

CommentFileSizeAuthor
#6 apachesolr_search_fieldname_fix.patch786 bytesrobinmofo

Comments

pwolanin’s picture

Status: Active » Postponed (maintainer needs more info)

The above is a patch? Can you please explain more clearly the bug. Is it jsut a Notice, or actually affects functionality?

lalit774’s picture

hi

i found notice only. but according to me the below condition never ever true. because $field_name not declare anywhere in the function.

i.e you can remove the below condition because its condition inner code never parse.

if ((isset($facet_show_children['apachesolr_search'][$field_name]) && $facet_show_children['apachesolr_search'][$field_name])

robinmofo’s picture

As well as the notice, I also got a warning

Warning: Invalid argument supplied for foreach() in apachesolr_search_nested_facet_items() (line 755 of /sites/all/modules/contrib/apachesolr/apachesolr_search.module).

Essentially, you are correct the $field_name is not declared and so I replaced my instances with $field['#name'].

I also updated the conditional $facet_show_children to

if (isset($facet_show_children['apachesolr_search'][$field['#name']]) && (!empty($field['#children']) && $field['#active'] == TRUE))  {

As I didn't see the need to check for both (isset) and (true).

My errors are now gone so I'm happy, I'd like to provide these as a patch (because I think I made some other local changes too for other notices? although I've been doing this a lot to contrib module recently as I evaluate them).

What's the status of the current dev version? Does it have any fixes in it?

nick_vh’s picture

Status: Postponed (maintainer needs more info) » Needs work

Please provide a valid patch file so we can fix this :-)

robinmofo’s picture

Assigned: Unassigned » robinmofo

OK, I'll assign it to myself so I don't forget (very busy atm)

robinmofo’s picture

Assigned: robinmofo » Unassigned
Status: Needs work » Needs review
StatusFileSize
new786 bytes

Patched against latest 6.x-1.x-dev branch.. file attached.
Also removing myself as owner.

Status: Needs review » Needs work

The last submitted patch, apachesolr_search_fieldname_fix.patch, failed testing.

robinmofo’s picture

sorry, I used a third party program to create the patch.. I'll get it updated asap.

nick_vh’s picture

Status: Needs work » Closed (cannot reproduce)

Closing in favor of 6.x-3.x and because nobody seems to care (time of last response) or cannot reproduce. If you think this is still an issue in 6.x-3.x, feel free to re-open!