Step-by-step process:

1. Verify correct installation of Role Expire.
Role Expire: version 7.x-1.0-beta2 (permissions checked)
Drupal Core: version 7.8

2. Go to /admin/people/permissions/roles, edit a role, set a default duration for the role and save role.

3. Go back to the role edit page. Problem 1: the default role duration field is still blank (in a previous version of role expire, this field shows the default duration that you saved). This indicates that something is wrong. We verify this in '4'

4. Assign the role to a user (user/#/edit) en verify that the role expire time message is showing on the profile page... Problem 2: The message is not showing at all.

5. Go back to user/#/edit, assign a role and add an expiry time manually (so that it's different from the default duration). This time, the role expire time message is showing on the profile page of the user. So this still works.

Additional info:

- I upgraded from Role expire version 7.x-1.0-beta1 to beta2. The default role expire duration set in beta1 were taken by beta2. Everything works fine untill you try to change the default role expire duration. (or add a default duration to a new role)

- I installed Role expire version 7.x-1.0-beta1 again. Everything is working fine in this version.
- After this, I uninstalled Role expire version 7.x-1.0-beta1 completly (so database tables removed) and installed Role expire version 7.x-1.0-beta2 again. Same issues as in my step-by-step process.

I hope you can duplicate the problem, if you need more info, just ask.

Thanks

Comments

sharplesa’s picture

Assigned: Unassigned » sharplesa

Good bug report. I've confirmed this behavior. Rats!

What's interesting is that roles that had default expirations before the update continue to have expirations now. But once I edit them, the default expiration goes away.

sharplesa’s picture

Status: Active » Needs review
StatusFileSize
new3.11 KB

I've found the problem. There was some code that I didn't update correctly from 6.x to 7.x when I built the new release. The attached patch should fix that problem (as well as the Views integration problem noted at #1291466: Views integration not working).

Now when you go through the steps Scipr outlined above, the default duration does get set.

Scipr, do you know how to apply patches? If you apply, test and confirm this patch, I'll update the module.

Again, thanks for the excellent bug report, Scipr. Made it easy to isolate and test.

Scipr’s picture

Thank you for looking into this issue.

So I applied the patch on version 7.x-1.0-beta2 of Role Expire using Netbeans. Verified that the code has changed and installed the module.

Testing functionality after applying the patch of #2:

- Manually set an expire duration on the user/#/edit page: works perfectly
- Views integration of role_expire: works perfectly
- Set a default duration on the admin/people/permissions/roles/edit role page. After saving the role I get this error message:

PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'duration' at row 1: INSERT INTO {role_expire_length} (rid, duration) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 6 [:db_insert_placeholder_1] => 24 months ) in role_expire_set_default_duration() (line 143 of /.../sites/all/modules/role_expire/role_expire.module).

If I had more knowledge about coding I could help more, but for now I'll contribute by testing :).

sharplesa’s picture

Testing is great!!

Did you remember to run update.php before you began this test sequence? The database schema does change between beta1 and beta2.

Thanks

Scipr’s picture

Yes, I remember. But because beta1 was completely removed from my Drupal installation (and I verified that the tables were removed from my database) you don't have to run update.php (I think). Although I checked update.php every time after installing the Role Expire module it said "No pending updates".
Also after applying the patch and installing the module I checked update.php: "No pending updates".
I just checked update.php again and it still says: "No pending updates".

So you can't duplicate this problem?

sharplesa’s picture

No. Can't duplicate the problem. Can you get to the database? Are you using mysql or something else? For my installation (mysql) the role_expire_length table looks like this:

CREATE TABLE `role_expire_length` (
  `rid` int(10) unsigned NOT NULL COMMENT 'The role_id.',
  `duration` tinytext COMMENT 'A strtotime-compatible duration string',
  PRIMARY KEY (`rid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Length in days to assign each role by default.';

Is this what yours is?

(To create this CREATE TABLE command, I used phpmyadmin and did an 'export' of the role_expire_length table, Structure-only.)

Scipr’s picture

Hi sharplesa,

I got everything working now. I use phpmyadmin (mysql) for my database. I dropped the table 'role_expire_length' and ran a query to create the table again (I copy/pasted the query from #6). A quick check indicates that everything works.

I would just like to point out a small issue with Role expire version 7.x-1.0-beta2. This issue explains why you couldn't duplicate the problem. But this is also very important for new users of the Role expire module.

Issue:
On a clean install (!) of Role expire version 7.x-1.0-beta2 the database field 'duration' from the table `role_expire_length`is still an 'integer'. This is not correct, this should be a 'tinytext' type. Even if you run the database update script, nothing changes to the field of the database.

However, someone who upgrades from beta1 to beta2 and runs the database update script: the database field 'duration' will be changed to 'tinytext'. This is why you couldn't duplicate the problem. You had the correct database structure. I had a database issue because I started from a clean install.

But, I could be mistaken, I'm quite new to this stuff.

I will confirm your patch later on when I have tested it a bit more.

Sharplesa, thank you for your patience and help. I really appreciate this. This is my first contact with the drupal community and it is very encouraging.

sharplesa’s picture

Yep. You've hit the nail on the head. I completely forgot about that use case(!) A revised patch is on its way.

BTW, testing for this uncovered another bug. If you edit a role a second time and don't change the non-empty default duration, you'll get a PDO error.
The bug:
1. Go to admin/people/permissions/roles and click "Edit role" for role A.
2. Add a duration to role A and click "Save role".
3. Still on admin/people/permissions/roles, click "Edit role" for role A (again).
4. Don't change anything and click "Save role".
5. Observe the error message.

The patch'll fix this second error too. Problem is, I'm tied up until at least Sunday.

Scipr, glad you're now part of the Drupal community. Your testing and reporting are invaluable.

sharplesa’s picture

Status: Needs review » Needs work
sharplesa’s picture

Status: Needs work » Needs review
StatusFileSize
new5.13 KB

The following patch addresses the problem Scipr in #3ff, and the one I found in #8.

To test #3:

  1. If role_expire is installed, completely uninstall role_expire:
    1. Go to admin/modules and uncheck role_expire and click "Save configuration"
    2. Go to admin/modules/uninstall and click the 'Uninstall' checkbox for role_expire and click "Uninstall" button.
  2. Apply role_expire-1293846-10.patch.
  3. Install role_expire -- go to admin/modules and check 'role_expire' and click "Save configuration"
  4. Set a default duration on the admin/people/permissions/roles/edit role page.
  5. Click 'edit role' again and verify that the default expiration you set in the previous step appears in the field.

To test #8:
(This was a total rewrite of role_expire_set_default_duration.)

  1. After testing #3, simply click "Save Role" without making any changes.
  2. Verify that you don't get an error message and that the value that was in the role's 'Default duration' field is unchanged.
  3. Regression test! Verify continued correct behavior of the module.

Additional changes:

  1. Added a check that the duration field is actually a string and not an int. If the duration field is an int, you'll see an error message that tells you to run update.php. (This was a total rewrite of role_expire_get_default_duration.)
  2. The views api was relaxed to accept any form of 3.x as a valid views version. (See #1291466: Views integration not working)
jhood’s picture

I tested the patch and it now saves the default duration. :)

My question is if I give the role to a user and the field to enter the default duration pops up, should the default duration show up?

bensti’s picture

Patch #10 work for me !

sharplesa’s picture

As it currently stands, if you use the default, you only see the default duration after the user has been saved. There's a 6.x patch that prefills the expiry field with the default duration on load. Once that patch is accepted, I plan to create a patch for the 7.x version that does the same thing.

liliplanet’s picture

StatusFileSize
new20.48 KB

i'm attaching the patched module with #10 thank you sharplesa!

and also patch from

"add expire time to role" in Rules adds from current day, but not the user's role expiration day at http://drupal.org/node/1370262, thank you davidwatson!

all working good :)

RKS’s picture

I love you Liliplanet! I have a client using GoDaddy without SSH and I didn't feel like doing anything with their stupid FTP panel. This patched version fixed the issue for me.

stewsnooze’s picture

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

RE #14 Liliplanet: If you have fixed this could you attach a patch to this issue.

See here for instructions if you need them. http://drupal.org/node/707484

That would be great and I could review and possibly commit that to the main module. If you can't do that let me know and perhaps we can see what changes you made to support this. I suspect you edited the beta rather than the dev version. Is that right?

liliplanet’s picture

Hi stewsnooze, thank you! yes the patches were done to the 7.x-1.x-dev version.

The patches include are:

http://drupal.org/files/role_expire-1293846-10.patch
http://drupal.org/files/1370262--role-expire-rules-2--7.patch

liliplanet’s picture

StatusFileSize
new13.27 KB

Here is also a block for users to view their expiry date. I did this because the date did not show up on the profile. The role in this instance is called 'Contributor'.

ressa’s picture

Thanks to everyone for patching the module and getting it fixed. The latest dev release (7.x-1.0-beta1+6-dev from 2012-Sep-24) works just fine, and the user's expiry date is also shown on their account page.

A tip to others and a reminder to myself: If you add the role to a user with Rules during checkout with Commerce for example, remember to set the expiration time for the user's role, otherwise the role expiration time will be empty.

The two rules to add

  • Add user role
  • Set expire time for role
liliplanet’s picture

Really, would we be able to solve the issues Commerce roles expiry as commerce_sp seems to be abandoned as that would be absolutely amazing.

Perhaps we could have a rule that sends an expiration (ie 3 days before) warning for the user?

Looking most forward to your development, thank you!

ressa’s picture

I think it can be done with Rules Scheduler, see this post by trevorkjorlien: http://drupal.org/node/827594#comment-5254316

It seems like a lot of work, perhaps there is a simpler method? :-)

krisrobinson’s picture

I was having this problem so I updated to the .dev version, after setting the default expire time on the role - I went back in to change the default expire time and I get this message:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5' for key 'PRIMARY': INSERT INTO {role_expire_length} (rid, duration) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 5 [:db_insert_placeholder_1] => 183 ) in role_expire_set_default_duration() (line 144 of /sites/all/modules/role_expire/role_expire.module).

mrded’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev
Issue summary: View changes

Which patch is actual for 7.x-1.x-dev version? #10 ?

jonhattan’s picture

Component: User interface » Code
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new5.54 KB

#10 doesn't apply. Re-rolled on top of latest dev. Also added hook_update_N() to address column type change.

ptmkenny’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch in #24; I was getting an error before when re-saving a role with an expiration, but that no longer occurs and it saves properly. Good work!

anybody’s picture

The patch works great but I think it is really important to have a new beta release because the current beta release is just broken, so things can not get worse... :(

devaraj johnson’s picture

Issue summary: View changes
Issue tags: +Spelling mistake
rcodina’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

I have tried to reproduce the problem using latest dev with no success. Could you check it out again? Anyway, the patch does not cleanly apply. I think the module works fine now. If you still find the same problem, please reopen and reroll patch.

sgdev’s picture

sgdev’s picture

So I've reviewed this in further detail, and compared to the original patch from #1280450.

I think there is value in what patch #24 has, and should be combined with what previously existed in from #1280450. I have created a single patch that brings the two together against the 7.x-1.x branch.

It can be found here: https://www.drupal.org/project/role_expire/issues/2891810#comment-12661918

Please review and provide your feedback, thanks.

rcodina’s picture

Status: Postponed (maintainer needs more info) » Fixed

Now #2891810: 7.x-1.0-rc1 rolls back some features from 7.x-1.0-beta2 (Default durations functionality) is fixed. So I close this issue. Thanks to everyone and specially to ron_s!

rcodina’s picture

Assigned: sharplesa » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.