You are here

public function MigrateDestinationUserpoints::rollback in User Points 7

Delete the provided userpoint transaction.

Parameters

$id: Primary key values.

File

./userpoints.migrate.inc, line 94
Migration class for userpoint transactions.

Class

MigrateDestinationUserpoints
Destination class for migrating userpoints.

Code

public function rollback(array $id) {
  migrate_instrument_start('userpoints_txn rollback');
  $txn_id = reset($id);
  $txn = userpoints_transaction_load($txn_id);

  // We set txn to expired and status to declined and send it to the recache,
  // before we delete the entry.
  // This is necessary to decrease the user's total points.
  $del_txn = (array) $txn;
  $del_txn['expired'] = 1;
  $del_txn['status'] = USERPOINTS_TXN_STATUS_DECLINED;
  _userpoints_update_cache($del_txn, (array) $txn);

  // As there is no API function to delete, we must delete the row ourselves.
  db_delete('userpoints_txn')
    ->condition('txn_id', $txn_id)
    ->execute();
  migrate_instrument_stop('userpoints_txn rollback');
}