I've set up an LDAP query that is tested and works. But when I try to create a View (using the simplest of default settings), my page gives this error:

Fatal error: Unsupported operand types in /Users/brad.garrett/htdocs/ep/employees/sites/all/modules/ldap/ldap_views/plugins/ldap_views_plugin_query_ldap.inc on line 241

Line 241 begins with "$num_entries" in the following code block.

    if ($result !== FALSE) { // not an error
        $entries = array_merge($entries, $result);
        $num_entries += array_shift($result);
      }
    }

Any idea what could be going wrong?

Comments

bradezone’s picture

Okay, after looking at this, when I debug the $result array, my "count" parameter is the last element of the array. Therefore if I use "array_pop" instead of "array_shift" it works -- is there a way to force the count to be the first element, or is this somehow set by the LDAP server itself?

bradezone’s picture

Actually when I deployed this on a server, the "count" WAS the first array element. So a better fix is as follows. It might be easier for you to add this fix to the repo, since it's pretty tiny:

    if ($result !== FALSE) { // not an error
        $entries = array_merge($entries, $result);
        $num_entries += $result['count'];
        unset($result['count']);
      }
    }
haydeniv’s picture

StatusFileSize
new643 bytes

I haven't tested this at all but do we even want count in the entries? Maybe:

    if ($result !== FALSE) { // not an error
        $num_entries += $result['count'];
        unset($result['count']);
        $entries = array_merge($entries, $result);
      }
    }

would be better. I'm not sure because I don't use ldap_views. Regardless here is a patch with your suggestion in #2

kenorb’s picture

Status: Active » Needs review
johnbarclay’s picture

Version: 7.x-2.0-beta8 » 7.x-2.x-dev
zxaos’s picture

The good news is that #3 resolves the issue.

The even better news is that #3 also resolves an issue where ldap views could not filter properly ( related to https://www.drupal.org/node/2216843 ? )

zxaos’s picture

StatusFileSize
new2.99 KB

On further testing, there's some additional places where the same assumption is made that count is at a particular array position.

Here's an updated patch that includes the previous changes as well as trying to make other references to count array-position agnostic.

grahl’s picture

Status: Needs review » Needs work
grahl’s picture

Status: Needs work » Needs review
grahl’s picture

Anyone else using this patch successfully?

catapipper’s picture

Seems to be working fine for me.

  • grahl committed dd8bb37 on 7.x-2.x authored by zxaos
    Issue #2291905 by zxaos, haydeniv: LDAP Views: "Unsupported operand...
grahl’s picture

Status: Needs review » Fixed

Thank you for the patch and feedback, committed.

What I can't tell from that patch is whether there ever could be a case where $result if not exactly false but does not contain count. I'm presuming this isn't an issue based on the feedback. Even if it where, not relying in the cryptic array shifting is clearly a far superior solution and should be used instead of it.

Status: Fixed » Closed (fixed)

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