There is an action to Revoke a role / Grant a role on expiration of role in uc_recurring. One of the options is to remove / grant custom selected roles. The code for that is possibly broken in 6.x-2.0-alpha6 (try it out!).
(Not that it should matter, FYI I am using PHP 5.2.x)
A proposed patch follows
--- a/htdocs/sites/all/modules/uc_recurring/modules/uc_recurring_subscription/uc_recurring_subscription.ca.inc
+++ b/htdocs/sites/all/modules/uc_recurring/modules/uc_recurring_subscription/uc_recurring_subscription.ca.inc
@@ -198,10 +198,13 @@ function uc_recurring_subscription_action_grant_role($order, $settings) {
$roles = user_roles(TRUE);
if ($settings['role_option'] == 'custom') {
- $account->roles += $settings['role'];
- watchdog('uc_recurring', 'Granted !role role to !user', array('!role' => $roles[$rid], '!user' => $account->name));
- }
- else {
+ foreach ($settings['role'] as $rid => $role) {
+ if($role) {
+ $account->roles += array($rid => $role);
+ watchdog('uc_recurring', 'Granted !role role to !user', array('!role' => $roles[$rid], '!user' => $account->name));
+ }
+ }
+ } else {
foreach ($order->products as $pid => $product) {
$subscription = uc_recurring_subscription_load($product->nid);
if (!empty($subscription->access[$settings['role_option']])) {
@@ -258,8 +261,10 @@ function uc_recurring_subscription_action_revoke_role($order, $settings) {
$roles = user_roles(TRUE);
if ($settings['role_option'] == 'custom') {
foreach ($settings['role'] as $rid => $role) {
- unset($account->roles[$rid]);
- watchdog('uc_recurring', 'Revoked !role role from !user', array('!role' => $roles[$rid], '!user' => $account->name));
+ if($role) {
+ unset($account->roles[$rid]);
+ watchdog('uc_recurring', 'Revoked !role role from !user', array('!role' => $roles[$rid], '!user' => $account->name));
+ }
}
}
else {
Comments
Comment #1
afox commentedDuplicate of #1105706: uc_recurring_subscription_action_revoke_role() revokes all roles when using 'custom'