Use of `hook_civicrm_managed` causes fatal
Created by: MegaphoneJon
Discussion between Eileen and myself is here.
In short: I have a database where I've already added an OptionValue record to cg_extend_objects
to allow custom fields on ContributionPage records. This causes the GDPR extension to barf on install. I get an "Value already exists in the database" error, and then Civi thinks I need to install the extension's db updates, which throws more errors.
I think the ideal solution is:
- Remove your
gdpr_civicrm_managed
code. - Instead use something like this in
gdpr_civicrm_install
:
civicrm_api3('OptionValue', 'create', [
'label' => ts('Contribution Page'),
'name' => 'civicrm_contribution_page',
'value' => 'ContributionPage',
'option_group_id' => 'cg_extend_objects',
'is_active' => 1,
'version' => 3,
]);
On CiviCRM uninstall, do an API call to CustomGroup.get
to see if there are any CustomGroup records that extend ContributionPage. If not, delete the entry. If yes, do nothing.