summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/files/cache/cache.php29
-rw-r--r--tests/lib/files/cache/cache.php26
2 files changed, 53 insertions, 2 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 138a5e6e63e..9d13b56104d 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -243,6 +243,32 @@ class Cache {
}
/**
+ * Move a file or folder in the cache
+ *
+ * @param string $source
+ * @param string $target
+ */
+ public function move($source, $target) {
+ $sourceId = $this->getId($source);
+ $newParentId = $this->getParentId($target);
+
+ //find all child entries
+ $query = \OC_DB::prepare('SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?');
+ $result = $query->execute(array($source . '/%'));
+ $childEntries = $result->fetchAll();
+ $sourceLength = strlen($source);
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?');
+
+ foreach ($childEntries as $child) {
+ $targetPath = $target . substr($child['path'], $sourceLength);
+ $query->execute(array($targetPath, md5($targetPath), $child['fileid']));
+ }
+
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `parent` =? WHERE `fileid` = ?');
+ $query->execute(array($target, md5($target), $newParentId, $sourceId));
+ }
+
+ /**
* remove all entries for files that are stored on the storage from the cache
*/
public function clear() {
@@ -296,8 +322,7 @@ class Cache {
/**
* search for files by mimetype
*
- * @param string $part1
- * @param string $part2
+ * @param string $mimetype
* @return array
*/
public function searchByMime($mimetype) {
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 4f22e9bd1d9..9c469aa9374 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -149,6 +149,32 @@ class Cache extends \UnitTestCase {
$this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
}
+ function testMove() {
+ $file1 = 'folder';
+ $file2 = 'folder/bar';
+ $file3 = 'folder/foo';
+ $file4 = 'folder/foo/1';
+ $file5 = 'folder/foo/2';
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar');
+
+ $this->cache->put($file1, $data);
+ $this->cache->put($file2, $data);
+ $this->cache->put($file3, $data);
+ $this->cache->put($file4, $data);
+ $this->cache->put($file5, $data);
+
+ $this->cache->move('folder/foo', 'folder/foobar');
+
+ $this->assertFalse($this->cache->inCache('folder/foo'));
+ $this->assertFalse($this->cache->inCache('folder/foo/1'));
+ $this->assertFalse($this->cache->inCache('folder/foo/2'));
+
+ $this->assertTrue($this->cache->inCache('folder/bar'));
+ $this->assertTrue($this->cache->inCache('folder/foobar'));
+ $this->assertTrue($this->cache->inCache('folder/foobar/1'));
+ $this->assertTrue($this->cache->inCache('folder/foobar/2'));
+ }
+
public function tearDown() {
$this->cache->clear();
}