Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/files/cache/cache.php24
-rw-r--r--tests/lib/files/cache/cache.php7
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 7f6d191fee4..69cbaea8516 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -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;
+ }
+ }
}
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 96a7623dac5..c466fbb63e7 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -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();
}