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

EntityFinancialAccount - A tale of two BAO classes #25036

Merged
merged 2 commits into from
Nov 23, 2022

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Nov 23, 2022

Overview

This BAO class did not follow the standard naming convention. Why was never explained, I suspect it was simply a mistake. Then last year a new BAO was added that is correctly named, but without dealing with the existing one.
This moves all BAO code into the one with the correct name, and aliases the other.

Technical Details

The nonstandard name effectively made it invisible to the API so the create and del functions were never used by the API. For consistency, I've therefore tagged them as @deprecated which keeps them hidden from the API. We can add business logic back in as needed using hook listeners. @aydun has started work on that in #25026.

Comments

#19927 introduced that extra BAO class. CC @eileenmcnaughton and also the guy who merged it.

@civibot
Copy link

civibot bot commented Nov 23, 2022

(Standard links)

@civibot civibot bot added the master label Nov 23, 2022
…ityFinancialAccount

This BAO class did not follow the standard naming convention which effectively made it invisible to the API.
Why was named this way in the first place was never explained, I suspect it was simply a mistake.

A BAO class actually did get added before this PR, in 37c608f which further added to the confusion.
This consolidates the two classes.

Because it was an "invisible" BAO class, the create and del functions were never used by the API.
For consistency, I've therefore tagged them as @deprecated which keeps them hidden from the API.
We can add business logic back in as needed using hook listeners.
This follows the same pattern as the create action - to only use BAO methods if they are not @deprecated.
Note that APIv4 already does this in the DAODeleteAction class.
@eileenmcnaughton
Copy link
Contributor

You have to remove those redirects in favour of exceptions to get the tests to pass ( I think you can just do it - it's such an obscure entity that if the forms get fusty about it it probably won't be noticed for years)

CRM_Contribute_Form_ContributionTest::testPremiumUpdate
Failure in api call for EntityFinancialAccount delete: civiExit called
#0 /home/jenkins/bknix-dfl/build/core-25036-32kxl/web/sites/all/modules/civicrm/CRM/Utils/System.php(561): CRM_Utils_System::civiExit(0, Array)
#1 /home/jenkins/bknix-dfl/build/core-25036-32kxl/web/sites/all/modules/civicrm/CRM/Financial/BAO/EntityFinancialAccount.php(122): CRM_Utils_System::redirect('/index.php?q=ci...')
#2 /home/jenkins/bknix-dfl/build/core-25036-32kxl/web/sites/all/modules/civicrm/api/v3/utils.php(1403): CRM_Financial_BAO_EntityFinancialAccount::del('27')
#3 /home/jenkins/bknix-dfl/build/core-25036-32kxl/web/sites/all/modules/civicrm/api/v3/EntityFinancialAccount.php(59): _civicrm_api3_basic_delete('CRM_Financial_B...', Array)
#4 /home/jenkins/bknix-dfl/build/core-25036-

@colemanw colemanw force-pushed the renameFinancialTypeAccount branch from eee94c9 to bb33fc6 Compare November 23, 2022 20:22
@@ -1395,7 +1395,7 @@ function _civicrm_api3_basic_create_fallback($bao_name, $params) {
function _civicrm_api3_basic_delete($bao_name, &$params) {
civicrm_api3_verify_mandatory($params, NULL, ['id']);
_civicrm_api3_check_edit_permissions($bao_name, ['id' => $params['id']]);
if (method_exists($bao_name, 'del')) {
if (method_exists($bao_name, 'del') && !\Civi\Api4\Utils\ReflectionUtils::isMethodDeprecated($bao_name, 'del')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this alter other v3 api delete calls - in possibly unpredictable ways?

Copy link
Contributor

@eileenmcnaughton eileenmcnaughton Nov 23, 2022

Choose a reason for hiding this comment

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

(also - can we use a use ) - at least if you make further updates

Copy link
Member Author

@colemanw colemanw Nov 23, 2022

Choose a reason for hiding this comment

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

Yes, but I like to think that it will do so in predictable ways. 😁

As @aydun and I have been systematically deprecating BAO::del() functions, we've made them functionally identical to the base method deleteRecord() (in fact gutted them each to one line calling that method), so switching the API from one to the other should have no impact. And APIv4 has already made that switch. Let's see what the tests think about my prediction...

Copy link
Contributor

Choose a reason for hiding this comment

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

OK - I'll let the tests decide

Copy link
Member Author

@colemanw colemanw Nov 23, 2022

Choose a reason for hiding this comment

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

Re a "use" statement. That makes me a little nervous (maybe unjustifiably so I think it's justified because the file itself sets up the classloader and that would happen after a use statement was evaluated) because api/v3/utils.php is not a class and is not in a namespace and gets included from random places that might crash if the require_once "api/v3/utils.php" gets called before our classloader is active.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm ok

@eileenmcnaughton eileenmcnaughton merged commit 19a207f into civicrm:master Nov 23, 2022
@eileenmcnaughton eileenmcnaughton deleted the renameFinancialTypeAccount branch November 23, 2022 22:07
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.

2 participants