We are importing from a JSON file where not every row has every source field defined in the migration. For example, not all addresses have an "address-line-2" field.
This works perfectly fine - all the nodes are imported correctly, but every time there is a missing source field in the JSON file, it creates an "Undefined Index..." notice from src/Plugin/migrate_plus/data_parser/Json.php line 122. This wasn't really an issue until we set it up to import the migration during cron runs. Then all the notices started showing up on-screen in the site itself, which we don't want.
I was able to get rid of the notices by putting in an "array_key_exists" check (see patch), but I'm not completely convinced that is the best way to go. Any help would be appreciated.
Comment | File | Size | Author |
---|---|---|---|
#7 | migrate_plus-undefined_index_missing_properties-2906264-7.patch | 4.42 KB | SylvainM |
#7 | migrate_plus-undefined_index_missing_properties-2906264-7-test_only.patch | 3.65 KB | SylvainM |
Comments
Comment #2
leewbutler CreditAttribution: leewbutler commentedHaving the same issue however in my JSON the entire array value is missing in certain records - so I had to adjust your patch to check for that scenario as well. The addition of "is_array($field_data)" to the "if" worked. Here's the patch with that adjustment.
Comment #3
heddnI'd appreciate if we could add a unit test or two to test the different scenarios.
Comment #4
arnested CreditAttribution: arnested at Reload commentedI just added this patch and it does what it says on the tin. Thumbs up.
Comment #5
SylvainM CreditAttribution: SylvainM at Axess Open Web Services commentedTest added.
I changed also a line to match coding standards:
must be:
Comment #7
SylvainM CreditAttribution: SylvainM at Axess Open Web Services commentedFile name for test changed.
Comment #10
heddnNit: Typically I see single quotes (') not double. That an whitespace I fixed on commit. Thanks for all your contributions!