Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Routh’s picture

Additional information:

This error appears in the dblog at the moment of the index break -

Recoverable fatal error: Argument 2 passed to apachesolr_index_send_to_solr() must be of the type array, null given, called in /home/aw_dev/public_html/sites/all/modules/apachesolr/apachesolr.index.inc on line 47 and defined in apachesolr_index_send_to_solr() (line 303 of /home/aw_dev/public_html/sites/all/modules/apachesolr/apachesolr.index.inc).

eliasbrat’s picture

Hello, Routh
I have same problem.
How did you fix it?

cimo75’s picture

Hi
you can try to run this module

https://drupal.org/project/delete_orphaned_terms

DrCord’s picture

Issue summary: View changes

I don't want to delete terms with no entries, those are still valid. Any other fixes or is this module broken? If you cannot index with it, then what good is it?

rudolfbyker’s picture

Same problem.
Drupal 7.34
apachesolr 7.x-1.7+2-dev
apachesolr_term 7.x-1.x-dev

Here are the error messages (sorry for the combination of Franch and English; this is from a half-translated dev site):
Warning : array_merge(): Argument #2 is not an array dans apachesolr_index_entities_document() (ligne 127 dans .../apachesolr/apachesolr.index.inc).
Warning : array_merge(): Argument #2 is not an array dans apachesolr_index_entities() (ligne 64 dans .../apachesolr/apachesolr.index.inc).
Notice : Undefined property: stdClass::$language dans apachesolr_multilingual_fields_default_indexing_callback_implementation() (ligne 20 dans .../apachesolr_multilingual/apachesolr_multilingual.index.inc).
Warning : array_merge(): Argument #1 is not an array dans apachesolr_index_entities() (ligne 64 dans .../apachesolr/apachesolr.index.inc).
Recoverable fatal error : Argument 2 passed to apachesolr_index_send_to_solr() must be an array, null given, called in .../apachesolr/apachesolr.index.inc on line 67 and defined dans apachesolr_index_send_to_solr() (ligne 340 dans .../apachesolr/apachesolr.index.inc).

There are TODO messages about this in apachesolr.index.inc:
In apachesolr_index_entities (lines 60 through 67):

    $documents = array();
    foreach ($rows as $row) {
      $row_documents = apachesolr_index_entities_document($row, $entity_type, $env_id);
      // TODO argument #1 is not an array
      $documents = array_merge($documents, $row_documents);
    }

    $indexed = apachesolr_index_send_to_solr($env_id, $documents);

In apachesolr_index_entities_document (lines 125 through 128)

    if ($build_document) {
      // TODO argument #2 is not an array
      $documents = array_merge($documents, apachesolr_index_entity_to_documents($row, $env_id));
    }

In apachesolr_index_entity_to_documents, lines 239 through 242, false is returned for empty entities:

  if (empty($entity)) {
    // If the object failed to load, just stop.
    return FALSE;
  }

So two things need to happen:

  1. Check for case where FALSE is returned, and don't pass FALSE to array_merge:
    So in apachesolr_index_entities_document:
        if ($build_document) {
          $new_documents = apachesolr_index_entity_to_documents($row, $env_id);
          if (is_array($new_documents)) {
            $documents = array_merge($documents, apachesolr_index_entity_to_documents($row, $env_id));
          }
        }
    
  2. Find out why the entity did not load... Somehow a non-existent taxonomy term id is passed in the $item variable at one or two of the calls to apachesolr_index_entity_to_documents.
rudolfbyker’s picture

Title: "An error occurred while processing apachesolr_index_batch_index_entities with arguments: apachesolr_index_batch_index_entities" » Argument is not an array
Project: Apachesolr Term » Apache Solr Search
Priority: Critical » Major
Status: Active » Needs review
stone_d’s picture

Same here:

Recoverable fatal error: Argument 2 passed to apachesolr_index_send_to_solr() must be an array, null given, called in /var/www/virtual/xxxxx.de/htdocs/sites/all/modules/apachesolr/apachesolr.index.inc on line 47 and defined in apachesolr_index_send_to_solr() (Zeile 332 von /var/www/virtual/xxxxx.de/htdocs/sites/all/modules/apachesolr/apachesolr.index.inc).

Any suggestions?

aghawkins’s picture

Any word on this?

rudolfbyker’s picture

Status: Needs review » Active

The fix that I proposed above only supresses half of the errors... On line 20 in apachesolr_multilingual.index.inc, it is assumed that the $entity stdClass will have a language property. However, taxonomy terms do not have that property. We could change line 20 to:
if (isset($entity->language) && ... && ... ) {
I'm not sure what this will do, but it does get rid of the errors. Marking this as active, because somebody that knows the apachesolr code better should propose a proper fix. Unfortunately I don't have time to study the ins and outs of apachesolr_term and apachesolr_multilingual modules.

botris’s picture

Status: Active » Needs review
FileSize
1.43 KB

You can't pass array_merge a null value, but you can pass an empty array.
So you can change the code from:

$documents = array_merge($documents, $row_documents);

to

$documents = array_merge((array)$documents, (array)$row_documents);

This solves the problem for me.

botris’s picture

Status: Needs review » Active

No still not working with taxonomy terms. Although #5 also doesn't work with taxonomy (at least for me) it's the better way to go.

AndyThornton’s picture

as fmr says in #5, it seems like a fix will involve handling the return of false from apachesolr_index_entity_to_documents. worryingly, in that function if false is returned the restoring of the user from anonymous and the saving of the session doesnt happen ... that doesnt smell right ... although, that is a different bug, i guess.

i have a very good way of reproducing this error, if anyone finds it useful. i am using apachesolr_term and termstatus (to provide a published/unpublished option for terms). if you unpublish a term and then index your content it will break (becasue apachesolr_term doesnt know about the unpublished flag introduced by termstatus).

Nebel54’s picture

I packed the changes from #5 into this patch and added some logging to find out which entities cause the null value.

nikus85’s picture

Version 1.10, the problem persists.

I have an additional module which denies access to particular taxonomy terms from viewing by anonymous user. This one is called 'Taxonomy Term Status' (termstatus) which allows a term not to be published while its content (nodes attached) is being maintained by editors. As shown in #5, function apachesolr_index_entity_to_documents occasionally returns FALSE in such a case, while it should return an empty array: array(), thus not breaking array_merge and other caller's code.

After publishing of the hidden term, it is re-indexed on the next cron rum (within a minute), so its content os available to the public as by a link provided, so by a searching for keywords. If the term is unpublished again, it is also re-indexed and empty array() make the search to return no results to the term as designed.

This can happen with any other module or custom code which denies access to any taxonomy term from the public.

So bugfix is simple: just replace FALSE with array() in apachesolr_index_entity_to_documents.

Sara.Ali’s picture

Created a patch for the suggestion in #14. It fixes the issue for me when using version 1.10.

Sara.Ali’s picture

Created a patch for the suggestion in #14. It fixes the issue for me when using version 1.10.

https://www.drupal.org/files/issues/2018-07-25/argument_is_not_an_array-...

hitfactory’s picture

Status: Active » Needs review
FileSize
1.25 KB

Confirming the patch in #15 resolves the issue. Thanks @Sara.Ali.

Attaching re-roll of #15 patch so it applies to latest version.

rudolfbyker’s picture

In response to #12 @AndyThornton: See https://www.drupal.org/project/apachesolr/issues/2333213

rudolfbyker’s picture

IMHO these two issues ( https://www.drupal.org/project/apachesolr/issues/2333213 and https://www.drupal.org/project/apachesolr/issues/1957072 ) cannot be separated, since the patch in #17, although it solves the problem in some circumstances, still leaves an annoying bug where admin users get logged out when trying to index content manually.

Here is a patch that solves this issue WITHOUT logging out the user. :)

rudolfbyker’s picture

Oops, ignore my previous patch. Use this one. I had the ternary operator swapped around.

rudolfbyker’s picture

Apparently PHPLint doesn't like new-style arrays [] (a shame, in my opinion), so here is a patch with old-style arrays array().

rudolfbyker’s picture

Status: Needs review » Reviewed & tested by the community

I've been using the last patch for over 2 years on three different production sites, without problem. I think that's enough review :)

  • japerry committed d2f6f27 on 7.x-1.x authored by Sara.Ali
    Issue #1957072 by rudolfbyker, botris, Sara.Ali, hitfactory, Nebel54:...
japerry’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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