From 2f207c15847c607b6c55d3d616a8198f9536a50d Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Thu, 16 Jan 2025 11:34:41 +0000 Subject: [PATCH] Convert MembershipLog.modified_date from date to timestamp so we record time as well --- CRM/Member/BAO/Membership.php | 6 +++--- CRM/Upgrade/Incremental/php/SixZero.php | 8 ++++++++ schema/Member/MembershipLog.entityType.php | 2 +- tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 6955e696de01..ef643d67e177 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1181,7 +1181,7 @@ public static function fixMembershipStatusBeforeRenew(&$currentMembership, $chan $currentMembership['end_date'], $format ), - 'modified_date' => date('Y-m-d H:i:s', CRM_Utils_Time::strtotime($today)), + 'modified_date' => date('YmdHis', CRM_Utils_Time::strtotime($today)), 'membership_type_id' => $currentMembership['membership_type_id'], 'max_related' => $currentMembership['max_related'] ?? 0, ]; @@ -2490,7 +2490,7 @@ public static function updateMembershipStatus($deceasedParams, $contactType) { 'start_date' => CRM_Utils_Date::isoToMysql($dao->start_date), 'end_date' => CRM_Utils_Date::isoToMysql($dao->end_date), 'modified_id' => $userId, - 'modified_date' => CRM_Utils_Time::date('Ymd'), + 'modified_date' => CRM_Utils_Time::date('YmdHis'), 'membership_type_id' => $dao->membership_type_id, 'max_related' => $dao->max_related, ]; @@ -2576,7 +2576,7 @@ private static function createMembershipLog($membership, string $logStartDate = 'status_id' => $membership->status_id, 'start_date' => $logStartDate, 'end_date' => CRM_Utils_Date::isoToMysql($membership->end_date), - 'modified_date' => CRM_Utils_Time::date('Ymd'), + 'modified_date' => CRM_Utils_Time::date('YmdHis'), 'membership_type_id' => $membershipTypeID ?? $membership->membership_type_id, 'max_related' => $membership->max_related, ]; diff --git a/CRM/Upgrade/Incremental/php/SixZero.php b/CRM/Upgrade/Incremental/php/SixZero.php index 4f5385d9b670..3037636abb9f 100644 --- a/CRM/Upgrade/Incremental/php/SixZero.php +++ b/CRM/Upgrade/Incremental/php/SixZero.php @@ -29,6 +29,14 @@ class CRM_Upgrade_Incremental_php_SixZero extends CRM_Upgrade_Incremental_Base { */ public function upgrade_6_0_alpha1($rev): void { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask( + 'Convert MembershipLog.modified_date to timestamp', + 'alterColumn', + 'civicrm_membership_log', + 'modified_date', + "timestamp NULL DEFAULT NULL COMMENT 'Date this membership modification action was logged.'", + FALSE + ); } } diff --git a/schema/Member/MembershipLog.entityType.php b/schema/Member/MembershipLog.entityType.php index 633c2c982894..5677c6239fb5 100644 --- a/schema/Member/MembershipLog.entityType.php +++ b/schema/Member/MembershipLog.entityType.php @@ -85,7 +85,7 @@ ], 'modified_date' => [ 'title' => ts('Membership Change Date'), - 'sql_type' => 'date', + 'sql_type' => 'timestamp', 'input_type' => 'Select Date', 'description' => ts('Date this membership modification action was logged.'), 'add' => '1.5', diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index ab56edae95a5..031315adf4af 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -379,7 +379,7 @@ public function testSubmitRecurCompleteInstant(): void { $log = $this->callAPISuccessGetSingle('MembershipLog', ['membership_id' => $membership['id'], 'options' => ['limit' => 1, 'sort' => 'id DESC']]); $this->assertEquals(CRM_Utils_Time::date($nextYear . '-01-01'), $log['start_date']); $this->assertEquals(CRM_Utils_Time::date($nextYear . '-01-31'), $log['end_date']); - $this->assertEquals(CRM_Utils_Time::date('Y-m-d'), $log['modified_date']); + $this->assertApproxEquals(strtotime(CRM_Utils_Time::date('Y-m-d H:i:s')), strtotime($log['modified_date']), 20); $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); $this->assertEquals($contributionRecur['id'], $membership['contribution_recur_id']); @@ -710,7 +710,7 @@ public function testSubmitRenewExpired(): void { $log = $this->callAPISuccessGetSingle('MembershipLog', ['membership_id' => $renewedMembership['id'], 'options' => ['limit' => 1, 'sort' => 'id DESC']]); $this->assertEquals(CRM_Utils_Time::date('Y-01-01'), $log['start_date']); $this->assertEquals(CRM_Utils_Time::date('Y-12-31'), $log['end_date']); - $this->assertEquals(CRM_Utils_Time::date('Y-m-d'), $log['modified_date']); + $this->assertApproxEquals(strtotime(CRM_Utils_Time::date('Y-m-d H:i:s')), strtotime($log['modified_date']), 20); $this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Current'), $log['status_id']); }