I got an error ”Invalid argument for foreach on entity.inc, line 199” when my import tried to throw a FieldValidationException with the following $e->error content:

array(1) {
  ["default"]=>
  array(1) {
    [0]=>
    array(2) {
      ["error"]=>
      string(17) "og_invalid_entity"
      ["message"]=>
      string(46) "The referenced group (node: 34049) is invalid."
    }
  }
}

It seems that the error handling in plugins/destinations/entity.inc assumes that there are a few more nested arrays in the content. The FieldValidationException definition seems to suggest that the value I got is in correct form:

15   * Constructor for FieldValidationException.
  16   *
  17   * @param $errors
  18   *   An array of field validation errors, keyed by field name and
  19   *   delta that contains two keys:
  20   *   - 'error': A machine-readable error code string, prefixed by
  21   *     the field module name. A field widget may use this code to decide
  22   *     how to report the error.
  23   *   - 'message': A human-readable error message such as to be
  24   *     passed to form_error() for the appropriate form element.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ZeiP created an issue. See original summary.

ZeiP’s picture

Attached is a patch with which the error is properly handled. I couldn't find anywhere else (in the module) that the exception should be raised, so I wonder if this is the correct solution or if there's a need for the extra nested arrays in some context.

ZeiP’s picture

Status: Active » Needs review
dltj’s picture

This patch fixed the same problem that I had (”Invalid argument for foreach on entity.inc, line 199”), and my migration into an existing OG now works. This issue's title says, though, that the problem occurs when importing a faulty OG. As far as I know, my Organic Group is fine; does the fact that this error was occurring mean that this is a problem with my Organic Group setup?

r-mo’s picture

Status: Needs review » Reviewed & tested by the community

This patch fixes errors within the catch for field cardinality too. $e->errors in this case:

Array
(
    [field_video_download_product] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [0] => Array
                                (
                                    [error] => field_cardinality
                                    [message] => <em class="placeholder">Download Product</em>: this field cannot hold more than 1 values.
                                )

                        )

                )

        )

)
brockfanning’s picture

This patch worked for me as well. Thank you!

Grayside’s picture

I am encountering the same situation as @dltj in #10: This patch is fixing import of the og reference field. The migrate messages now record the validation error, even though the content seems to be successfully associated with the group entity (in this case a taxonomy term) without a problem.

Given that potentially invalid validation errors are out of scope, this patch seems RTBC to me.

  • pifagor committed ff5f9e0 on 7.x-2.x
    Issue #2806535 by dbt102, krina.addweb: Add_migrate_help. Issue #2811321...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Done

pifagor’s picture

Status: Fixed » Closed (fixed)