From a6a8e2c553bd2ba82c3d50f147a49793ed62b6f5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 15 Apr 2012 11:44:04 +0200 Subject: [PATCH] add public api to get the file id from the cache --- lib/filecache.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/filecache.php b/lib/filecache.php index cdd91dcbfa..24984c2ccf 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -281,6 +281,7 @@ class OC_FileCache{ /** * get the file id as used in the cache + * unlike the public getId, full paths are used here (/usename/files/foo instead of /foo) * @param string $path * @return int */ @@ -303,6 +304,39 @@ class OC_FileCache{ return -1; } } + + /** + * get the file id as used in the cache + * @param string path + * @param string root (optional) + * @return int + */ + public static function getId($path,$root=''){ + if(!$root){ + $root=OC_Filesystem::getRoot(); + } + if($root=='/'){ + $root=''; + } + $path=$root.$path; + return self::getFileId($path); + } + + /** + * get the file path from the id, relative to the home folder of the user + * @param int id + * @param string user (optional) + * @return string + */ + public static function getPath($id,$user=''){ + if(!$user){ + $user=OC_User::getUser(); + } + $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id=? AND user=?'); + $result=$query->execute(array($id,$user)); + $row=$result->fetchRow(); + return $row['path']; + } /** * get the file id of the parent folder, taking into account '/' has no parent