I'm attaching a patch to fix various undefined index notices in apachesolr.module

I haven't looked in to why these are happening, or if they have knock on issues, but its generally good practice to check if an array key isset before checking its value. i.e.

if (isset($array['key']) && $array['key']) {
// do something
}

Comments

nick_vh’s picture

I tried it out and I did not see any notice disappear nor appear.
Could you please add a working prototype example (written as in content type with certain field) or a screenshot to make sure we don't add unneeded code?

nick_vh’s picture

Status: Needs review » Needs work

Marking as needs work

josh waihi’s picture

Status: Needs work » Reviewed & tested by the community

Works for me! Here are the logs I am currently getting:

 178402  30/Sep 15:16  notice    php   Notice: Undefined index: multiple in apachesolr_index_key() (line 1517 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).          
 178403  30/Sep 15:16  notice    php   Notice: Undefined index: name_callback in apachesolr_entity_fields() (line 1619 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module). 
 178404  30/Sep 15:16  notice    php   Notice: Undefined index: index_type in apachesolr_index_key() (line 1461 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).        
 178405  30/Sep 15:16  notice    php   Notice: Undefined index: multiple in apachesolr_index_key() (line 1517 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).                    
 178406  30/Sep 15:16  notice    php   Notice: Undefined index: name_callback in apachesolr_entity_fields() (line 1619 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module). 
 178407  30/Sep 15:16  notice    php   Notice: Undefined index: index_type in apachesolr_index_key() (line 1461 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).        
 178408  30/Sep 15:16  notice    php   Notice: Undefined index: multiple in apachesolr_index_key() (line 1517 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).                    
 178409  30/Sep 15:16  notice    php   Notice: Undefined index: facets in apachesolr_facetapi_facet_info() (line 269 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).   
 178410  30/Sep 15:16  notice    php   Notice: Undefined index: facets in apachesolr_facetapi_facet_info() (line 269 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).   
 178411  30/Sep 15:16  notice    php   Notice: Undefined index: facets in apachesolr_facetapi_facet_info() (line 269 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).   
 178412  30/Sep 15:16  notice    php   Notice: Undefined index: facets in apachesolr_facetapi_facet_info() (line 269 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).   
 178413  30/Sep 15:16  notice    php   Notice: Undefined index: facets in apachesolr_facetapi_facet_info() (line 269 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).

This patch fixes all but this one for me:

 178406  30/Sep 15:16  notice    php   Notice: Undefined index: name_callback in apachesolr_entity_fields() (line 1619 of /var/www/drupal/sites/all/modules/contrib/apachesolr/apachesolr.module).
lazysoundsystem’s picture

Here's the patch again with an extra check for the remaining error.

Nick_vh - the errors appear if php E_NOTICE errors are turned on (http://randyfay.com/node/76).

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

For this case, you should use empty(), not isset().

e.g.:

-      if ($field_info['facets']) {
+      if (!empty($field_info['facets'])) {

empty() returns TRUE is the variable is not set (or is 0 or FALSE or '' or array()).

lazysoundsystem’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.81 KB

Edit: missed pwolanin's last comment - rewriting patch now - skip this patch for comment 8.

lazysoundsystem’s picture

Here it is with pwolanin's improvement included. Thanks! - skip this patch too for comment 8.

lazysoundsystem’s picture

Status: Needs work » Needs review
StatusFileSize
new1.78 KB

Sorry, one more time with error removed.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

The same pattern using empty() should be applied to all 3 hunks.

elianm’s picture

This worked for me too!
I was getting "Notice: Undefined index: facets in apachesolr_facetapi_facet_info() (line 269 of..."

Thanks a lot.

lazysoundsystem’s picture

Status: Needs work » Needs review
StatusFileSize
new1.79 KB

Sorry, Peter, and thanks for your patience, it was that sort of day.

Here's the patch again, for - hopefully - the final time...

nick_vh’s picture

Status: Needs review » Reviewed & tested by the community

Looking good, marking as reviewed and tested :)

nick_vh’s picture

just for your info, the patch you submitted failed to apply somehow.
Included is a patch that works. I'd guess the problem was in the filename so please review your patch creation process :)

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

Need to change all 3 spots to just test empty()

pwolanin’s picture

to clarify: the ternary is overly complex

  $sm = (!empty($field['multiple']) && $field['multiple']) ? 'm_' : 's_';

can be written as:

  $sm = empty($field['multiple']) ? 's_' : 'm_';
jweowu’s picture

Re-rolling to fix issue from #15, and upper-case the constants as per coding standards.

jweowu’s picture

Actually, there was some other slight untidiness in that patch. Revised version attached.

pwolanin’s picture

Status: Needs work » Needs review
pwolanin’s picture

Version: 7.x-1.0-beta8 » 7.x-1.x-dev
Status: Needs review » Fixed

thanks

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.