Commit 05fcfc4c authored by drumm's avatar drumm

If CiviCRM has an active membership, use it

parent 0599220e
......@@ -7005,6 +7005,14 @@ function _drupalorg_update_user_membership_fields_shutdown() {
foreach (user_load_multiple($uids) as $account) {
$account_wrapper = entity_metadata_wrapper('user', $account);
// If CiviCRM has an active membership, use it.
// todo remove when CiviCRM is no longer a source of truth.
if ($civicrm_membership = db_query_range('SELECT expiration_date FROM {drupalorg_crosssite_ind_civimembership} WHERE user_name = :name AND expiration_date > :end', 0, 1, [':name' => $account->name, ':end' => $combined_subscriptions[$account->uid]->current_period_ends_at])->fetch()) {
watchdog('drupalorg_chargify', 'Using CiviCRM expiration date for user @name', ['@name' => $account->name], WATCHDOG_NOTICE, l($account->name, 'user/' . $account->uid));
$combined_subscriptions[$account->uid]->state = 'active';
$combined_subscriptions[$account->uid]->current_period_ends_at = $civicrm_membership->expiration_date;
}
$changed = [];
if ($combined_subscriptions[$account->uid]->state === 'active') {
if ($account_wrapper->field_da_ind_membership->value() !== 'Current') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment