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

Convert MembershipLog.modified_date from date to timestamp so we record time as well #31799

Merged
merged 1 commit into from
Jan 18, 2025
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be simplified to just CRM_Utils_Time::time() but I'll put it up as a followup.


$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