eileenmcnaughton / nz.co.fuzion.csvimport

Import to API using csv GUI
GNU Affero General Public License v3.0
8 stars 27 forks source link

Fix address import on PHP 8 #63

Closed omarabuhussein closed 1 year ago

omarabuhussein commented 1 year ago

Before

Unable to import addresses on PHP 8 sites, where it fails on the fields mapping page:

1111111

After

address import works fine

22222

image

Technical notes

The address external_identifier is a special case field and not part of the address entity, : https://github.com/omarabuhussein/nz.co.fuzion.csvimport/blob/e5f0c93d02c81b29406527e88ebb996dd3abc8c3/CRM/Csvimport/Import/Parser/Api.php#L269

but the getReferenceFields method uses the API getfields action to get the Address entity fields meta data, then tries to to look for the external_identifier in there and then it tires to merge it with some other meta data (using array_merge) : https://github.com/omarabuhussein/nz.co.fuzion.csvimport/blob/e5f0c93d02c81b29406527e88ebb996dd3abc8c3/CRM/Csvimport/Import/Parser/Api.php#L135-L142

but because external_identifier is not available inside the response coming from getfields API call on the address entity (given it is not part of the Address entity), the first argument to the array_merge will be NULL, which on PHP 7 sites will just throw a warning, but on PHP 8 sites it fails with the following error:

array_merge(): Argument #1 must be of type array, null given in array_merge() (line 126 of /var/www/default/htdocs/httpdocs/profiles/devprofile/modules/contrib/civicrm/ext/nz.co.fuzion.csvimport/CRM/Csvimport/Import/Parser/Api.php)