You are here

function uc_recurring_subscription_revoke_role in UC Recurring Payments and Subscriptions 7.2

Revoke user roles.

2 string references to 'uc_recurring_subscription_revoke_role'
uc_recurring_subscription_ca_predicate in modules/uc_recurring_subscription/uc_recurring_subscription.ca.inc
Implementation of hook_ca_predicate().
uc_recurring_subscription_default_rules_configuration in modules/uc_recurring_subscription/uc_recurring_subscription.rules_defaults.inc
Implements hook_default_rules_configuration().

File

modules/uc_recurring_subscription/uc_recurring_subscription.rules.inc, line 183
Rules definitions.

Code

function uc_recurring_subscription_revoke_role($order, $role_option, $roles) {
  $account = user_load($order->uid);
  $role_names = user_roles(TRUE);
  if ($role_option == 'custom') {
    foreach ($roles as $rid => $role) {
      unset($account->roles[$rid]);
      watchdog('uc_recurring', 'Revoked !role role from !user', array(
        '!role' => $role_names[$rid],
        '!user' => $account->name,
      ));
    }
  }
  else {
    foreach ($order->products as $pid => $product) {
      $subscription = uc_recurring_subscription_load($product->nid);
      if (!empty($subscription->access[$role_option])) {
        foreach ($subscription->access[$role_option] as $rid => $role) {

          // @todo: we need to check other subscriptions to ensure that the role
          // is no longer required by another subscription.
          unset($account->roles[$rid]);
        }
      }
    }
  }
  $account = user_save($account, array(
    'roles' => $account->roles,
  ));
}