Fatal error with managed custom groups containing duplicate field names
Overview
I have two custom groups. Each contains a field titled 'Status'. In the database they have the same 'name': 'status'.
I want these groups to be managed entities. So I export both groups using the 'export' command on the 'CustomGroup' entity. I set the export to match on 'name' - this seems the sensible field as users can't change it.
This helpfully exports everything I need: I get a .mdg.php file with each custom groups, their fields, and the fields' option values.
But when I enable the extension on a test machine I get a fatal error because of the duplicate 'name'.
The first field gets created fine, but when creating the second field it erroneously matches on the first one so thinks it exists already, and things go wrong from there.
The fix is to set the 'match' parameter on the managed entity to include the custom group name too:
'match' => [
'name','custom_group_id.name',
],
But you can't do this through the UI. The 'match' option on the CustomGroup Export action doesn't include fields from the CustomField entity (let alone the name).
Reproduction steps
- Create a new extension with the two managed entities from this gist
- Try to enable it
Environment information
- CiviCRM: 5.60
- PHP: 7.4
Comments
I can fix it manually by changing the field names, or by manually adding the custom_group_id.name to the .mgd.php files. But I figure duplicate names are common enough to trip people up, and it was a tough one to debug, so I thought it was worth reporting.