D7 doesn't provide an easy way to delete a path based on a wildcard, so we have to write our own small function do it for us.

D7:

/**
 * Delete multiple URL aliases based on a wildcard source.
 *
 * Given a source like 'node/1' this function will delete any alias that have
 * that specific source or any sources that match 'node/1/%'.
 *
 * @param $source
 *   An string with a source URL path.
 */
function pathauto_path_delete_multiple($source) {
  $sql = "SELECT pid FROM {url_alias} WHERE source = :source OR source LIKE :source-wildcard";
  $pids = db_query($sql, array(':source' => $source, ':source-wildcard' => $source . '/%'))->fetchCol();
  foreach ($pids as $pid) {
    path_delete(array('pid' => $pid));
  }
}

D6:

function pathauto_path_delete_multiple($source) {
  $source = urldecode($source);
  // Delete the source path.
  db_query("DELETE FROM {url_alias} WHERE src = '%s'", $source);
  // Delete any sub-paths.
  db_query("DELETE FROM {url_alias} WHERE src LIKE '%s'", $source . '/%%');
  drupal_clear_path_cache();
}

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new3.84 KB
dave reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.