-
-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ensure checkbox custom fields on contributions import properly #23246
ensure checkbox custom fields on contributions import properly #23246
Conversation
(Standard links)
|
Nope - no test fails - this adds a test & code looks better but I haven't figured out what implications there could be yet |
$newContribution = CRM_Contribute_BAO_Contribution::create($formatted); | ||
$this->_newContributions[] = $newContribution->id; | ||
|
||
$newContribution = civicrm_api3('contribution', 'update', $formatted); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are using apiv3 the action is still 'create' - api v4 uses 'update' as a preferred action
e7024f4
to
f6fc1b1
Compare
Thanks for looking it over @eileenmcnaughton - I just changed 'update' to 'create' and squashed the commits into just one commit. |
@jmcclelland I've been pondering this PR - the underlying issue is the code is pretty awful so it's hard to know what is going on or what the consequences are. Test cover of this import class turns out to be 'a bit better than I had expected' in This behaviour also seems to be tested to be consistent with the documentation
WHich leads me to the decision to merge as
|
Thanks Eileen!! |
Overview
We've been treating checkboxes differently when importing for a while, but perhaps the need for the different behavior is over? I've included a test and am hoping we have enough test coverage to see a failure if the checkbox exception is still needed somewhere.
Before
When importing a Contribution, that includes a custom field of the the type checkbox in which there is no value of "1", an error is returned.
When testing it's important that you use a custom option set that does not use numeric values - you must use string values.
After
The contribution and custom field is properly imported.
Technical Details
The old code unserialized a comma separated list into an array with the array key set to the option value and the value to the number 1. It expected the proper values to be extracted from the keys.
However, when imported, the values are taken from the array values, not the keys, so it's always "1".
Some tests might not detect a failure here. Suppose you have an option list with the name "Blue" assigned the value 1. You can test this option list and it passes simply because you wanted the value "1" and it just so happens that all values get set to 1.
Comments
I expect some test failures which might suggest this is a bad idea or might suggest that we should fix the code that is failing. I'm really not sure.