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

Fix problem with group.update api #26260

Merged
merged 2 commits into from
May 29, 2023
Merged

Fix problem with group.update api #26260

merged 2 commits into from
May 29, 2023

Conversation

samuelsov
Copy link
Contributor

@samuelsov samuelsov commented May 18, 2023

Overview

Following PR #26200, there are 3 things to fix/improve in CRM_Contact_BAO_Group::update:

  • in the api, the expectation is that if you omit a param then it will not be changed, however the logic is that if we omit $params['parents'] it will be deleted
  • there is nothing preventing adding itself as a parent which causes a recursive loop in CRM_Contact_BAO_GroupNesting::getParentGroupIds
  • we don't need to update group nesting cache for every update that doesn't touch parents

@civibot
Copy link

civibot bot commented May 18, 2023

(Standard links)

CRM/Contact/BAO/Group.php Outdated Show resolved Hide resolved
@samuelsov samuelsov changed the title Problème with group.update api [WIP] Problème with group.update api May 18, 2023
@samuelsov samuelsov changed the title [WIP] Problème with group.update api [WIP] Problem with group.update api May 18, 2023
@colemanw
Copy link
Member

@samuelsov probably just delete line 339?

@samuelsov
Copy link
Contributor Author

@samuelsov probably just delete line 339?

It is converted to an array a bit later in the code so I moved the check to the very beginning of the method.

@@ -384,6 +388,10 @@ public static function create(&$params) {

if (!CRM_Utils_System::isNull($params['parents'])) {
$params['parents'] = CRM_Utils_Array::convertCheckboxFormatToArray((array) $params['parents']);
Copy link
Member

Choose a reason for hiding this comment

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

Refactoring note: not a blocker for this PR, but this function really shouldn't be called from the BAO as it's only needed on the quickform.

CRM/Contact/BAO/Group.php Outdated Show resolved Hide resolved
@colemanw
Copy link
Member

@samuelsov are you able to rebase this into a single commit?

@samuelsov
Copy link
Contributor Author

@colemanw ok, yeah, done (I think). I though you could do it when merging like in gitlab.

@colemanw
Copy link
Member

That would be nice! But our workflow currently requires a merge-commit.

@samuelsov I think the only thing missing here is a unit test. Are you up for that?

@samuelsov
Copy link
Contributor Author

@colemanw yes, hopefully tomorrow :)

@colemanw
Copy link
Member

That would be great thanks @samuelsov

@samuelsov
Copy link
Contributor Author

@colemanw seems good to me, the tests detected an error that I fixed. Can you review ?

@@ -448,7 +456,7 @@ public static function create(&$params) {
}
Copy link
Member

Choose a reason for hiding this comment

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

This block (see above) will actually force in a parents param, so we either need to alter $parentsParamProvided here or else modify the check below for refreshing the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, any preference ? we could also go back to a safer approach where the cache is updated no matter what.

// parent group is removed
CRM_Contact_BAO_GroupNestingCache::update();
// refresh cache if parents param was provided
if ($parentsParamProvided) {
Copy link
Member

Choose a reason for hiding this comment

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

How about this?

Suggested change
if ($parentsParamProvided) {
if ($parentsParamProvided || !empty($params['parents'])) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok done. It may be useful to add some unit tests to check the group nesting cache although not sure I'm the good person for that.

@colemanw colemanw changed the title [WIP] Problem with group.update api Fix problem with group.update api May 29, 2023
@colemanw colemanw merged commit 85b3d15 into civicrm:master May 29, 2023
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.

2 participants