upgrade to 5.21.2 leads to deletion of custom fields (and data) defined in extensions via *.mgd.php files
This issues seems closely related to #1460 (closed) but is a more urgent variant so I thought it deserved a separate issue.
I have several extensions that provide custom data fields via *.mgd.php files.
The "cleanup" is set to "always" because, when the extension is deleted, I want the custom data to be deleted. That way people can try out the extension and if they don't like it, they can cleanly remove it and everything it created.
However we have a problem during upgrade:
- While in upgrade mode, at the end of the process,
CRM_Upgrade_Form::doFinish()
callsCRM_Core_ManagedEntities::singleton(TRUE)->reconcile(TRUE);
. -
reconcile
generates a list of managed entities which at some point tries to callhook_civicrm_managed
. - However, since we are in upgrade mode, only certain hooks are called - and
hook_civicrm_managed
is not one of them. -
reconcile
then compares the list of managed items in the database (which specifies the custom data fields that my extensions have defined and all have set thecleanup
field 'always') with the list of managed entities defined by the the code base (which is none - becausehook_civicrm_managed
didn't run) and... - Poof! All those custom fields are deleted along with all their data and option lists.
We didn't notice the data loss at first, so then had to re-construct the missing data which was quite tedious.
I see from #1460 (closed) that we are trying to leave out hook_civicrm_managed
because of some trouble with entities of the type PaymentProcessorType but, it seems that calling reconcile without hook_civicrm_managed
is always going to cause problems.