diff --git a/api/v3/Membershiputils/Adjustmembershipenddate.php b/api/v3/Membershiputils/Adjustmembershipenddate.php
index ae8ba97..d8ca7a5 100644
--- a/api/v3/Membershiputils/Adjustmembershipenddate.php
+++ b/api/v3/Membershiputils/Adjustmembershipenddate.php
@@ -22,6 +22,7 @@ function civicrm_api3_membershiputils_Adjustmembershipenddate($params): array {
// If this option is enabled then action, otherwise skip
if (Civi::settings()->get('adjust_membership_end_date')) {
// Get all memberships
+ // Note: This intentionally updates both Primary and Non-primary memberships because CiviCRM has a long history of bugs when it comes to correctly inheriting changes from Primary to non-primary memberships
$memberships = Membership::get()
->addSelect('id', 'end_date')
->addWhere('status_id:name', 'IN', [
diff --git a/api/v3/Membershiputils/Specificmembershipenddate.php b/api/v3/Membershiputils/Specificmembershipenddate.php
index 25cd518..d521950 100644
--- a/api/v3/Membershiputils/Specificmembershipenddate.php
+++ b/api/v3/Membershiputils/Specificmembershipenddate.php
@@ -25,6 +25,7 @@ function civicrm_api3_membershiputils_Specificmembershipenddate($params): array
->get('specific_membership_end_date'));
// Get all memberships
+ // Note: This intentionally updates both Primary and Non-primary memberships because CiviCRM has a long history of bugs when it comes to correctly inheriting changes from Primary to non-primary memberships
\Civi\Api4\Membership::update(TRUE)
->addValue('end_date', $new_end_date->format('Y-m-d'))
->addWhere('status_id:name', 'IN', [
diff --git a/info.xml b/info.xml
index 874afe9..1390520 100644
--- a/info.xml
+++ b/info.xml
@@ -14,8 +14,8 @@
https://agileware.com.au/contact
http://www.gnu.org/licenses/agpl-3.0.html
- 2024-06-07
- 1.4.3
+ 2024-07-15
+ 1.4.4
stable
5.27
diff --git a/membershiputils.php b/membershiputils.php
index ba9ae95..bfc183c 100644
--- a/membershiputils.php
+++ b/membershiputils.php
@@ -177,14 +177,26 @@ function membershiputils_adjustmembershipenddate($end_date) {
return $new_end_date->format($date_format);
}
-function membershiputils_civicrm_pre($op, $objectName, $id, &$params) {
+function membershiputils_civicrm_pre($op, $objectName, $id, &$params)
+{
// If the Membership is being created or edited and the end date has been set then adjust
// Skip when 'null' is set as the end_date as this indicates a Lifetime membership term with on end date
if (('Membership' == $objectName) && ('edit' == $op || 'create' == $op) && $params['end_date'] && 'null' !== $params['end_date']) {
- if (Civi::settings()->get('adjust_membership_end_date') || Civi::settings()->get('use_specific_membership_end_date')) {
- // This is where CiviCRM may pass in the end date in two different formats
+
+ // Get all the membership statuses
+ $membershipStatuses = \Civi\Api4\MembershipStatus::get(TRUE)
+ ->addSelect('id', 'name')
+ ->execute()
+ ->indexBy('id')
+ ->getArrayCopy();
+
+ $currentStatus = $membershipStatuses[$params['status_id']]['name'];
+
+ if (Civi::settings()->get('adjust_membership_end_date') && $currentStatus == 'New' || $currentStatus == 'Current' || $currentStatus == 'Grace') {
$params['end_date'] = membershiputils_adjustmembershipenddate($params['end_date']);
}
+ } elseif (Civi::settings()->get('use_specific_membership_end_date') && $currentStatus == 'New' || $currentStatus == 'Current') {
+ $params['end_date'] = membershiputils_adjustmembershipenddate($params['end_date']);
}
}
@@ -192,7 +204,7 @@ function membershiputils_civicrm_post($op, $objectName, $id, &$params) {
// This function is required to work around weirdness in CiviCRM which sometimes does not set the membership dates, they may be NULL
if ('Membership' == $objectName && 'create' == $op) {
if (Civi::settings()->get('adjust_membership_end_date') || Civi::settings()->get('use_specific_membership_end_date')) {
- // If end date has been set then do not try to calculate it now
+ // If end date has not been set then try to calculate it now
if (!$params->end_date) {
$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($params->membership_type_id, NULL, NULL, NULL);
diff --git a/settings/Membershiputils.setting.php b/settings/Membershiputils.setting.php
index d17d61a..98877f3 100644
--- a/settings/Membershiputils.setting.php
+++ b/settings/Membershiputils.setting.php
@@ -35,7 +35,7 @@
'is_domain' => 1,
'is_contact' => 0,
'title' => E::ts('Specific Membership End Date'),
- 'description' => E::ts('Set the Membership End Date to the end of month. Applies to New, Current and Grace memberships only. Leave blank to disable.'),
+ 'description' => E::ts('Set the Membership End Date to the end of month. Applies to New and Current memberships only. Leave blank to disable.'),
'settings_pages' => ['membershiputils' => ['weight' => 10]],
],
'membershiputils_type_change_notification' => [