From ccd459b88eb80a8c852a262503aee95e0431615c Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 1 Jan 2021 22:20:56 -0800 Subject: [PATCH] (REF) CRM/Member - Change strtotime() to CRM_Utils_Time::strtotime() --- CRM/Member/BAO/Membership.php | 12 ++++++------ CRM/Member/BAO/MembershipStatus.php | 14 +++++++------- CRM/Member/Form/Membership.php | 2 +- CRM/Member/Form/MembershipRenewal.php | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 01086e0f88..ada6d3cd31 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -252,8 +252,8 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { if (empty($params['is_override']) && empty($params['skipStatusCal'])) { $fieldsToLoad = []; foreach (['start_date', 'end_date', 'join_date'] as $dateField) { - if (!empty($params[$dateField]) && $params[$dateField] !== 'null' && strpos($params[$dateField], date('Ymd', strtotime(trim($params[$dateField])))) !== 0) { - $params[$dateField] = date('Ymd', strtotime(trim($params[$dateField]))); + if (!empty($params[$dateField]) && $params[$dateField] !== 'null' && strpos($params[$dateField], date('Ymd', CRM_Utils_Time::strtotime(trim($params[$dateField])))) !== 0) { + $params[$dateField] = date('Ymd', CRM_Utils_Time::strtotime(trim($params[$dateField]))); // @todo enable this once core is using the api. // CRM_Core_Error::deprecatedWarning('Relying on the BAO to clean up dates is deprecated. Call membership create via the api'); } @@ -1012,7 +1012,7 @@ INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_ty $dates = ['startDate', 'endDate']; foreach ($dates as $date) { if (strlen($$date) === 8) { - $$date = date('Y-m-d', strtotime($$date)); + $$date = date('Y-m-d', CRM_Utils_Time::strtotime($$date)); } } @@ -1200,7 +1200,7 @@ AND civicrm_membership.is_test = %2"; $currentMembership['end_date'], $format ), - 'modified_date' => date('Y-m-d H:i:s', strtotime($today)), + 'modified_date' => date('Y-m-d H:i:s', CRM_Utils_Time::strtotime($today)), 'membership_type_id' => $currentMembership['membership_type_id'], 'max_related' => $currentMembership['max_related'] ?? 0, ]; @@ -2102,7 +2102,7 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND */ protected static function matchesRequiredMembership($params, $membership) { foreach (['start_date', 'end_date'] as $date) { - if (strtotime($params[$date]) !== strtotime($membership[$date])) { + if (CRM_Utils_Time::strtotime($params[$date]) !== CRM_Utils_Time::strtotime($membership[$date])) { return FALSE; } if ((int) $params['status_id'] !== (int) $membership['status_id']) { @@ -2714,7 +2714,7 @@ WHERE {$whereClause}"; } $today = time(); - if ($deceasedDate && strtotime($deceasedDate) > $today) { + if ($deceasedDate && CRM_Utils_Time::strtotime($deceasedDate) > $today) { return $updateMembershipMsg; } diff --git a/CRM/Member/BAO/MembershipStatus.php b/CRM/Member/BAO/MembershipStatus.php index dd3404405d..026b133062 100644 --- a/CRM/Member/BAO/MembershipStatus.php +++ b/CRM/Member/BAO/MembershipStatus.php @@ -218,7 +218,7 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { CRM_Core_Error::deprecatedFunctionWarning('pass now rather than today in'); } - $statusDate = date('Ymd', strtotime($statusDate)); + $statusDate = date('Ymd', CRM_Utils_Time::strtotime($statusDate)); //fix for CRM-3570, if we have statuses with is_admin=1, //exclude these statuses from calculatation during import. @@ -236,9 +236,9 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { $membershipStatus = CRM_Core_DAO::executeQuery($query); $dates = [ - 'start' => ($startDate && $startDate !== 'null') ? date('Ymd', strtotime($startDate)) : '', - 'end' => ($endDate && $endDate !== 'null') ? date('Ymd', strtotime($endDate)) : '', - 'join' => ($joinDate && $joinDate !== 'null') ? date('Ymd', strtotime($joinDate)) : '', + 'start' => ($startDate && $startDate !== 'null') ? date('Ymd', CRM_Utils_Time::strtotime($startDate)) : '', + 'end' => ($endDate && $endDate !== 'null') ? date('Ymd', CRM_Utils_Time::strtotime($endDate)) : '', + 'join' => ($joinDate && $joinDate !== 'null') ? date('Ymd', CRM_Utils_Time::strtotime($joinDate)) : '', ]; while ($membershipStatus->fetch()) { @@ -253,9 +253,9 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { if ($membershipStatus->{$eve . '_event_adjust_unit'} && $membershipStatus->{$eve . '_event_adjust_interval'} ) { - $month = date('m', strtotime($date)); - $day = date('d', strtotime($date)); - $year = date('Y', strtotime($date)); + $month = date('m', CRM_Utils_Time::strtotime($date)); + $day = date('d', CRM_Utils_Time::strtotime($date)); + $year = date('Y', CRM_Utils_Time::strtotime($date)); // add in months if ($membershipStatus->{$eve . '_event_adjust_unit'} === 'month') { ${$eve . 'Event'} = date('Ymd', mktime(0, 0, 0, diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 4988331a0e..a9008897de 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1966,7 +1966,7 @@ DESC limit 1"); $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis'); if (!empty($params['receive_date'])) { - $recurParams['start_date'] = date('YmdHis', strtotime($params['receive_date'])); + $recurParams['start_date'] = date('YmdHis', CRM_Utils_Time::strtotime($params['receive_date'])); } $recurParams['invoice_id'] = $params['invoiceID'] ?? NULL; $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index cffc53edfc..d2f65ecaeb 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -737,7 +737,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { ])) { return CRM_Member_BAO_Membership::create($memParams); } - $memParams['join_date'] = date('Ymd', strtotime($currentMembership['join_date'])); + $memParams['join_date'] = date('Ymd', CRM_Utils_Time::strtotime($currentMembership['join_date'])); $isMembershipCurrent = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $currentMembership['status_id'], 'is_current_member'); // CRM-7297 Membership Upsell - calculate dates based on new membership type -- 2.25.1