You are here

function userpoints_expire_transactions in User Points 6

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_expire_transactions()
  2. 7.2 userpoints.module \userpoints_expire_transactions()
  3. 7 userpoints.module \userpoints_expire_transactions()
1 call to userpoints_expire_transactions()
userpoints_cron in ./userpoints.module

File

./userpoints.module, line 1637

Code

function userpoints_expire_transactions() {
  $sql = "SELECT txn_id, uid, points, time_stamp, operation, description\n          FROM {userpoints_txn}\n          WHERE status = 0 AND expired = 0\n          AND (expirydate < %d AND expirydate != 0)";
  $results = db_query($sql, time());
  while ($line = db_fetch_array($results)) {
    $line['time_stamp'] = format_date($line['time_stamp'], 'custom', 'Y-m-d H:i');
    $description = t(variable_get(USERPOINTS_EXPIRY_DESCRIPTION, NULL), array_merge(userpoints_translation(), array(
      '!operation' => $line['operation'],
      '!description' => $line['description'],
      '!txn_id' => $line['txn_id'],
      '!date' => $line['time_stamp'],
    )));

    //$description
    $params = array(
      'points' => -$line['points'],
      'uid' => $line['uid'],
      'operation' => 'expiry',
      'description' => $description,
      'parent_txn_id' => $line['txn_id'],
      'moderate' => FALSE,
      'expirydate' => 0,
    );
    userpoints_userpointsapi($params);

    //Ok we've expired the entry lets update the original entry to set the expired flag
    $params = array(
      'txn_id' => $line['txn_id'],
      'expired' => 1,
    );
    userpoints_userpointsapi($params);
  }
}