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

[REF] APIv4 Notes - Ensure child notes are deleted with parent, and hooks are called #21208

Merged
merged 1 commit into from
Aug 23, 2021

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Aug 21, 2021

Overview

Note BAO refactoring related to work on dev/core#2757
Companion to #21204

Before

  • When deleting a parent group via APIv4, child groups would not be deleted.
  • Hooks never called when deleting a note (by any means)

After

  • When deleting a parent group via APIv4, child groups are deleted.
  • Hooks always called when deleting a note (even outside the api)

@civibot
Copy link

civibot bot commented Aug 21, 2021

(Standard links)

$note->id = $id;
$note->find();
$note->fetch();
if ($note->entity_table == 'civicrm_note') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly I would rip out this status stuff & just fix the 4 places that call this to set the status after it is called. The 'comment' part seems like a really long ago feature idea that never amounted to much

@colemanw
Copy link
Member Author

Ok @eileenmcnaughton that was more refactoring that I had planned on given the ever-creeping scope of getting APIv4 delete functions working, but you know I can never resist a good cleanup challenge.

I've refactored out all core uses of CRM_Core_BAO_Note::del() and added a noisy deprecation to it.

@eileenmcnaughton
Copy link
Contributor

Thanks @colemanw - I'll take a look. I just want to prod around the function call a little - I was expecting you would switch to calling apiv4 rather than calling deleteRecord directly. They are functionally the same & the v4 is slightly more verbose so my reasoning was more around modelling consistent behaviour in core forms that we would also hope extension forms would use

@eileenmcnaughton
Copy link
Contributor

That deprecation is a bit much for the tests

api\v4\Entity\NoteTest::testDeleteWithChildren
Deprecated function CRM_Core_BAO_Note::del, use deleteRecord.

/home/jenkins/bknix-dfl/build/core-21208-7ccy4/web/sites/all/modules/civicrm/CRM/Core/Error.php:1044
/home/jenkins/bknix-dfl/build/core-21208-7ccy4/web/sites/all/modules/civicrm/CRM/Core/BAO/Note.php:297

@colemanw
Copy link
Member Author

Oh that's interesting. Looks like APIv4 does call BAO::del() methods after all.

So the reason for the original problem in dev/core#2757 is simply that the Contact BAO doesn't have a method with that name.

Ok I'm going to put up another PR for that in a minute. I'll revert the noisy deprecation from this one to make it mergeable.

…called

Deprecates the CRM_Core_BAO_Note::del() function and refactors out all references to it.
Related to work on dev/core#2757
@colemanw
Copy link
Member Author

@eileenmcnaughton want to give this one MOP?

@eileenmcnaughton
Copy link
Contributor

@colemanw I'm happy to leave changing it out of scope for this PR - but did you have a response about what syntax we should be modelling - ie calling the v4 api vs by-passing it?

I worry about extension writers copying tendencies hence I prefer we try to use the v4 api as best practice - but you might disagree?

@colemanw
Copy link
Member Author

I don't have strong feelings about it, but we should document that Extensions should always use the API, and never treat core BAO code as an example to be emulated 😝

@eileenmcnaughton
Copy link
Contributor

@colemanw yeah - but in reality? I think they look to core code & copy & paste. Anyway I won't hold this up on that but I do think we should write core code as if it's being copied

@seamuslee001 seamuslee001 merged commit d459353 into civicrm:master Aug 23, 2021
@seamuslee001 seamuslee001 deleted the refNotes branch August 23, 2021 23:07
@colemanw
Copy link
Member Author

@eileenmcnaughton I guess so. I feel ambivalent about calling the API layer from the BAO layer because that feels like going from low to high when the normal flow is high to low. We wouldn't ever e.g. want to call the create api from a BAO::create function because the api then calls the BAO function and we have an infinite loop. With form and page code however I think it's fine.

@eileenmcnaughton
Copy link
Contributor

@colemanw yeah - but we routinely call OTHER create api from withing BAO creates - you are talking about a case where the function is calling itself - which is where we wind up using lower level functions like direct dao or direct sql

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.

3 participants