You are here

function redirect_delete_by_path in Redirect 7

Same name and namespace in other branches
  1. 8 redirect.module \redirect_delete_by_path()
  2. 7.2 redirect.module \redirect_delete_by_path()

Delete any redirects associated with a path or any of its sub-paths.

Given a source like 'node/1' this function will delete any redirects that have that specific source or any sources that match 'node/1/%'.

Parameters

$path: An string with an internal Drupal path.

Related topics

1 call to redirect_delete_by_path()
redirect_delete_by_entity_path in ./redirect.module
Delete an entity URL alias and any of its sub-paths.

File

./redirect.module, line 922

Code

function redirect_delete_by_path($path) {
  $query = db_select('redirect');
  $query
    ->addField('redirect', 'rid');
  $query_or = db_or();
  if (variable_get('redirect_delete_by_source_path', TRUE)) {
    $query_or
      ->condition('source', db_like($path), 'LIKE');
    $query_or
      ->condition('source', db_like($path . '/') . '%', 'LIKE');
  }
  $query_or
    ->condition('redirect', db_like($path), 'LIKE');
  $query_or
    ->condition('redirect', db_like($path . '/') . '%', 'LIKE');
  $query
    ->condition($query_or);
  $rids = $query
    ->execute()
    ->fetchCol();
  if ($rids) {
    return redirect_delete_multiple($rids);
  }
}