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

API - Consistently save custom data for v3 & v4 #24036

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Jul 21, 2022

Overview

Fixes dev/core#3747

Before

Mailing custom fields saved for v3 but not v4.

After

Works for both, plus more cleanup.

Technical Details

APIv3 has a fallback for saving custom data in the API layer if the BAO doesn't handle it. APIv4 does not, and relies on the BAO to always work. So we really need to get our BAOs consistently saving custom data. The best way to do that is for them to use writeRecord instead of ad-hoc create and add functions. I've been making an effort to mark create and add functions @deprecated which triggers the API to ignore them.

Comments

Ideally we should remove custom data handling from v3 but this PR doesn't go quite that far.

@civibot
Copy link

civibot bot commented Jul 21, 2022

(Standard links)

@civibot civibot bot added the master label Jul 21, 2022
Fixes dev/core#3747
It's confusing to handle saving custom data in the APIv3 layer,
because APIv4 expects the BAO to handle it.

Until every BAO consistently uses WriteRecord this will continue to be a pain point.
@jensschuppe
Copy link
Contributor

I can confirm this fixes the issue for Mailing entities - didn't test any other scenario than described in the issue though.

@@ -35,6 +35,7 @@ public static function entityTables(): array {
/**
* @param array $params
*
* @deprecated
* @return CRM_ACL_BAO_ACLEntityRole
*/
public static function create(&$params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

OK - already calls writeRecord
image

@@ -174,6 +174,7 @@ public static function getList($filterMapping = NULL, $filterValue = NULL): arra
* @param array $params
* An assoc array of name/value pairs.
*
* @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

OK
image

@@ -149,6 +149,7 @@ public function getLocationValues() {
* @param array $params
* @param int $id
*
* @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

image

@@ -160,6 +161,7 @@ public static function edit($params, $id): CRM_Core_DAO_Domain {
/**
* Create or update domain.
*
* @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

OK - not called from api anyway

@@ -144,6 +144,7 @@ public static function setStatus($status) {
/**
* Create or update a RecurringEntity.
*
* @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

ok

image

@@ -26,6 +26,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website {
*
* @param array $params
*
* @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

ok
image

@@ -46,7 +45,7 @@ public static function create($params) {
*/
public static function add($params) {
CRM_Core_Error::deprecatedFunctionWarning('use apiv4');
return self::create($params);
return self::writeRecord($params);
Copy link
Contributor

Choose a reason for hiding this comment

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

OK
image

@eileenmcnaughton
Copy link
Contributor

I started eyeballing this & commented where I've checked.

*
* @return CRM_Mailing_DAO_Mailing
* @throws \Civi\API\Exception\UnauthorizedException
*/
public static function add(&$params, $ids = []) {
$id = $params['id'] ?? $ids['mailing_id'] ?? NULL;
public static function add($params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ok - ids was deprecated noisily in year zero (2020)

isset($params['from_email'])
) {
$params['replyto_email'] = $params['from_email'];
}
$mailing->copyValues($params);
Copy link
Contributor

Choose a reason for hiding this comment

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

OK - changes to this function make sense

@@ -19,6 +19,7 @@ class CRM_Member_BAO_MembershipBlock extends CRM_Member_DAO_MembershipBlock {
/**
* Create or update a MembershipBlock.
*
* @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

ok
image

*
* @return CRM_Pledge_BAO_PledgeBlock
* @deprecated
* @return CRM_Pledge_DAO_PledgeBlock
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

OK - this is long but completely lacking in goodness
image

*
* @return object
* @deprecated
* @return CRM_Pledge_DAO_PledgeBlock
*/
public static function add($params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

OK - this has some non-api-worthy horror show but nothing the api needs

image

@eileenmcnaughton
Copy link
Contributor

@colemanw can you explain this bit - https://github.com/civicrm/civicrm-core/pull/24036/files#diff-66c5190e94fdb11fb2c74061a039d80cfe7908cff12cce3a4244021afd57f569R1337-R1356

My read is that anything that calls writeRecord should be in that list - so most of the ones you touched, like MembershipBlock should be in there - but it isn't?

@eileenmcnaughton
Copy link
Contributor

Also - we could probably add a deprecation notice into that apiv3 custom field handling (in a follow up PR)

@colemanw
Copy link
Member Author

@eileenmcnaughton everything that's annotated @deprecated doesn't need to be in the list. The list is just for oddballs that do handle custom data but don't have the annotation.

@eileenmcnaughton
Copy link
Contributor

OK - well tests pass so ...

@eileenmcnaughton eileenmcnaughton merged commit 1c41a31 into civicrm:master Jul 26, 2022
@eileenmcnaughton eileenmcnaughton deleted the v3Custom branch July 26, 2022 14:04
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