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

dev/core#1558 [REF] Remove unnecessary query, clean up silly function #16412

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jan 29, 2020

Overview

This simplifies the checkContributeSettings function.

Before

$name parameter is optional & there is handling for it to be null - but it is never not passed in.

$checkInvoicing parameter means a result is only returned if the invoicing setting is also true. However in no case is it a good choice:

  1. from getInvoiceNumber - but it makes more sense to check before calling this function if invoicing is enabled as this saves us calculating $nextContributionID if we don't need it. The other place getInvoiceNumber is called from is the invoice code so we can be comfortable invoicing is enabled & no check is required.

  2. a unit test - where the test is more reliable if we hard code our expected result

  3. an upgrade clause - we are better here to copy the function into the upgrade code because the upgrade wants to deal with the setting as it was for 4.7x users & not 'adapt' as we use a more up to date version of how the setting is stored.

After

checkContributeSettings has one required parameter (name). We check if invoicing is enabled before calling getInvoiceNumber. Upgrade code has it's own copy.

Technical Details

Comments

@civibot
Copy link

civibot bot commented Jan 29, 2020

(Standard links)

@civibot civibot bot added the master label Jan 29, 2020
getInvoiceNumber returns NULL if the 'invoicing' setting is disabled, by checking slightly earlier
we can skip a query if it is not

Upgrade fix: Copy code to upgrade script rather than call a function.

The function will change as we fix the setting but we want the upgrade function to work off the old setting

Test fix: Use hard coded invoicePrefix

We know what it is - if it were not set right then the test would not pick it up because it is comparing
based on the assumption it is - using the string is more reliable
@@ -132,8 +132,7 @@ public function tearDown() {
* @throws \CRM_Core_Exception
*/
public function testGetContribution() {
$contributionSettings = $this->enableTaxAndInvoicing();
$invoice_prefix = CRM_Contribute_BAO_Contribution::checkContributeSettings('invoice_prefix', TRUE);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this incorrectly returned empty then we would be incorrectly checking it was empty - better to test the known value that we set in enableTaxAndInvoicing

@eileenmcnaughton eileenmcnaughton changed the title [REF] Remove unnecessary query, clean up silly function dev/core#1558 [REF] Remove unnecessary query, clean up silly function Jan 29, 2020
@yashodha
Copy link
Contributor

@eileenmcnaughton looks good to me.

@mattwire
Copy link
Contributor

Merging based on @yashodha review

@mattwire mattwire merged commit 4a2eb82 into civicrm:master Jan 29, 2020
@eileenmcnaughton eileenmcnaughton deleted the cont_settings branch January 29, 2020 19:45
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