-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Conversation
(Standard links)
|
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.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -174,6 +174,7 @@ public static function getList($filterMapping = NULL, $filterValue = NULL): arra | |||
* @param array $params | |||
* An assoc array of name/value pairs. | |||
* | |||
* @deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -149,6 +149,7 @@ public function getLocationValues() { | |||
* @param array $params | |||
* @param int $id | |||
* | |||
* @deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -160,6 +161,7 @@ public static function edit($params, $id): CRM_Core_DAO_Domain { | |||
/** | |||
* Create or update domain. | |||
* | |||
* @deprecated |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -26,6 +26,7 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { | |||
* | |||
* @param array $params | |||
* | |||
* @deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | ||
* @return CRM_Pledge_BAO_PledgeBlock | ||
* @deprecated | ||
* @return CRM_Pledge_DAO_PledgeBlock | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | ||
* @return object | ||
* @deprecated | ||
* @return CRM_Pledge_DAO_PledgeBlock | ||
*/ | ||
public static function add($params) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 |
Also - we could probably add a deprecation notice into that apiv3 custom field handling (in a follow up PR) |
@eileenmcnaughton everything that's annotated |
OK - well tests pass so ... |
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-hoccreate
andadd
functions. I've been making an effort to markcreate
andadd
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.