Open twomice opened 6 months ago
Original discussion in jsumfields
issue queue: https://github.com/twomice/com.joineryhq.jsumfields/issues/25#issuecomment-2005150863
Thanks @twomice legend!
Thanks @twomice for the bug report! sumfields is an old extension and is definitely in need of some love.
I replicated the problem without much trouble. But, I was able to rectify it by simply disabling and then uninstalling sumfields (I received an error about failing to delete the custom field I manually deleted, but it nonetheless completed). Then I enabled and it seems to work properly. However, I have enough experience with sync'ing fields to know that I probably got lucky :).
I think the best and easiest option is to make the custom group "reserved" - that should result in it disappearing from the custom fields page - so nobody will be able to mess with it. I didn't know about that option when I created the extension.
That should be an easy fix (and could apply to existing installs via an upgrade script).
However, even when reserved, there will be times when things get out of sync. I think a second, more involved fix would be to use the civicrm_hook_managed
hook to install, disable and uninstall the custom fields. That hook didn't exist when i wrote sumfields, so I have essentially invented my own bootleg version of it. I suspect it would be less buggy to use the core version instead.
I'm not sure how long it would take me to work on these, but I would welcome a PR from anyone who wants to take a crack at either fix.
@jmcclelland Right, great ideas regarding 'Reserved' and hook_civicrm_managed
!
I don't have a business case for this fix myself, but of course I'm hoping someone does.
Thanks!
Summary:
CiviCRM allows permissioned users to delete custom fields, including those in the Summary Fields group, as well as the Summary Fields custom field group itself.
If this happens, triggers that reference those deleted custom fields will cause fatal errors, which will cause related actions in CiviCRM to fail as well. E.g., cannot record a contribution if "Total Lifetime Contributions" Summary Field is a) enabled, and b) has had its custom field deleted by a site admin.
(Disclaimer: Naturally, nobody should be deleting these custom fields, but they can and sometimes do.)
Repro steps:
Failed attemps to workaround:
I was hopeful that this situation could be resolved by doing one or more of the following:
However, these steps don't resolve the problem, and indeed some of them (re-anabling Summary Fields after uninstalling it) are not possible because of fatal errors due to the missing custom fields/group.
Actual tedious workaround:
Suggestions for improvement in sumfields extension:
Some ways this extension might deal with the problem of admin users deleting Summary Fields custom fields/group might be: