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

APIv4 - Don't automatically set domain. #16911

Closed
wants to merge 4 commits into from

Conversation

colemanw
Copy link
Member

Overview

In 60142ef this field was set to be handled automatically across all entities, however this caused problems with entities like optionValue where it can be NULL.
So setting a default needs to be the job of the BAO.

Before

In all api4 entities, domain_id field not required and given default value.

After

In all api4 entities, domain_id field not required but not given default value.
The underlying BAO create function can do that.

Comments

Most BAO create functions already set this default, so it should be fine.

In 60142ef this field was set to be handled automatically across all entities,
however this caused problems with entities like optionValue where it can be NULL.
So setting a default needs to be the job of the BAO.
@civibot
Copy link

civibot bot commented Mar 26, 2020

(Standard links)

@@ -31,7 +31,7 @@ class FieldDomainIdSpecProvider implements Generic\SpecProviderInterface {
public function modifySpec(RequestSpec $spec) {
$domainIdField = $spec->getFieldByName('domain_id');
if ($domainIdField) {
$domainIdField->setRequired(FALSE)->setDefaultValue('current_domain');;
Copy link
Member Author

Choose a reason for hiding this comment

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

Funny that our linter doesn't catch ;;

@seamuslee001
Copy link
Contributor

@colemanw I think the test fail relates here

@colemanw
Copy link
Member Author

@seamuslee001 I fixed it by adding a default domain to the MailSettings BAO create. Then I noticed a faulty assumption in the code and fixed that too.

}

//handle is_default.
if (!empty($params['is_default'])) {
$domain = $params['domain_id'] ?? CRM_Core_DAO::getFieldValue(__CLASS__, $params['id'], 'domain_id');
Copy link
Member Author

Choose a reason for hiding this comment

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

We can get away with assuming $params['id'] is set here because the latter half of this ?? expression is only reachable if domain_id is not set, and that can only happen if $params['id'] is not empty per above.

@eileenmcnaughton
Copy link
Contributor

@colemanw nope - tests not happy

@colemanw
Copy link
Member Author

@eileenmcnaughton @seamuslee001 this PR feels like it's getting out of hand with all the BAO adjustments. Here's a possibly simpler alternative if it works: #16917

@seamuslee001
Copy link
Contributor

closing in favour of #16917

@colemanw colemanw deleted the domainId branch April 2, 2020 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants