Just looking through watchdog and saw this:

Warning: Invalid argument supplied for foreach() in apachesolr_attachments_field_attach_update() (line 472 of apachesolr_attachments/apachesolr_attachments.module).

While running cron:
/eng/admin/reports/status/run-cron?destination=admin/modules

Comments

ksavoie’s picture

I can second this issue except it appears within admin on every node save if a 'file' field is empty. If file field is populated then this error does not occur. If node has more than one empty 'file' field it shows that many times.

Warning: Invalid argument supplied for foreach() in apachesolr_attachments_field_attach_update() (line 472 of /var/www/html/mudomaha/sites/all/modules/apachesolr_attachments/apachesolr_attachments.module).

Version 7.x-1.2
PHP 5.3.19
Seems to be working otherwise, indexes uploaded files.

valdo’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

This has been already partially fixed in the 7.x-1.x dev branch:

$items = field_get_items($parent_entity_type, $parent_entity, $field_info['field_name']);
if ($items) {
  foreach ($items as $file_info) {

- the second line is the fix.

But there is also 1 more place like this that needs to be sanitized the same way - the same logic inside apachesolr_attachments_field_attach_delete().

Patch to fix this issue is attached.

solquimpo’s picture

Here's a better patch to get rid of the warnings originating from both apachesolr_attachments_field_attach_update and apachesolr_attachments_field_attach_delete.

solquimpo’s picture

Hmm, something wrong with the previous patch. Attaching another one.

eiriksm’s picture

Status: Needs review » Reviewed & tested by the community

Except there is no new line at end of file, patch looks good to me, and fixes the issue.

This error totally breaks drush migrate imports with file fields, so would really like to see this get commited :)

nick_vh’s picture

Status: Reviewed & tested by the community » Needs work

nickveenhof@Nick-Veenhofs-MacBook-Pro:~/Sites/dev/apachesolrissues/site/sites/all/modules/contrib/apachesolr_attachments$ git apply ~/Sites/dev/patches/apachesolr_attachments_php_warning_fix2.patch
error: patch failed: apachesolr_attachments.module:469
error: apachesolr_attachments.module: patch does not apply

It does not apply? :-/ Please reroll

eiriksm’s picture

Status: Needs work » Reviewed & tested by the community

Hey.

The patch in #4 works for 7.x-1.2. But as valdo states in #2 this issue was partly fixed in -dev. But the patch in #2 applies to -dev and fixes the issue. Sorry I did not make that clear when setting it to RTBC.

nick_vh’s picture

Status: Reviewed & tested by the community » Needs work

That still does not make it apply? Please reroll

valdo’s picture

Nick_vh: I believe this issue can be closed, as there is nothing to fix anymore in the dev branch. It has already been fixed, this is the code I see now in the recent dev branch (7.x-1.x):

File: apachesolr_attachments.module
Line 595:

        $items = field_get_items($parent_entity_type, $parent_entity, $field_info['field_name']);
        if ($items) {

Line 627:

        $items = field_get_items($parent_entity_type, $parent_entity, $field_info['field_name']);
        if(!empty($items)) {

The conditions if ($items) or if(!empty($items)) were the parts that were missing and causing this bug.

I'm not sure whether these fixes were included in the recent release already, but in the dev branch they are fixed.