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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update defaults for civicrm_contribution_recur table
  • Loading branch information
eileenmcnaughton committed Mar 29, 2021
commit d462cb53e285955cf1fdf7596e7644a3324fe9bd
8 changes: 6 additions & 2 deletions CRM/Contribute/DAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contribute/ContributionRecur.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:f84af6c77cc1e2d93f27952a2a9766fd)
* (GenCodeChecksum:47f389ccf532868b1a41d77c7691912a)
*/

/**
Expand Down Expand Up @@ -385,6 +385,7 @@ public static function &fields() {
'description' => ts('Number of time units for recurrence of payment.'),
'required' => TRUE,
'where' => 'civicrm_contribution_recur.frequency_interval',
'default' => '1',
'table_name' => 'civicrm_contribution_recur',
'entity' => 'ContributionRecur',
'bao' => 'CRM_Contribute_BAO_ContributionRecur',
Expand Down Expand Up @@ -416,6 +417,7 @@ public static function &fields() {
'description' => ts('The date the first scheduled recurring contribution occurs.'),
'required' => TRUE,
'where' => 'civicrm_contribution_recur.start_date',
'default' => 'CURRENT_TIMESTAMP',
'table_name' => 'civicrm_contribution_recur',
'entity' => 'ContributionRecur',
'bao' => 'CRM_Contribute_BAO_ContributionRecur',
Expand All @@ -434,6 +436,7 @@ public static function &fields() {
'description' => ts('When this recurring contribution record was created.'),
'required' => TRUE,
'where' => 'civicrm_contribution_recur.create_date',
'default' => 'CURRENT_TIMESTAMP',
'table_name' => 'civicrm_contribution_recur',
'entity' => 'ContributionRecur',
'bao' => 'CRM_Contribute_BAO_ContributionRecur',
Expand All @@ -451,6 +454,7 @@ public static function &fields() {
'title' => ts('Modified Date'),
'description' => ts('Last updated date for this record. mostly the last time a payment was received'),
'where' => 'civicrm_contribution_recur.modified_date',
'default' => 'CURRENT_TIMESTAMP',
'table_name' => 'civicrm_contribution_recur',
'entity' => 'ContributionRecur',
'bao' => 'CRM_Contribute_BAO_ContributionRecur',
Expand Down Expand Up @@ -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.

'table_name' => 'civicrm_contribution_recur',
'entity' => 'ContributionRecur',
'bao' => 'CRM_Contribute_BAO_ContributionRecur',
Expand Down
31 changes: 30 additions & 1 deletion CRM/Upgrade/Incremental/php/FiveThirtySeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public function upgrade_5_37_alpha1($rev) {
'civicrm_note', 'note_date', "timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date attached to the note'");
$this->addTask('core-issue#2243 - Add created_date to civicrm_note', 'addColumn',
'civicrm_note', 'created_date', "timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When the note was created'");

$this->addTask('core-issue#2243 - Update existing note_date and created_date', 'updateNoteDates');
$this->addTask('core-issue#2487 Add / alter defaults for civicrm_contribution_recur', 'updateDBDefaultsForContributionRecur');
}

// /**
Expand Down Expand Up @@ -106,4 +106,33 @@ public static function alterSavedSearchFK(CRM_Queue_TaskContext $ctx) {
return TRUE;
}

/**
* Update DB defaults for contribution recur.
*
* This adds default values for start_date, create_date, modified_date
* and frequency_interval in line with what is in the UI (frequency_unit
* already has 'month' as the default.
*
* The default of 'Pending' for contribution_recur_id will be updated as
* appropriate as soon as a contribution is attached to it by BAO code.
*
* The core code does not rely on the defaults for any of these fields.
*
* @param \CRM_Queue_TaskContext $ctx
*
* @return bool
*/
public static function updateDBDefaultsForContributionRecur(CRM_Queue_TaskContext $ctx): bool {
$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

MODIFY COLUMN `create_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When this recurring contribution record was created.',
MODIFY COLUMN `modified_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Last updated date for this record. mostly the last time a payment was received',
MODIFY COLUMN `contribution_status_id` int(10) unsigned DEFAULT {$pendingID},
MODIFY COLUMN `frequency_interval` int(10) unsigned NOT NULL DEFAULT 1 COMMENT 'Number of time units for recurrence of payment.';
");
return TRUE;
}

}
6 changes: 5 additions & 1 deletion xml/schema/Contribute/ContributionRecur.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<title>Interval (number of units)</title>
<type>int unsigned</type>
<required>true</required>
<default>1</default>
<comment>Number of time units for recurrence of payment.</comment>
<add>1.6</add>
<html>
Expand All @@ -114,6 +115,7 @@
<title>Start Date</title>
<type>datetime</type>
<required>true</required>
<default>CURRENT_TIMESTAMP</default>
<comment>The date the first scheduled recurring contribution occurs.</comment>
<add>1.6</add>
<html>
Expand All @@ -128,6 +130,7 @@
<title>Created Date</title>
<type>datetime</type>
<required>true</required>
<default>CURRENT_TIMESTAMP</default>
<comment>When this recurring contribution record was created.</comment>
<add>1.6</add>
<html>
Expand All @@ -141,6 +144,7 @@
<name>modified_date</name>
<title>Modified Date</title>
<type>datetime</type>
<default>CURRENT_TIMESTAMP</default>
<comment>Last updated date for this record. mostly the last time a payment was received</comment>
<add>1.6</add>
<html>
Expand Down Expand Up @@ -259,7 +263,7 @@
<uniqueName>contribution_recur_contribution_status_id</uniqueName>
<title>Status</title>
<type>int unsigned</type>
<default>1</default>
<default>2</default>
<import>true</import>
<add>1.6</add>
<pseudoconstant>
Expand Down