Is there any way to modify the module to expire roles after hours instead of days?
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | role_expire-926248-22.patch | 7.75 KB | sharplesa |
| #20 | role_expire-926248-20.patch | 7.56 KB | sharplesa |
| #11 | 926248.patch | 2.21 KB | stella |
Is there any way to modify the module to expire roles after hours instead of days?
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | role_expire-926248-22.patch | 7.75 KB | sharplesa |
| #20 | role_expire-926248-20.patch | 7.56 KB | sharplesa |
| #11 | 926248.patch | 2.21 KB | stella |
Comments
Comment #1
sfdrummer commentedComment #2
stewsnoozeHave you tried putting in a default expiry of .5 for half a day before we code it up?
The module uses mktime() to generate the date in the future. I guess it depends on whether that supports it?
Comment #3
stewsnoozeComment #4
sfdrummer commentedJust tried that and the Default Day Length defaults to 0
Comment #5
stewsnoozeok then. This is a feature request. It will need to be coded.
Comment #6
sfdrummer commentedOk then, I was just wondering if theres a quick hack to get it working. Thanks for the quick response!!
Comment #7
stewsnoozeIf I was to develop this now to only support hours instead of days (which I'm not doing as if we do it then we should support both)
then I would edit this function
and I'd change following line editing the mktime call to add hours instead of days.
You could check out http://php.net/manual/en/function.mktime.php to see what you need if you want to hack away at it.
Comment #8
sfdrummer commentedMany thanks for all your help!
Works perfectly!
Comment #9
stewsnooze@sfdrummer Would you be so kind as to share your patch? or at least the lines you changed
Comment #10
sfdrummer commented@stewsnooze Sorry, I missed your request, yes I'd be happy to.
Not sure how much use this will be to anyone but here is the section I changed in role_expire.module
As you can see, I've just moved $role_day_period so that it changes the hours instead of the days.
Comment #11
stella commentedHere's an actual patch and I changed the UI text to match.
Comment #12
stewsnoozeI can't commit this. We have a user base that expect this to do days. I'm not against adding something to the UI to expose hours as an option but the default must be days as it is now.
Comment #13
stella commentedIf we wrote an update hook to update the database so the default expiry period is stored as hours rather than days, would you accept it then? Or are you looking for a complete rewrite? I don't have a paying client to cover the time for a rewrite now, so will just have to continue using this patch until someone else can provide an acceptable solution.
Comment #14
stewsnoozeI don't think I want an update function. If we want this functionality I think the UI needs to allow people to type something like "3 days "or "3 hours", defaulting to days if no type is entered into the text box and have the module process what they entered.
Alternatively we could have a select box that contains the type. I think I prefer the first option. What do you think?
Comment #15
stella commentedThe first option is appealing, but if working on a non-English or multi-lingual site, could be confusing or difficult to use, so atm, I'm leaning towards the select box - or if just two options, maybe a radio button is better? not sure.
Comment #16
sharplesa commentedSeems that this can be done more simply. Here's an implementation I have working:
1. Slightly modify the description of the field so that users can know they can enter fractional days.
2. Modify the schema of the role_expire_length.duration column to be float instead of int.
3. Add an update to the .install file to modify the schema.
4. Modify role_expire_process_default_role_duration_for_user to accommodate the integer and fractional day parts.
If this is OK, then what remains to be decided is the minutes/seconds parts. That is, when mktime is called, should we just use 0 for the minutes and seconds?
Alternatively, if this seems like a real burden on users, then an hours field should be added to the default-setting page at admin/user/roles.
What do you think? Seems pretty easy to implement fractional days.
Comment #17
stewsnoozeI don't think that fractions of days will provide a good user interface. I don't know of anyone who talks about fractions of days rather than hours so I believe we should stick to real world terms in the user interface.
The lines of code that calculate the expiry time based on a default are something like this...
However when somebody edits a user and adds an expiry it gets assigned using something like this
Why don't we just change the default box to also be calculated by strtotime also and include suitable directions in the user interface? If you agree this would allow people to enter "4 hours", "5 days", "3 months", "1 year" e.t.c.
Also we'd need an update function that converts the role_expire_length.duration from an int to a string to store the strtotime modifier e.g. 1 day. Because altering that table will likely loose all of the data we'd need to be very careful with the update function. Perhaps the update function would first add a new column to keep the duration, migrate the rows by doing something like
When this is complete we could drop the original column. We might have to make the update function batch the conversion. I'd still like the resulting column to be called duration at the end of the update.
Thoughts?
Comment #18
sharplesa commentedI've thought long about your approach, and can't think of any way to improve it, except that _validate() needs to be solid.
So, unless you see something else, our direction is pretty clear. And of course, this should be done for 7.x as well. Were you going to work on this, or were you looking for someone else to?
Comment #19
sharplesa commentedI'll give it a go.
Comment #20
sharplesa commentedPatch for your review:
NOTE: There is one functional behavior change. Default durations now generate expiration dates that are relative to the date and time the role was added to the user. Previously, the time was always midnight.
Changes
function role_expire_get_default_durationfunction role_expire_set_default_durationfunction role_expire_form_user_admin_role_alterfunction role_expire_user_admin_role_validatefunction role_expire_add_expiration_inputY-m-d H:i:s.function role_expire_process_default_role_duration_for_userHow to Test
Setup (before applying this patch)
Tests
Comment #21
sharplesa commentedIf this is OK, I'll create a 7.x patch as well.
Comment #22
stewsnoozeHi,
This is great. A small point.
We should always assume the users are not programmers so lets leave in an indication that this is a strtotime compatible function but have examples in there of working parameters. Something like...
Thoughts?
Comment #23
sharplesa commentedGood point, Stew. Here's the update. Some important comments:
check_plain()calls in role_expire_user_admin_role_validate() and role_expire_set_default_duration(). Don't know if that was necessary since strtotime gets mad pretty easily.Comment #24
stewsnoozedb_change_field will drop the column and re add it for postgres which will result in a loss of data. You can use "USING to_char" or similar for postgres. I wonder whether we have any postgres users? I guess we should assume we do have some.
Comment #25
sharplesa commentedAre you sure you'll lose data? When I look at the code for db_change_field (http://api.drupal.org/api/drupal/includes--database.pgsql.inc/function/d...), it looks like it:
1. Renames the original column to {orig}_old.
2. Creates a new column called {orig}.
3. Calls update_sql with a CAST to convert the old type to a new type as it puts data from {orig}_old into {orig}.
I've never used postgresql and don't know if this is sufficient to handle it, but it looks to me like it should.
Comment #26
stewsnoozeGo for it then!
Comment #27
sharplesa commentedWhat version would you say this should be? 1.10 or 2.0?
Comment #28
stewsnoozeI would say 1.10 as we haven't added a lot of extra features but if you feel strongly about 2 then go for it.
Comment #29
sharplesa commentedFixed and now addressed in the new release 6.x-1.10 that incorporates the patch at #23.
Comment #30
stewsnoozeYAY! Congrats andy on your first role expire release.
@stella We'd love some feedback on whether this fixes your problem.