Skip to content
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

OptionValue - Fix checking if domain is set #22095

Merged
merged 1 commit into from
Nov 18, 2021

Conversation

colemanw
Copy link
Member

Overview

Fixes a bug introduced in #19970 when saving an option value related to a domain

Before

This was causing test failures in #22064

After

Fixed

Technical Details

Similar to the problem in #22089 we need to use CRM_Utils_System::isNull() because the API will pass the string 'null' into BAO functions like this one.

@civibot
Copy link

civibot bot commented Nov 18, 2021

(Standard links)

@civibot civibot bot added the master label Nov 18, 2021
@colemanw
Copy link
Member Author

@demeritcowboy since you merged #22089 would you take a look at this one too? I don't have an idea of how to write a test for it, but without this PR the tests in #22064 all blow up. So maybe that counts as test coverage?

@colemanw
Copy link
Member Author

@demeritcowboy - actually I managed to add test coverage to this PR - the lines I added trigger the bug and will cause the test to fail without this patch.

@@ -192,7 +193,7 @@ public static function add(&$params, $ids = []) {
$p = [1 => [$params['option_group_id'], 'Integer']];

// Limit update by domain of option
$domain = $optionValue->domain_id ?? NULL;
$domain = CRM_Utils_System::isNull($optionValue->domain_id) ? NULL : $optionValue->domain_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused at first thinking this would give an error in the typical situation, where $optionValue->domain_id never gets set and so attempting to reference a non-existent thing, but it's declared as a property in the DAO so works ok. So the previous ?? wasn't really necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto :)

@demeritcowboy demeritcowboy merged commit ced06b3 into civicrm:master Nov 18, 2021
@colemanw colemanw deleted the fixDomainOptionGroup branch November 18, 2021 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants