summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-12-21 19:33:47 -0800
committerBharat Mediratta <bharat@menalto.com>2010-12-21 19:33:47 -0800
commitd9299f3b3f4b1a52f5b68399cfcaa96d5b367899 (patch)
tree6d9f094d5a90c3bdbb11779e7b40573c4965f784 /modules/gallery/helpers
parent2a08cbf76da0f9984c0e182e6c448b516d8d7db3 (diff)
Change item::find_by_path() to check the relative_path_cache first,
and only fall back the name/level comparison if there's no cached entry. Update tests accordingly.
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/item.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 08a04ad0..bac189f4 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -211,6 +211,7 @@ class item_Core {
/**
* Find an item by its path. If there's no match, return an empty Item_Model.
+ * NOTE: the caller is responsible for performing security checks on the resulting item.
* @param string $path
* @return object Item_Model
*/
@@ -222,6 +223,21 @@ class item_Core {
return item::root();
}
+ // Check to see if there's an item in the database with a matching relative_path_cache value.
+ // Since that field is urlencoded, we must urlencoded the components of the path.
+ foreach (explode("/", $path) as $part) {
+ $encoded_array[] = rawurlencode($part);
+ }
+ $encoded_path = join("/", $encoded_array);
+ $item = ORM::factory("item")
+ ->where("relative_path_cache", "=", $encoded_path)
+ ->find();
+ if ($item->loaded()) {
+ return $item;
+ }
+
+ // Since the relative_path_cache field is a cache, it can be unavailable. If we don't find
+ // anything, fall back to checking the path the hard way.
$paths = explode("/", $path);
foreach (ORM::factory("item")
->where("name", "=", end($paths))