API - Reverse Lookup. path_redirect_load()
mikeytown2 - May 2, 2009 - 21:29
| Project: | Path redirect |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Given the new path, I would like to get all the redirects pointing to the new path. This is for #443736: Smarter boost_cache_expire(). Path Changes & Wildcard Support

#1
You should be able to do:
<?php$redirect = path_redirect_load(array('redirect' => 'the/path/getting/redirect/to'));
?>
#2
path_redirect_load() only returns the first value. Most of the time there is a loop on the db_fetch_object() operation correct? Example: actions_get_all_actions()
<?php
/**
* Retrieve a specific URL redirect from the database.
*/
function path_redirect_load($where = array(), $args = array(), $sort = array()) {
if (is_numeric($where)) {
$where = array('rid' => $where);
}
foreach ($where as $key => $value) {
if (is_string($key)) {
$args[] = $value;
$where[$key] = $key .' = '. (is_numeric($value) ? '%d' : "'%s'");
}
}
if ($where && $args) {
$sql = "SELECT * FROM {path_redirect} WHERE ". implode(' AND ', $where);
if ($sort) {
$sql .= ' ORDER BY '. implode(' ,', $sort);
return db_fetch_object(db_query_range($sql, $args, 0, 1));
}
}
}
?>
Looks like
if ($sort)is missing it's ending}as well.#3
Here's how I would like that function to work.
#4
Ah I see now how you would want it used: #443736: Smarter boost_cache_expire(). Path Changes & Wildcard Support.
[Edit: Um, d'oh! You already linked to this in the original post. Sorry!]
#5
I'd support a path_load_multiple_by_path() function. I'm getting rid of that stupid query load function. Now it's only path_redirect_load($rid) for menu loaders and things that know rids, and path_redirect_load_by_path($path, $language).
#6
As a part of #168877: Path-redirect as an option on the node form (add or edit) there is now a path_redirect_load_multiple_by_redirect() function available which is exactly what you're needing I think. Keep in mind APIs are not yet finalized as we're going through a lot of revision and updating before porting to Drupal 7.
#7
Thanks for doing it, I won't use this API right away then; but for the 7.x port of boost, I probably will from the get go.
#8
Automatically closed -- issue fixed for 2 weeks with no activity.