Userpoints Evaporate 1.0

Well, I finally got a revision 1.0 out the door for one of my Drupal modules.  A fact I thought I'd celebrate with a blog.

The module with this honour is the most recent one I started, userpoints_evaporate, just over a week ago.

I guess it's a nice example of why open source is cool. Someone on the #drupal-support channel on Freenode asked if anyone knew whether an existing module could do what he wanted, which was essentially use the UserPoints module (which works kind of like karma on Launchpad) to automatically expire a set number of points for all users every hour or day (again, kind of like karma on Launchpad).

The existing modules can add an expiry date to any given points transaction, but can't expire a set number from all users in a batch run. Not any of the Drupal 6.x compatible modules, anyway.

After having a look at the hook_cron api docs and the userpoints module schema, I reckoned it shouldn't be too hard to just run an update query on the userpoints table and set points = points - 1, so I offered to have a go at it.

About an hour later I had a working module that essentially did what was needed. A bit more work added an administrative UI to set some options as well. The only problem turned out to be that because a cron run doesn't always take exactly the same amount of time, it's possible the module's cron hook gets fired after 59 minutes, instead of an hour. That would cause it to skip the occasional run. Bad.

The fix is easy though, just store the last run time minus a few minutes. I did that this morning, so now version 1.0 is out for all to enjoy :-)  Next step: getting it added to userpoints_contrib.

Add new comment