function userpoints_expire_transactions in User Points 7
Same name and namespace in other branches
- 5.3 userpoints.module \userpoints_expire_transactions()
- 6 userpoints.module \userpoints_expire_transactions()
- 7.2 userpoints.module \userpoints_expire_transactions()
Finds and expires expired points.
Finds all transactions with a expirydate < REQUEST_TIME and posts opposite transactions (sum of 0).
1 call to userpoints_expire_transactions()
- userpoints_cron in ./
userpoints.module - Implements hook_cron().
File
- ./
userpoints.module, line 1555
Code
function userpoints_expire_transactions() {
$sql = "SELECT txn_id, uid, points, time_stamp, operation, description, tid\n FROM {userpoints_txn}\n WHERE status = 0 AND expired = 0\n AND (expirydate < :expiry_date AND expirydate != 0)";
$result = db_query($sql, array(
':expiry_date' => REQUEST_TIME,
));
foreach ($result as $line) {
$time_stamp_formatted = format_date($line->time_stamp, 'custom', 'Y-m-d H:i');
$arguments = array_merge(userpoints_translation(), array(
'!operation' => $line->operation,
'!description' => $line->description,
'!txn_id' => $line->txn_id,
'!date' => $time_stamp_formatted,
));
$description = strtr(variable_get(USERPOINTS_EXPIRY_DESCRIPTION, NULL), $arguments);
$params = array(
'points' => -$line->points,
'uid' => $line->uid,
'operation' => 'expiry',
'description' => $description,
'parent_txn_id' => $line->txn_id,
'moderate' => FALSE,
'tid' => $line->tid,
'time_stamp' => $line->time_stamp,
'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);
}
}