You are here

function _pathauto_alias_exists in Pathauto 6

Same name and namespace in other branches
  1. 5.2 pathauto.inc \_pathauto_alias_exists()
  2. 5 pathauto.module \_pathauto_alias_exists()
  3. 6.2 pathauto.inc \_pathauto_alias_exists()
  4. 7 pathauto.inc \_pathauto_alias_exists()

Check to see if there is already an alias pointing to a different item.

Parameters

$alias: A string alias.

$source: A string that is the internal path.

$language: A string indicating the path's language.

Return value

TRUE if an alias exists, FALSE if not.

1 call to _pathauto_alias_exists()
pathauto_create_alias in ./pathauto.inc
Apply patterns to create an alias.

File

./pathauto.inc, line 22
Miscellaneous functions for Pathauto.

Code

function _pathauto_alias_exists($alias, $source, $language = '') {
  $pid = db_result(db_query_range("SELECT pid FROM {url_alias} WHERE src <> '%s' AND dst = '%s' AND language IN ('%s', '') ORDER BY language DESC, pid DESC", $source, $alias, $language, 0, 1));
  if (module_exists('path_redirect') && function_exists('path_redirect_delete_multiple')) {

    // Delete from path_redirect the exact same alias to the same node.
    path_redirect_delete_multiple(NULL, array(
      'source' => $alias,
      'redirect' => $source,
    ));

    // If there still is this alias used in path_redirect, then create a different alias.
    $redirects = path_redirect_load_multiple(NULL, array(
      'source' => $alias,
    ));
  }
  if ($pid || !empty($redirects)) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}