function user_relationships_cron in User Relationships 7
Same name and namespace in other branches
- 5 user_relationships_hooks.inc \user_relationships_cron()
- 5.2 user_relationships_hooks.inc \user_relationships_cron()
Implements hook_cron()
File
- ./
user_relationships.module, line 318 - User Relationships API. Module shell.
Code
function user_relationships_cron() {
$now = REQUEST_TIME;
// only expire relationships once a day
$last_cron = variable_get('user_relationships_last_expire', 0);
if ($now < $last_cron + 86400) {
return FALSE;
}
$result = db_query(" SELECT ur.rid\n FROM {user_relationships} ur\n INNER JOIN {user_relationship_types} urt ON ur.rtid = urt.rtid\n WHERE ur.approved = 0\n AND urt.expires_val > 0\n AND ur.changed < (:now - (urt.expires_val * 86400))\n GROUP BY ur.rid", array(
':now' => $now,
));
$expired_requests = $result
->fetchCol();
if (count($expired_requests)) {
db_delete('user_relationships')
->condition('rid', $expired_requests)
->execute();
//FIXME: this will trigger various hook_user_relationships() but will not pass a valid relationship object. E.g. in mailer.
module_invoke_all('user_relationships_delete', $expired_requests);
}
// remember when we last expired relationships
variable_set('user_relationships_last_expire', $now);
return TRUE;
}