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] Replace create with writeRecord in Group #31095

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Sep 11, 2024

Overview

In order to keep BAO CRUD fns cleaner and central to, this patch move all the Create logics (that includes updating related entities, defaulting columns like frontend_title, name etc, rebuilding cache if parent groups are added/updated etc. ) onto pre and post hook. And so that we can avoid using deprecated CRM_Contact_BAO_Group::create and use DAO::writeRecord instead.

Before

CRM_Contact_BAO_Group::create with additional logics before and after writing record.

After

Move all the additional logics on to pre/post hook and call writeRecord for ...... obviously writing record only.

Comments

ping @colemanw @eileenmcnaughton @seamuslee001

Copy link

civibot bot commented Sep 11, 2024

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the master label Sep 11, 2024
@colemanw
Copy link
Member

@monishdeb this looks good, but the CRM_Core_Error::deprecatedFunctionWarning will cause tests to fail (because when tests hit that deprecated warning they mark it as a failure).

So I think we remove the deprecated warning but keep the @deprecated annotation in the docBlock. That annotation gets read by API v3 and v4 and tells them to directly call BAO::writeRecords() instead of BAO::create().

But one more thing. Since we allow the create() function to still be used, I wonder if all the crufty stuff has to be moved. Perhaps some of it is only used by legacy code that calls create() and so can remain in the create() function so we don't port crufty hacks into our nice new writeRecord implementation.

@monishdeb monishdeb force-pushed the replace_create_with_writeRecords branch 6 times, most recently from 193d124 to 224c10e Compare September 12, 2024 04:17
Comment on lines -349 to -355
// Fill title and frontend_title if not supplied
if (empty($params['id']) && empty($params['title'])) {
$params['title'] = $params['frontend_title'] ?? $params['name'];
}
if (empty($params['id']) && empty($params['frontend_title'])) {
$params['frontend_title'] = $params['title'];
}
Copy link
Member

Choose a reason for hiding this comment

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

I see you were able to drop this code due to #31096 😁

Copy link
Member

Choose a reason for hiding this comment

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

However, I think some of the test failures are due to missing fallbacks, so I think we need to add more fallbacks to Group.entityType.php for title and frontend_title

@monishdeb monishdeb force-pushed the replace_create_with_writeRecords branch 2 times, most recently from 2eb51fe to 3f0fcd1 Compare September 14, 2024 10:57
@monishdeb monishdeb force-pushed the replace_create_with_writeRecords branch from 3f0fcd1 to bc91019 Compare September 15, 2024 10:02
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