1 redirect.module redirect_purge_inactive_redirects(array $types = array('redirect'), $interval = NULL)

Purge inactive redirects from the database.

Parameters

$types: An array of redirect types to remove. Default is only the self-managed 'redirect'. If not provided all redirect types will be eligible for removal.

$interval: The number of seconds to subtract from the current time and used to find the inactive redirects.

Return value

array: An array of redirect IDs that were deleted.

File

core/modules/redirect/redirect.module, line 879

Code

function redirect_purge_inactive_redirects(array $types = array('redirect'), $interval = NULL) {
  if (!isset($interval)) {
    $interval = config_get('redirect.settings', 'purge_inactive');
  }
  // If there is no interval at all, do not discard any redirects.
  if (empty($interval)) {
    return array();
  }

  $query = db_select('redirect');
  $query->addField('redirect', 'rid');
  if (!empty($types)) {
    $query->condition('type', $types);
  }
  $query->condition('access', REQUEST_TIME - $interval, '<');
  $query->condition('access', 0, '<>');
  $query->addTag('redirect_purge');
  $rids = $query->execute()->fetchCol();

  if (count($rids)) {
    redirect_delete_multiple($rids);
    watchdog('redirect', format_plural(count($rids), 'Removed 1 inactive redirect from the database.', 'Removed @count inactive redirects from the database.'));
  }

  return $rids;
}