function uc_roles_cron in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_roles/uc_roles.module \uc_roles_cron()
- 7.3 uc_roles/uc_roles.module \uc_roles_cron()
Implements hook_cron().
File
- uc_roles/
uc_roles.module, line 37
Code
function uc_roles_cron() {
$reminder_granularity = variable_get('uc_roles_reminder_granularity', 'never');
$reminder_qty = variable_get('uc_roles_reminder_length', NULL);
$time = time();
$sql = 'SELECT * FROM {uc_roles_expirations} WHERE expiration <= %d';
$args = array(
$time,
);
if ($reminder_granularity != 'never') {
$sql .= ' OR (notified IS NULL AND expiration <= %d)';
$args[] = _uc_roles_get_expiration($reminder_qty, $reminder_granularity, $time);
}
$result = db_query($sql, $args);
while ($expiration = db_fetch_object($result)) {
$account = user_load($expiration->uid);
// Cleanup if user or role was deleted already.
if (!$account || !in_array($expiration->rid, array_keys($account->roles))) {
uc_roles_delete($expiration, $expiration->rid, TRUE);
}
elseif ($expiration->expiration <= $time) {
ca_pull_trigger('uc_roles_notify_revoke', $account, $expiration);
uc_roles_revoke($account, $expiration->rid);
}
elseif ($reminder_granularity != 'never') {
ca_pull_trigger('uc_roles_notify_reminder', $account, $expiration);
db_query('UPDATE {uc_roles_expirations} SET notified = 1 WHERE uid = %d AND rid = %d', $account->uid, $expiration->rid);
}
}
}