add Cache::move
This commit is contained in:
parent
e312c142dc
commit
8a6bb7965d
2 changed files with 53 additions and 2 deletions
29
lib/files/cache/cache.php
vendored
29
lib/files/cache/cache.php
vendored
|
@ -242,6 +242,32 @@ class Cache {
|
|||
$query->execute(array($entry['fileid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -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) {
|
||||
|
|
26
tests/lib/files/cache/cache.php
vendored
26
tests/lib/files/cache/cache.php
vendored
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue