// Tests for this function are in api_v3_JobTest. Please add tests for all updates.
$updateCount = $processCount = self::updateDeceasedMembersStatuses();
-
+ $allStatus = CRM_Member_PseudoConstant::membershipStatus();
$allTypes = CRM_Member_PseudoConstant::membershipType();
// This query retrieves ALL memberships of active types.
INNER JOIN civicrm_contact ON ( civicrm_membership.contact_id = civicrm_contact.id )
INNER JOIN civicrm_membership_type ON
(civicrm_membership.membership_type_id = civicrm_membership_type.id AND civicrm_membership_type.is_active = 1)
-WHERE civicrm_membership.is_test = 0";
+WHERE civicrm_membership.is_test = 0
+ AND civicrm_contact.is_deceased = 0 ";
+
+ $deceaseStatusId = array_search('Deceased', $allStatus);
+ $pendingStatusId = array_search('Pending', $allStatus);
+ // CRM-15475
+ $cancelledStatusId = array_search(
+ 'Cancelled',
+ CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE)
+ );
+ $expiredStatusId = array_search('Expired', $allStatus);
- $dao = CRM_Core_DAO::executeQuery($baseQuery . " AND civicrm_contact.is_deceased = 0");
+ $query = $baseQuery . " AND civicrm_membership.is_override IS NOT NULL AND civicrm_membership.status_override_end_date IS NOT NULL";
+ $dao1 = CRM_Core_DAO::executeQuery($query);
+ while ($dao1->fetch()) {
+ self::processOverriddenUntilDateMembership($dao1);
+ }
+ $dao1->free();
- $allStatus = self::buildOptions('status_id', 'create');
- while ($dao->fetch()) {
+ $query = $baseQuery . " AND civicrm_membership.is_override IS NULL
+ AND civicrm_membership.status_id NOT IN (%1, %2, %3, %4)
+ AND civicrm_membership.owner_membership_id IS NULL ";
+ $params = array(
+ 1 => array($pendingStatusId, 'Integer'),
+ 2 => array($cancelledStatusId, 'Integer'),
+ 3 => array($expiredStatusId, 'Integer'),
+ 4 => array($deceaseStatusId, 'Integer'),
+ );
+ $dao2 = CRM_Core_DAO::executeQuery($query, $params);
+
+ while ($dao2->fetch()) {
+ // echo ".";
$processCount++;
+ // Put common parameters into array for easy access
$memberParams = array(
- 'id' => $dao->membership_id,
- 'status_id' => $dao->status_id,
- 'contact_id' => $dao->contact_id,
- 'membership_type_id' => $dao->membership_type_id,
- 'membership_type' => $allTypes[$dao->membership_type_id],
- 'join_date' => $dao->join_date,
- 'start_date' => $dao->start_date,
- 'end_date' => $dao->end_date,
- 'source' => $dao->source,
+ 'id' => $dao2->membership_id,
+ 'status_id' => $dao2->status_id,
+ 'contact_id' => $dao2->contact_id,
+ 'membership_type_id' => $dao2->membership_type_id,
+ 'membership_type' => $allTypes[$dao2->membership_type_id],
+ 'join_date' => $dao2->join_date,
+ 'start_date' => $dao2->start_date,
+ 'end_date' => $dao2->end_date,
+ 'source' => $dao2->source,
'skipStatusCal' => TRUE,
'skipRecentView' => TRUE,
);
- //we fetch related, since we need to check for deceased
- //now further processing is handle w/ main membership record.
- if ($dao->owner_membership_id) {
- continue;
- }
+ // CRM-7248: added excludeIsAdmin param to the following fn call to prevent moving to admin statuses
+ //get the membership status as per id.
+ $newStatus = civicrm_api('membership_status', 'calc',
+ array(
+ 'membership_id' => $dao2->membership_id,
+ 'version' => 3,
+ 'ignore_admin_only' => TRUE,
+ ), TRUE
+ );
+ $statusId = CRM_Utils_Array::value('id', $newStatus);
- self::processOverriddenUntilDateMembership($dao);
-
- //update membership records where status is NOT - Pending OR Cancelled.
- //as well as membership is not override.
- //skipping Expired membership records -> reduced extra processing( kiran )
- if (!$dao->is_override &&
- !in_array($dao->status_id, array(
- array_search('Pending', $allStatus),
- // CRM-15475
- array_search(
- 'Cancelled',
- CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE)
- ),
- array_search('Expired', $allStatus),
- ))
+ //process only when status change.
+ if ($statusId &&
+ $statusId != $dao2->status_id
) {
-
- // CRM-7248: added excludeIsAdmin param to the following fn call to prevent moving to admin statuses
- //get the membership status as per id.
- $newStatus = civicrm_api('membership_status', 'calc',
- array(
- 'membership_id' => $dao->membership_id,
- 'version' => 3,
- 'ignore_admin_only' => TRUE,
- ), TRUE
+ //take all params that need to save.
+ $memParams = $memberParams;
+ $memParams['status_id'] = $statusId;
+ $memParams['createActivity'] = TRUE;
+ $memParams['version'] = 3;
+
+ // Unset columns which should remain unchanged from their current saved
+ // values. This avoids race condition in which these values may have
+ // been changed by other processes.
+ unset(
+ $memParams['contact_id'],
+ $memParams['membership_type_id'],
+ $memParams['membership_type'],
+ $memParams['join_date'],
+ $memParams['start_date'],
+ $memParams['end_date'],
+ $memParams['source']
);
- $statusId = CRM_Utils_Array::value('id', $newStatus);
+ //since there is change in status.
- //process only when status change.
- if ($statusId &&
- $statusId != $dao->status_id
- ) {
- //take all params that need to save.
- $memParams = $memberParams;
- $memParams['status_id'] = $statusId;
- $memParams['createActivity'] = TRUE;
- $memParams['version'] = 3;
-
- // Unset columns which should remain unchanged from their current saved
- // values. This avoids race condition in which these values may have
- // been changed by other processes.
- unset(
- $memParams['contact_id'],
- $memParams['membership_type_id'],
- $memParams['membership_type'],
- $memParams['join_date'],
- $memParams['start_date'],
- $memParams['end_date'],
- $memParams['source']
- );
-
- //process member record.
- civicrm_api('membership', 'create', $memParams);
- $updateCount++;
- }
+ //process member record.
+ civicrm_api('membership', 'create', $memParams);
+ $updateCount++;
}
}
+ $dao2->free();
$result['is_error'] = 0;
$result['messages'] = ts('Processed %1 membership records. Updated %2 records.', array(
1 => $processCount,