OK, I moved this out from migrate_points and removed the submodule. I did not add this to hook_migrate_api() because it is still waiting on a userpoints patch from april. If people could help test that and get it committed, we'll test this and finish it up.

#441678: Use drupal_write_record(). Needed to be able to import transactions with migrate_extras

#11 userpoints_migrate-689702-11.patch5.34 KBderhasi
Test request sent.
[ View ]


Version:master» 7.x-2.x-dev
Component:migrate_extras» Migrate Extras Features
Status:Postponed» Active

Moving request to V2.

I'm gonna need this ^^

Frankcarey, could you link to the April patch that needs testing, if it still needs testing, or are userpoints now ready to go?



frankcarey, that's a patch from April of 2009?! Does that even apply to the D7 version?

Any other way to get the userpoints imported?



And there is no any chance to get this working?

I ended up writing a custom script that would used the userpoints_userpointsapi() function to "import" the points.

mototribe, can you share?

//retrieve points from your import table
$result = mysql_query("SELECT uid, points FROM ...", $con);
    if (!
$result) {
'Invalid query: ' . mysql_error());
//loop over the results
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$uid = $row['uid'];
$points = $row['points'];
$params = array (
'uid' => $uid,
'points' => $points,
'description' => '....'
$ret = userpoints_userpointsapi($params);

Please, somebody to help me.
I whant to migrate XML content to custom nodes. It's ok. The question is how to get the id whitch is an atribute.
xml: (i put () instad of angle brackets)
(aaa id='1')

what about:
$item_xpath = '/main/aaa';
$item_ID_xpath = '@id ';
$items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);


$this->map = new MigrateSQLMap($this->machineName,
'id' => array( //****WHAT TO DO WITH THE ID
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,


Title:Userpoints IntegrationMigration support for User Points
Project:Migrate Extras» User Points
Component:Migrate Extras Features» Code: userpoints

Migration support for a contrib module would best go into that module.

Version:7.x-2.x-dev» 7.x-1.0
Assigned:frankcarey» Unassigned
Status:Active» Needs review
new5.34 KB
Test request sent.
[ View ]

I needed migration support for a project of mine, so I wrote a patch implementing basic migration for Userpoints 1.0

Patch attached ;)

Version:7.x-1.0» 7.x-1.x-dev

Thanks, looks good, can you improve these comments a bit and then I'm happy to commit this.

+++ b/userpoints.migrate.incundefined
@@ -0,0 +1,145 @@
+  public function __toString() {
+    return t('userpoints');

I'm not exactly sure where this is displayed, be we usually use 'User Points' in user facing strings.

Also, this and the one below should have a simple docblock. According to the current coding standards, that would be Overrides/Implements Class/Interface::method().

+++ b/userpoints.migrate.incundefined
@@ -0,0 +1,145 @@
+   * Importing given item as userpoints transaction.
+   *
+   * @param stdClass $entity
+   * @param stdClass $row
+   * @return array|bool
+   */
+  function import(stdClass $entity, stdClass $row) {

I assume this is the implementation of a interface method, then the @params and @return isn't necessary and it should just state Implements ... as described above.

Same for those below.

Any news on this?

I have applied this patch but the migration doesn't appear in the Migrate UI. Is there something else that needs doing for this to work?

I am attempting to migrate user points with the method described by @mototribe, but it's not working for me. I am on 7.x-1.0, I have a function that is called in my complete() for the user migration class that ( successfully ) pulls the user's points from my D6 userpoints_txn table, sets the parameters for each record in an array.

However, as soon as I loop over my array of user points and call userpoints_userpointsapi($params), it completely fails. It stops the foreach, gives no error or message.

This is what my setup looks like:

function mymigration_userpoints($new_uid, $old_uid) {
$query = Database::getConnection('default', 'for_migration') // this is the connection to my old db, this part works.
->select('userpoints_txn', 'up')
fields('up', array('points', 'time_stamp', 'description', 'tid'))
condition('up.uid', $old_uid, '=')
condition('up.status', '0', '=');
$points_result = $query->execute()->fetchAll();  // so far so good, I am getting my old records just fine.
   //print_r($points_result);  // when uncommented, it gives an array of results that look correct
   // now I want to loop over the results
foreach ($points_result as $points_data) {
$time_stamp = $points_data->time_stamp;
$points = $points_data->points;
$description = $points_data->description;
$tid = mapValues('points', $points_data->tid);  // this is supurfluous, it merely maps the old tid to my new tid, works.
$params = array(
'uid' => $new_uid,
'points' => $points,
'description' => t('Migrated Giving Points'),
'tid' => $tid,
'moderate' => FALSE,
// print_r($params);  // when uncommented, gives only the first result in the loop, because it dies when the next part is called
$ret = userpoints_userpointsapi($params);

I have attempted to break down my params array to the bear minimum, even just 'uid' and 'points', but it still fails, and fails hard.

= array(
'uid' => $new_uid,
'points' => 10,

I am using very similar code in another module, for scoring Quiz ( I needed some more flexibility for the points ). I use the same params array, the same call to userpoints_userpointsapi($params). I even tried hard coding the values in the array. Nothing works for me.

To summarize, in my custom migration, anytime I call userpoints_userpointsapi(), it completely stops propagation, does not add points, does not pass "Go", does not collect $200. Using 7.x-1.0. Works in other modules.

Any ideas of how I am doing this wrong?