Skip to content

Commit

Permalink
Convert MembershipLog.modified_date from date to timestamp so we reco…
Browse files Browse the repository at this point in the history
…rd time as well
  • Loading branch information
mattwire committed Jan 17, 2025
1 parent f65b9a7 commit 2f207c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down Expand Up @@ -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,
];
Expand Down Expand Up @@ -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,
];
Expand Down
8 changes: 8 additions & 0 deletions CRM/Upgrade/Incremental/php/SixZero.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

}
2 changes: 1 addition & 1 deletion schema/Member/MembershipLog.entityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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']);
}

Expand Down

0 comments on commit 2f207c1

Please sign in to comment.