Beispiel #1
0
 /**
  * get the file id as used in the cache
  * @param string path
  * @param string root (optional)
  * @return int
  */
 public static function getId($path, $root = false)
 {
     if ($root === false) {
         $root = OC_Filesystem::getRoot();
     }
     $fullPath = $root . $path;
     if (($cache = OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/' . $fullPath)) {
         return $cache->get('fileid/' . $fullPath);
     }
     $query = OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `path_hash`=?');
     $result = $query->execute(array(md5($fullPath)));
     if (OC_DB::isError($result)) {
         OC_Log::write('files', 'error while getting file id of ' . $path, OC_Log::ERROR);
         return -1;
     }
     $result = $result->fetchRow();
     if (is_array($result)) {
         $id = $result['id'];
     } else {
         $id = -1;
     }
     if ($cache = OC_Cache::getUserCache(true)) {
         $cache->set('fileid/' . $fullPath, $id);
     }
     return $id;
 }