You are here

function _pathauto_existing_alias_data in Pathauto 5.2

Same name and namespace in other branches
  1. 6.2 pathauto.inc \_pathauto_existing_alias_data()
  2. 6 pathauto.inc \_pathauto_existing_alias_data()
  3. 7 pathauto.inc \_pathauto_existing_alias_data()

Returns old alias and pid if there is already an alias pointing to a different item.

Parameters

$src: A string that is the internal path.

Return value

An array with the keys "pid" and "old_alias" containing the "pid" and old "alias", respectively, of the old alias.

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

File

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

Code

function _pathauto_existing_alias_data($src) {
  $output = array(
    'pid' => '',
    'old_alias' => '',
  );
  $result = db_query("SELECT pid, dst FROM {url_alias} WHERE src='%s'", $src);
  if ($data = db_fetch_object($result)) {

    // The item is already aliased, check what to do...
    switch (variable_get('pathauto_update_action', 2)) {

      // Replace old alias - remember the pid to update
      case 2:
      case 3:
        $output['pid'] = $data->pid;

      // Add new alias in addition to old one
      case 1:
        $output['old_alias'] = $data->dst;
        break;

      // Do nothing
      case 0:
      default:
        break;
    }
  }
  return $output;
}