diff --git a/uc_roles/uc_roles.module b/uc_roles/uc_roles.module index 9739964..cdd3bf7 100644 --- a/uc_roles/uc_roles.module +++ b/uc_roles/uc_roles.module @@ -31,7 +31,14 @@ function uc_roles_cron() { $reminder_granularity = variable_get('uc_roles_reminder_granularity', 'never'); $reminder_qty = variable_get('uc_roles_reminder_length', NULL); - $result = db_query("SELECT * FROM {uc_roles_expirations}"); + $sql = 'SELECT * FROM {uc_roles_expirations} WHERE expiration <= :expiration'; + $args = array(':expiration' => REQUEST_TIME); + if ($reminder_granularity != 'never') { + $sql .= ' OR (notified IS NULL AND expiration <= :reminder)'; + $args[':reminder'] = _uc_roles_get_expiration($reminder_qty, $reminder_granularity, REQUEST_TIME); + } + $result = db_query($sql, $args); + foreach ($result as $expiration) { $account = user_load($expiration->uid); @@ -47,23 +54,13 @@ function uc_roles_cron() { } // Remind the user about an upcoming expiration. - elseif ($reminder_granularity != 'never') { - // Only if not already notified. - if (intval($expiration->notified) >= 1) { - continue; - } - - // If we're past the expiration time minus the reminder time. - $threshold = _uc_roles_get_expiration(-$reminder_qty, $reminder_granularity, $expiration->expiration); - if ($threshold <= REQUEST_TIME) { - rules_invoke_event('uc_roles_notify_reminder', $account, $expiration); - - db_update('uc_roles_expirations') - ->fields(array('notified' => 1)) - ->condition('uid', $account->uid) - ->condition('rid', $expiration->rid) - ->execute(); - } + else { + rules_invoke_event('uc_roles_notify_reminder', $account, $expiration); + db_update('uc_roles_expirations') + ->fields(array('notified' => 1)) + ->condition('uid', $account->uid) + ->condition('rid', $expiration->rid) + ->execute(); } } }