I know that RE will use the default expiration if you add a role to an existing user, but won't do so upon creating new users.

What do you think about adding that functionality to new user creation as well? Would commit it if I provided a patch?

Thanks.

Comments

chrispeat’s picture

Yes that seems very logical and valuable to me. I am looking for a way to set users as expired and would be bulk uploading users, its seems sensible to have it this way round.

Would give it a virtual thumbs up from my end, for what its worth!

Chris

stewsnooze’s picture

I would of course commit it after standard style checks and testing. I'd love simpletests but I am a realistic human.

I am on holiday until 21 dec so take your time and thank you so much

kentr’s picture

@chrispeat: I think I saw somewhere that someone created an addition for user import that incorporates role expire.

kentr’s picture

Status: Active » Postponed

Sorry, my need for this has decreased, so I'm not working on a patch.

stewsnooze’s picture

Status: Postponed » Active

I think this should be a feature. Setting back to active

OliverColeman’s picture

StatusFileSize
new979 bytes

I've made a patch for this. It works for users created by administrators and self-registrations.

It should probably display a notice for administrators to let them know that the role(s) will expire (maybe this should happen whenever the default expiration time has been applied). And in fact the instructions under the text fields in user add/edit form aren't entirely accurate: they always indicate that leaving the field blank will mean the role won't expire, but if they've just enabled the role it will be set to the default duration period. But these should probably be files as different bug reports. :)

inductor’s picture

OliverColeman, thanks a lot for the patch! Works perfectly for new users. Any chance for this to get committed? Maybe somebody else will test it too so we can set the status to RTBC?

sharplesa’s picture

Version: 6.x-1.5 » 6.x-1.11
Assigned: Unassigned » sharplesa
Status: Active » Needs review
StatusFileSize
new13.41 KB

Created a patch that will serve as the candidate for 6.x-1.12. This patch addresses the following issues:

This patch features cleaner help text (from a UX perspective).

Files affected:

  • role_expire.module
  • role_expire.views.inc

I propose to leave this in patch form for a few weeks so you can test it. Please test that Views works correctly and that the default value behavior works as advertised (and is actually an improvement). If I don't hear anything by Christmas, I'll roll a new version of role_expire with this patch incorporated.

Gareth10’s picture

Category: feature » support
Status: Needs review » Active

Is the patch (role_expire.module.diff) that was Posted by OliverColeman on July 2, 2010 at 6:31am which allows it to work for users created by administrators and self-registrations, included in the patch that you released on November 26, 2011 at 12:12am that "will serve as the candidate for 6.x-1.12"?

If it is not included, is it safe to run OliverColeman's path after already running the role_expire-649256-08.patch, or should it be done in order of release?

Thanks to both contributors for the work done here.

sharplesa’s picture

@Gareth10 - Yes, the OliverColeman stuff is included in the patch I wrote. Note that this patch will not apply to the D7 version of role_expire. A separate patch will have to be made for it.

Gareth10’s picture

Status: Active » Needs review

sharplesa - fantastic, thanks for getting back to me so quickly. I will be conducting extensive testing with this module over the next week so I will feedback my findings so you can roll out the new version of role_expire with this patch incorporated.

Many thanks once again - G

Gareth10’s picture

Is this module compatible with Auto assign role (http://drupal.org/project/autoassignrole ) ?

I am using Auto assign role to assign a reg-trial role to all users that sign up to the site, this aspect is working fine.

I am then attempting to use role expire to auto remove this role (back to authenticated user) after a period of time. I have now run several tests but the role is not being automatically removed when the given time period expires. Is what i am trying to achieve not possible with the Role Expire module or am missing something?

Any thoughts / suggestions are greatly welcomed

Many thanks

sharplesa’s picture

Sorry, I don't know anything about auto-assign role. If it uses standard mechanisms, there's a chance it's compatible. Did you give it a try? Did it work?

sharplesa’s picture

Status: Needs review » Fixed

Rolled patch at http://drupal.org/node/649256#comment-5291110 into new version 6.x-1.12.

stewsnooze’s picture

Status: Fixed » Active

There are multiple problems with the code in the patch from http://drupal.org/files/role_expire-649256-08.patch

For instance.

We have comments that are TODO's

+// Addresses: 649256,699608,924976,1230014 (for D6). TODO: Document.
+// TODO: Add updates to D7 version.

We should instead create issues for those and remove them from code.

We have entire functions that are commented out. We are using git. Surely that work if it is in progress should simply be in a branch rather than in the released code?


+///**
+// * Implementation of hook_menu
+// */
+//function role_expire_menu() {
+//  $items['admin/user/role_expiration'] = array(
+//    'title' => 'Role expiration',
+//    'description' => 'List of users with roles that will expire.',
+//    'page callback' => 'drupal_goto',
+//    'page arguments' => array('admin/user/roles/role_expiration'),
+//    'access arguments' => array('access administration pages'),
+//  );
+//
+//  return $items;
+//}

The tab size seems wrong to me in places. It should be 2, inserted as spaces


-    $timestamp2 = strtotime($duration_string,$now-100);
     if ($timestamp===FALSE || $timestamp < 0) {
-      form_set_error('role_expire', 'Role expiration default duration must be a strtotime-compatible string.');
+      form_set_error('role_expire',
+                     t('Default expiration must be a valid duration or date. See php documentation at !l.',
+                             array('!l' => l('strtotime',
+                              'http://php.net/manual/en/function.strtotime.php'
+                                            )
+                                  )
+                      )
+      );

Tab size again.

+    drupal_set_message(t('Default expiration set for %role.',
+                         array('%role' => $form['name']['#default_value']))
+                      );
sharplesa’s picture

Merry Christmas, Stew! Long time no hear! I figured that you had tacitly approved of the patch since it had been out for testing for over a month.

  1. The TODO comments in the code are a-reminders of which issues are covered, and b-reminders to me/someone not to forget to address the same things for D7. I'm pretty sure they're already issues as well.
  2. The commented out role_expire_menu was left in just in case. I wasn't sure whether it was needed when I saw it in a previous release so I just left it.
  3. There are no tabs in the file. Some of the string continuations are extra-indented for legibility. Parens line up and the arguments to t() line up.

You're right that I need to get smart about branching in git. As it is now, I have two different repositories, one for D6 and one for D7. Nevertheless, I think it's good functional code. Suggest you close and throw new issues to clean up the comments.

dianacastillo’s picture

I have the same problem, I am using "auto assign role" to automatically assign users the role of "registered_user" and "trial_user" which works fine , when they register they have those roles. But I also set the role "trial_user" to have a default expiration of "30 days" and when they register they have no default expiration set up.

can this be fixed ? thank you

dianacastillo’s picture

Assigned: sharplesa » Unassigned
Status: Active » Needs work

I dont understand if the patch on comment # 8 was put into the last version of "Role Expire" why when I just installed the latest role expire 6.x-1.x-dev tar.gz (14.37 KB) | zip (17.26 KB) 2012-Aug-30
and ran update.php, i still do not get an automatically generated expiration date when new users register. Can someone clarify if I have to run the patch seperately to get this to work?

dianacastillo’s picture

i just made the changes in this patch and I still do not get an expiration date when someone registers themselves and their role is automatically assigned.

dianacastillo’s picture

I made a cron script to update users with correct expiration date once a day:
http://drupal.org/node/1420070#comment-6635516

dianacastillo’s picture

Status: Postponed (maintainer needs more info) » Needs work

I modified the cron within the role expire module and added two functions and now everytime cron runs the new users who have had the role of "trial user" auto assigned to them get the expiration date assigned: here is the modified cron and the two api functions I added to role_expire.module . I made a patch, but I don't have permissions to attach it.

/**
* Implementation of hook_cron().
*/
function role_expire_cron() {
if ($expires = role_expire_get_expired()) {
$roles = _role_expire_get_role();
foreach ($expires as $expire) {

// Remove the role from the user.
$account = user_load($expire['uid']);
$edit = $account->roles;
unset($edit[$expire['rid']]);
// In the documentation for the role_expire implementation of hook_user we
// state to use $category = 'account'. We don't do that here because
// that would cause the delete to occur twice.
user_save($account, array('roles' => $edit), NULL);

// Remove the role expiration record.
role_expire_delete_record($expire['uid'], $expire['rid']);
watchdog('role expire', 'Remove role @role from user @account.', array('@role' => $roles[$expire['rid']], '@account' => $account->name));
}
}

// now look for users that dont have expiration dates but should and add them

$rid=get_role_id_by_name("trial_user");

// now get the default duration for this role in days
$duration=role_expire_get_default_duration($rid);
$pieces = explode(" ", $duration);

$currentTimestamp = time();// current date
$expiration_date=strtotime("+$pieces[0] $pieces[1]", $currentTimestamp);

// get the users that have the trial user rold but dont have an expiration date yet.
$results=get_users_without_expiration_date($rid);
if (count($results)){
foreach ($results as $uid){
role_expire_write_record($uid,$rid,$expiration_date);
}
}

}

/**
* API function; Get the users that dont have an expiration time for a specific role id.
* // added by diana
* @param $rid
* Role ID.
* @return
* Array with user ids.
*/

function get_users_without_expiration_date($rid){

$result = db_query("SELECT users . uid , users_roles.rid, role_expire . expiry_timestamp
FROM users
JOIN users_roles ON users.uid = users_roles.uid
LEFT OUTER JOIN role_expire ON users.uid = role_expire.uid
WHERE users_roles.rid =$rid AND ISNULL(role_expire.expiry_timestamp)");
while ($row = db_fetch_array($result)) {
$return[] = $row['uid'];
}
return $return;

}

/**
* API function; Get the role id by the name of the role.
* // added by diana
* @param $role_name
* @return $rid
* Role ID
*/
function get_role_id_by_name($role_name){
$result = db_fetch_array(db_query("SELECT rid FROM role WHERE name='$role_name'"));
return (!empty($result)) ? $result['rid'] : '';
}

stewsnooze’s picture

Status: Needs work » Postponed (maintainer needs more info)

Could you at least paste the patch? You can wrap it in code < code > < /code >

dianacastillo’s picture

Here it is, the only thing is I made it specifically for the user with role "trial_user" , this should probably be administrable on the admin page, i havent done that

31a32,68
>  * API function; Get the users that dont have an expiration time for a specific role id.
>  * // added by diana
>  * @param $rid
>  *   Role ID.
>  * @return
>  *  Array with user ids.
>  */
> 
> function get_users_without_expiration_date($rid){
>
>   $result = db_query("SELECT users . uid , users_roles.rid, role_expire . expiry_timestamp
>   FROM users
>   JOIN users_roles ON users.uid = users_roles.uid
>   LEFT OUTER JOIN role_expire ON users.uid = role_expire.uid
>   WHERE users_roles.rid =$rid AND ISNULL(role_expire.expiry_timestamp)");
>   while ($row = db_fetch_array($result)) {
>     $return[] = $row['uid'];
>   }
>   return $return;
> 
> }
> 
> 
> /**
>  * API function; Get the role id by the name of the role.
>  * // added by diana
>  * @param $role_name
>   * @return $rid
>  *   Role ID
>   */
> function get_role_id_by_name($role_name){
>    $result = db_fetch_array(db_query("SELECT rid FROM role WHERE name='$role_name'"));
>    return (!empty($result)) ? $result['rid'] : '';
> }
> 
> 
> /**
188d224
<   $form['account']['roles']['#attributes'] = array('class' => 'role-expire-roles');
287,290c323,324
<    global $user;
<     //if ($category == 'account' && (user_access('administer role expire') || user_access('administer users'))) {
<      if ($category == 'account' && (user_access('administer role expire') || user_access('administer users')) || !$user->uid) {      
< // Add roles expiry information for the user role.
---
>     if ($category == 'account' && (user_access('administer role expire') || user_access('administer users'))) {
>       // Add roles expiry information for the user role.
382a417,436
> 
>   // now look for users that dont have expiration dates but should and add them 
> 
>   $rid=get_role_id_by_name("trial_user");
>   
>   // now get the default duration for this role in days
>    $duration=role_expire_get_default_duration($rid);
>    $pieces = explode(" ", $duration);
>  
>     $currentTimestamp = time();// current date 
>     $expiration_date=strtotime("+$pieces[0] $pieces[1]", $currentTimestamp);
> 	
>   // get the users that have the trial user rold but dont have an expiration date yet.
>    $results=get_users_without_expiration_date($rid);
>    if (count($results)){
>    foreach ($results as $uid){
>      	role_expire_write_record($uid,$rid,$expiration_date);
>     }
       }
>  
> 
463c517
< }
---
> }
\ No newline at end of file

Status: Needs work » Postponed (maintainer needs more info)
rcodina’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (won't fix)

Drupal 6 version is unsupported!