0

I have a dev and prod versions of my D7 site. On dev I developed some functionality based on User Points module and plan to roll out it on prod. But it requires some initial number of user points for every user.

What is the best way to add user points to existing users: SQL query, Rules etc?

1
  • There's no "best" way, only different ways. Yes you can do it with an SQL query, not sure how you'd do it with rules, or you could probably set something up with VBO. Which one is best for you depends on what you already know and how quickly you pick up new things. Have a go, and if you get stuck, ask a more specific question and you'll surely get a good answer
    – Clive
    Jul 4, 2015 at 8:48

2 Answers 2

1

One method here is to use the Userpoints API and execute a code snippet that will add the points for you. You can reference the userpoints API here. You can do something like this...

$initial_value = 10;
//@TODO: Build a list of all $uids in an array
foreach($uids as $uid) { =
  userpoints_userpointsapi(array(
    'uid' => $uid,
    'points' => $initial_value,
    'operation' => "Add Initial User Point Value",
  ));
}
1

I think User Points Contributed modules is a possible alternative to consider. I. e. submodule userpoints_retroactive. Excerpt from that project page:

Award users points for their nodes, comments and votes that they have created so far, before userpoints was enabled on the site.

However, the port of this module to D7 still needs work. Maybe you can/want to somehow contriute to the finishing touch of that issue?

Another approach to consider: create a rule with specs like so:

  • Event = a user logging in
  • Condition like "if user points is 0"
  • Action to set the initial number of user points.

Haven't actually created such rule (yet), but pretty sure that's fairly easy to do.

PS: there is also Berdir's Api documentation about this submodule ... (maybe that helps somehow).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.