From d462cb53e285955cf1fdf7596e7644a3324fe9bd Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 29 Mar 2021 14:20:50 +1300 Subject: [PATCH] Update defaults for civicrm_contribution_recur table --- CRM/Contribute/DAO/ContributionRecur.php | 8 +++-- .../Incremental/php/FiveThirtySeven.php | 31 ++++++++++++++++++- xml/schema/Contribute/ContributionRecur.xml | 6 +++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CRM/Contribute/DAO/ContributionRecur.php b/CRM/Contribute/DAO/ContributionRecur.php index 2b9f2f24a6..707afaa176 100644 --- a/CRM/Contribute/DAO/ContributionRecur.php +++ b/CRM/Contribute/DAO/ContributionRecur.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contribute/ContributionRecur.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:f84af6c77cc1e2d93f27952a2a9766fd) + * (GenCodeChecksum:47f389ccf532868b1a41d77c7691912a) */ /** @@ -385,6 +385,7 @@ class CRM_Contribute_DAO_ContributionRecur extends CRM_Core_DAO { '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', @@ -416,6 +417,7 @@ class CRM_Contribute_DAO_ContributionRecur extends CRM_Core_DAO { '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', @@ -434,6 +436,7 @@ class CRM_Contribute_DAO_ContributionRecur extends CRM_Core_DAO { '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', @@ -451,6 +454,7 @@ class CRM_Contribute_DAO_ContributionRecur extends CRM_Core_DAO { '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', @@ -587,7 +591,7 @@ class CRM_Contribute_DAO_ContributionRecur extends CRM_Core_DAO { 'import' => TRUE, 'where' => 'civicrm_contribution_recur.contribution_status_id', 'export' => TRUE, - 'default' => '1', + 'default' => '2', 'table_name' => 'civicrm_contribution_recur', 'entity' => 'ContributionRecur', 'bao' => 'CRM_Contribute_BAO_ContributionRecur', diff --git a/CRM/Upgrade/Incremental/php/FiveThirtySeven.php b/CRM/Upgrade/Incremental/php/FiveThirtySeven.php index 1114ebb36c..cca8c19aba 100644 --- a/CRM/Upgrade/Incremental/php/FiveThirtySeven.php +++ b/CRM/Upgrade/Incremental/php/FiveThirtySeven.php @@ -67,8 +67,8 @@ class CRM_Upgrade_Incremental_php_FiveThirtySeven extends CRM_Upgrade_Incrementa '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'); } // /** @@ -106,4 +106,33 @@ class CRM_Upgrade_Incremental_php_FiveThirtySeven extends CRM_Upgrade_Incrementa 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.', + 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; + } + } diff --git a/xml/schema/Contribute/ContributionRecur.xml b/xml/schema/Contribute/ContributionRecur.xml index 0d6621d02b..39c5fd7a36 100644 --- a/xml/schema/Contribute/ContributionRecur.xml +++ b/xml/schema/Contribute/ContributionRecur.xml @@ -93,6 +93,7 @@ Interval (number of units) int unsigned true + 1 Number of time units for recurrence of payment. 1.6 @@ -114,6 +115,7 @@ Start Date datetime true + CURRENT_TIMESTAMP The date the first scheduled recurring contribution occurs. 1.6 @@ -128,6 +130,7 @@ Created Date datetime true + CURRENT_TIMESTAMP When this recurring contribution record was created. 1.6 @@ -141,6 +144,7 @@ modified_date Modified Date datetime + CURRENT_TIMESTAMP Last updated date for this record. mostly the last time a payment was received 1.6 @@ -259,7 +263,7 @@ contribution_recur_contribution_status_id Status int unsigned - 1 + 2 true 1.6 -- 2.25.1