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

CommentFileSizeAuthor
#3 path_redirect.patch684 bytesmikeytown2

Comments

dave reid’s picture

You should be able to do:

$redirect = path_redirect_load(array('redirect' => 'the/path/getting/redirect/to'));
mikeytown2’s picture

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()

/**
 * 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.

mikeytown2’s picture

Title: API - Reverse Lookup » API - Reverse Lookup. path_redirect_load()
Category: support » feature
Status: Active » Needs review
StatusFileSize
new684 bytes

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

dave reid’s picture

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!]

dave reid’s picture

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).

dave reid’s picture

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.

mikeytown2’s picture

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.

Status: Fixed » Closed (fixed)

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