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

Dave Reid - May 2, 2009 - 22:05

You should be able to do:

<?php
$redirect
= path_redirect_load(array('redirect' => 'the/path/getting/redirect/to'));
?>

#2

mikeytown2 - May 2, 2009 - 22:53

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

mikeytown2 - May 5, 2009 - 01:40
Title:API - Reverse Lookup» API - Reverse Lookup. path_redirect_load()
Category:support request» feature request
Status:active» needs review

Here's how I would like that function to work.

AttachmentSize
path_redirect.patch 684 bytes

#4

Dave Reid - May 31, 2009 - 14:48

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

Dave Reid - October 27, 2009 - 04:43
Status:needs review» needs work

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

Dave Reid - November 27, 2009 - 03:07
Status:needs work» fixed

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

mikeytown2 - November 27, 2009 - 03:27

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

System Message - December 11, 2009 - 03:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.