]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cache: add function to get storage id and internal path of a file by id
authorRobin Appelman <icewind@owncloud.com>
Sat, 26 Jan 2013 22:59:29 +0000 (23:59 +0100)
committerRobin Appelman <icewind@owncloud.com>
Sat, 26 Jan 2013 23:13:50 +0000 (00:13 +0100)
lib/files/cache/cache.php
tests/lib/files/cache/cache.php

index 7f6d191fee41debf101fe91b021d74da03ea20b7..69cbaea8516760b3fde33371d8c8efd6ec950088 100644 (file)
@@ -494,4 +494,28 @@ class Cache {
                        return false;
                }
        }
+
+       /**
+        * get the storage id of the storage for a file and the internal path of the file
+        *
+        * @return array, first element holding the storage id, second the path
+        */
+       static public function getById($id) {
+               $query = \OC_DB::prepare('SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
+               $result = $query->execute(array($id));
+               if ($row = $result->fetchRow()) {
+                       $numericId = $row['storage'];
+                       $path = $row['path'];
+               } else {
+                       return null;
+               }
+
+               $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?');
+               $result = $query->execute(array($numericId));
+               if ($row = $result->fetchRow()) {
+                       return array($row['id'], $path);
+               } else {
+                       return null;
+               }
+       }
 }
index 96a7623dac5f9d102dc46c41e781721f86b0c563..c466fbb63e79bda189e37d05252ce1eaf53e5896 100644 (file)
@@ -197,6 +197,13 @@ class Cache extends \PHPUnit_Framework_TestCase {
                $this->assertEquals(array(), $this->cache->getFolderContents('foo'));
        }
 
+       function testGetById() {
+               $storageId = $this->storage->getId();
+               $data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+               $id = $this->cache->put('foo', $data);
+               $this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id));
+       }
+
        public function tearDown() {
                $this->cache->clear();
        }