You are here

function user_relationships_cron in User Relationships 5

Same name and namespace in other branches
  1. 5.2 user_relationships_hooks.inc \user_relationships_cron()
  2. 7 user_relationships.module \user_relationships_cron()

Cron

File

./user_relationships_hooks.inc, line 269

Code

function user_relationships_cron() {
  $now = time();

  // only expire relationships once a day
  $last_cron = variable_get('user_relationships_last_expire', 0);
  if ($now > $last_cron + 24 * 60 * 60) {
    return FALSE;
  }
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query(" DELETE ur\n        FROM user_relationships ur, user_relationship_types urt \n        WHERE ur.approved = 0 \n          AND ur.rtid = urt.rtid \n          AND urt.expires_val > 0 \n          AND NOW() > DATE_ADD(ur.updated_at, INTERVAL urt.expires_val DAY)");
      break;
  }

  // remember when we last expired relationships
  variable_set('user_relationships_last_expire', $now);
  return TRUE;
}