You are here

function flag_session_api_cleanup in Flag 7.3

Same name and namespace in other branches
  1. 6.2 flag.module \flag_session_api_cleanup()
  2. 7.2 flag.module \flag_session_api_cleanup()

Implements hook_session_api_cleanup().

Clear out anonymous user flaggings during Session API cleanup.

File

./flag.module, line 1264
The Flag module.

Code

function flag_session_api_cleanup($arg = 'run') {

  // Session API 1.1 version:
  if ($arg == 'run') {
    $query = db_select('flagging', 'fc');
    $query
      ->leftJoin('session_api', 's', 'fc.sid = s.sid');
    $result = $query
      ->fields('fc', array(
      'sid',
    ))
      ->condition('fc.sid', 0, '<>')
      ->isNull('s.sid')
      ->execute();
    foreach ($result as $row) {
      db_delete('flagging')
        ->condition('sid', $row->sid)
        ->execute();
    }
  }
  elseif (is_array($arg)) {
    $outdated_sids = $arg;
    db_delete('flagging')
      ->condition('sid', $outdated_sids, 'IN')
      ->execute();
  }
}