// eg pay later membership, membership update cron CRM-3984
if (empty($params['is_override']) && empty($params['skipStatusCal'])) {
- $dates = ['start_date', 'end_date', 'join_date'];
- // Declare these out of courtesy as IDEs don't pick up the setting of them below.
- $start_date = $end_date = $join_date = NULL;
- foreach ($dates as $date) {
- $$date = $params[$date] = CRM_Utils_Date::processDate(CRM_Utils_Array::value($date, $params), NULL, TRUE, 'Ymd');
- }
+ // @todo - we should be able to count on dates being correctly formatted by they time they hit the BAO.
+ // Maybe do some tests & throw some deprecation warnings if they aren't?
+ $params['start_date'] = trim($params['start_date']) ? date('Ymd', strtotime(trim($params['start_date']))) : 'null';
+ $params['end_date'] = trim($params['end_date']) ? date('Ymd', strtotime(trim($params['end_date']))) : 'null';
+ $params['join_date'] = trim($params['join_date']) ? date('Ymd', strtotime(trim($params['join_date']))) : 'null';
//fix for CRM-3570, during import exclude the statuses those having is_admin = 1
$excludeIsAdmin = CRM_Utils_Array::value('exclude_is_admin', $params, FALSE);
$excludeIsAdmin = TRUE;
}
- $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($start_date, $end_date, $join_date,
+ $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($params['start_date'], $params['end_date'], $params['join_date'],
'today', $excludeIsAdmin, CRM_Utils_Array::value('membership_type_id', $params), $params
);
if (empty($calcStatus)) {
- throw new CRM_Core_Exception(ts(
- "The membership cannot be saved because the status cannot be calculated for start_date: $start_date end_date $end_date join_date $join_date as at " . date('Y-m-d H:i:s')),
- 0,
- $errorParams
- );
+ throw new CRM_Core_Exception(ts("The membership cannot be saved because the status cannot be calculated for start_date: {$params['start_date']} end_date {$params['end_date']} join_date {$params['join_date']} as at " . date('Y-m-d H:i:s')));
}
$params['status_id'] = $calcStatus['id'];
}
* Test merging 2 organizations.
*
* CRM-20421: This test make sure that inherited memberships are deleted upon merging organization.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
public function testMergeOrganizations() {
$organizationID1 = $this->organizationCreate([], 0);
$membershipParams = [
'membership_type_id' => $membershipType["id"],
'contact_id' => $organizationID1,
- 'start_date' => "01/01/2015",
- 'join_date' => "01/01/2010",
- 'end_date' => "12/31/2015",
+ 'start_date' => '01/01/2015',
+ 'join_date' => '01/01/2010',
+ 'end_date' => '12/31/2015',
];
- $ownermembershipid = $this->contactMembershipCreate($membershipParams);
+ $ownerMembershipID = $this->contactMembershipCreate($membershipParams);
- $contactmembership = $this->callAPISuccess("membership", "getsingle", [
- "contact_id" => $contact["id"],
- ]);
+ $contactMembership = $this->callAPISuccessGetSingle('membership', ['contact_id' => $contact['id']]);
- $this->assertEquals($ownermembershipid, $contactmembership["owner_membership_id"], "Contact membership must be inherited from Organization");
+ $this->assertEquals($ownerMembershipID, $contactMembership['owner_membership_id'], "Contact membership must be inherited from Organization");
CRM_Dedupe_Merger::moveAllBelongings($organizationID2, $organizationID1, [
- "move_rel_table_memberships" => "0",
+ 'move_rel_table_memberships' => "0",
"move_rel_table_relationships" => "1",
"main_details" => [
"contact_id" => $organizationID2,
],
]);
- $contactmembership = $this->callAPISuccess("membership", "get", [
+ $contactMembership = $this->callAPISuccess("membership", "get", [
"contact_id" => $contact["id"],
]);
- $this->assertEquals(0, $contactmembership["count"], "Contact membership must be deleted after merging organization without memberships.");
+ $this->assertEquals(0, $contactMembership["count"], "Contact membership must be deleted after merging organization without memberships.");
}
/**
return $tests;
}
- /**
+ /**
* CRM-14743 - test api respects search operators.
*
* @param int $version
*
+ * @param $query
+ * @param $field
+ * @param $expected
+ *
+ * @throws \CRM_Core_Exception
* @dataProvider versionAndPrivacyOption
*/
public function testGetContactsByPrivacyFlag($version, $query, $field, $expected) {