In userpoints_basic.module, you can give users points for creating nodes. Giving points for a usernode is the (only known) possibility to offer some basic points to new users, so they could start with anything but frustrating 0 points. This works fine.
Unfortunately, each time account settings (or profile sections) are saved, the user gets the points for creation again.
Reason for this is, that userpoints_basic.module expects the saved node to be prepared before it's getting saved.
Here's the critical excerpt from userpoints_basic.module:
function userpoints_nodeapi(&$node, $op, $teaser, $page) {
static $orig_uid;
$points = variable_get(USERPOINTS_POST . $node->type, 0);
switch($op) {
// some cases
case 'prepare':
$orig_uid = $node->uid;
break;
case 'update':
if ($node->uid != $orig_uid) {
// Add to the new node owner
userpoints_userpointsapi('points',$points, $node->uid, $node->type);
// subtract from the original node owner
$points = -$points;
userpoints_userpointsapi('points',$points, $orig_uid, $node->type);
}
break;
}
}
Of course, this is not the best way of looking for new nodes or those whose owner has changed. I cannot think of a better solution and maybe this won't be the only case where usernode.module could conflict with other modules in this step.
My suggestion is to wrap the critical section in usernode.module into a node_prepare() command. There are so many functions in usernode that deal with savings that I don't know where to wrap it correctly. So please find a solution or give me a hint where to put it so I would also write a patch for it. Solutions how userpoints_basic.module could be improved instead are also welcome.
Comments
Comment #1
fagothere is no bug in usernode. If you run your code on node update, of course it runs when the usernode is updated. use op insert if you want to run it also on creation.
http://api.drupal.org/api/function/hook_nodeapi/5 says to op prepare: "The node is about to be shown on the add/edit form". This doesn't apply when usernodes are automatically created/updated, but only if the are edited explicitly.
Just an idea: what about adding a userpoint workflow-ng action? I've never user userpoints, but I think this would be really powerful and should be really easy to implement. E.g. then you could just configure an action to give a user 10 points after his registration.
Comment #2
marcor commentedThank you, fago, good idea. I'm not so deep in userpoints development. I implemented a workaround for the above problem outside of userpoints so I don't rely on that function anymore.