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#2487 Update defaults for civicrm_contribution_recur table #19934

Merged
merged 1 commit into from
Apr 7, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Mar 29, 2021

Overview

dev/core#2487 Update defaults for civicrm_contribution_recur table

Per https://lab.civicrm.org/dev/core/-/issues/2487 this brings the api behaviour closer to the UI - providing the same defaults as the UI does

Before

v4 api requires fields for which reasonable defaults could be used. Both apis apply the 'wrong' default for contribution_status_id and as it is not required it is easy to mistakenly create recurring contributions that bypass the code logic to manage status

After

Defaults in line with the UI

Technical Details

This bubbled to the top because of pain around tests for apiv4

Comments

The change of status for contribution_status_id was previously discussed here #19512 - the key thing to note (which was obviously not clear up front) is that the Contribution BAO has code to update the recurring contribution status as contributions are created with contribution_recur_id set

@civibot
Copy link

civibot bot commented Mar 29, 2021

(Standard links)

$pendingID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', 'Pending');
CRM_Core_DAO::executeQuery("
ALTER TABLE `civicrm_contribution_recur`
MODIFY COLUMN `start_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'The date the first scheduled recurring contribution occurs.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these date columns be datetime or timestamps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seamuslee001 I tested & the default works with datetime - which is what they already are. I wanted to leave any type change out of scope

Copy link
Contributor

Choose a reason for hiding this comment

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

I too prefer to have separate PR/issue for changing default value compared to changing the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JoeMurray I did have the PR for that change (linked above) - I closed it to incorporate into this as I felt it had been canvassed & upgrade scripts don't play well as separate PRs

@@ -587,7 +591,7 @@ public static function &fields() {
'import' => TRUE,
'where' => 'civicrm_contribution_recur.contribution_status_id',
'export' => TRUE,
'default' => '1',
'default' => '2',
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be nice to have comment
// ie Pending

Copy link
Member

Choose a reason for hiding this comment

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

Agree it would be nice, but we can't put comments in a generated DAO file.

@colemanw colemanw merged commit 03f3525 into civicrm:master Apr 7, 2021
@colemanw colemanw deleted the recur branch April 7, 2021 01:45
@colemanw
Copy link
Member

colemanw commented Apr 7, 2021

I'm merging as Eileen addressed feedback without any additional pushback, and I think this is better in than out.

@eileenmcnaughton
Copy link
Contributor Author

Thanks @colemanw - one thing I've been mulling over is https://lab.civicrm.org/dev/core/-/issues/2474 & perhaps whether even just adding a try-catch might mitigate the risk of that

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.

4 participants