Userpoints 7.x-1.x allows modules which award points to declare their operations in hook_userpoints_info(). For these, operations is now a technical identifier and has most probably changed compared to 6.x versions.
This means that old transactions still show the untranslated operation/description.
This patch provides a simple framework that allows modules to convert existing transactions and update their operation/description to their updated ones.
It works quite simple:
- Userpoints selects all transactions which don't have a defined (through hook_userpoints_info()) operation and processes them with batch
- hook_userpoints_convert($transaction) is called for every of these transactions
- Any module that implements that hook can now "claim" such a transaction by setting the new operation and returning TRUE. If a module returns TRUE, the (updated) operation is persisted.
The advantage of this process compared to doing it during the upgrade is that it can be repeated whenever a module is enabled and it works in a fully bootstrapped with a clean state so we can use hooks and so on. Also, the modules implementing the hook only need a few lines of code, everything else is managed by userpoints.module.
Todo:
- I'm thinking about providing some statistics on that page: # unclaimed transactions and then splitted up by operation.
Patch for userpoints_nc.module follows soon. Without that, not much is going to happen :)
Comment | File | Size | Author |
---|---|---|---|
#8 | userpoints_convert2.patch | 4.6 KB | Berdir |
userpoints_convert.patch | 5.11 KB | Berdir | |
Comments
Comment #1
BerdirComment #2
BerdirWhen testing this patch, I heavily suggest to create a backup of the userpoints_txn table both to being able to restore if something goes wrong and being able to reproduce the converting.
Comment #3
BerdirWhen testing this patch, I heavily suggest to create a backup of the userpoints_txn table both to being able to restore if something goes wrong and being able to reproduce the converting.
Comment #5
BerdirComment #6
BenK CreditAttribution: BenK commentedSubscribing to help with testing.
Comment #7
BenK CreditAttribution: BenK commentedBumping this so that I don't lose track.
Comment #8
BerdirI successfully confused the testbot with my duplicate issues.
Here is a new patch, needed a re-roll anyway.
Comment #9
BenK CreditAttribution: BenK commentedHey Berdir,
I tested the latest patch and it worked well. I had old style UP-NC operations and they were successfully converted to the new format. Double-checked with phpmyadmin and everything seemed great. Here are some potential usability suggestions:
1. Do we want this as it's own tab? If so, I'd put it to left of the settings tab. But maybe it could be a vertical tab since most people aren't likely to use this a lot. Another option could be to make this its own sub-module so that only people who need it enable it. I'm just not sure if warrants a whole horizontal tab to itself.
2. Any way to provide an "undo" link to undo the most recent operation? Because this actually changes the database (even though it is a pretty harmless change), we might want a way to revert this if it has unforeseen affects (if someone clicks the "convert transactions" button by mistake). This would be especially needed if some other Userpoints-related module (one that we don't work on) incorrectly implemented the operation change. On alternate approach would be to just provide a confirmation dialog box upon clicking the button so that we're sure it was intentional.
3. Yes, a few basic statistics (like you suggested) would be great. It's nice to know whether your system needs to be updated and what will happen if you click the "convert transactions" button.
4. Probably needs a sentence or two of explanation at the top of the page. If you suggest something, I can refine it.
--Ben
Comment #10
BerdirThought about this and I think, this doesn't belong into the mail. Moving to userpoints contrib.
Comment #11
BenK CreditAttribution: BenK commented