add Cache::getFolderContent

This commit is contained in:
Robin Appelman 2012-09-23 15:25:03 +02:00
parent 4d2669f6b3
commit dcf995fff3
2 changed files with 42 additions and 0 deletions

View File

@ -44,6 +44,25 @@ class Cache {
return $data;
}
/**
* get the metadata of all files stored in $folder
*
* @param \OC\Files\File $folder
* @return array
*/
static public function getFolderContents($folder) {
$fileId = self::getId($folder);
if ($fileId > -1) {
$query = \OC_DB::prepare(
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`
FROM `*PREFIX*filecache` WHERE parent = ?');
$result = $query->execute(array($fileId));
return $result->fetchAll();
} else {
return array();
}
}
/**
* store meta data for a file or folder
*

View File

@ -78,6 +78,29 @@ class Cache extends \UnitTestCase {
$this->assertEqual(array('size' => 12, 'mtime' => 15), FileCache::get($file1));
}
public function testFolder() {
$file1 = $this->createPath('folder');
$file2 = $this->createPath('folder/bar');
$file3 = $this->createPath('folder/foo');
$data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
$fileData = array();
$fileData['bar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
$fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
FileCache::put($file1, $data1);
FileCache::put($file2, $fileData['bar']);
FileCache::put($file3, $fileData['foo']);
$content = FileCache::getFolderContents($file1);
$this->assertEqual(count($content), 2);
foreach ($content as $cachedData) {
$data = $fileData[$cachedData['name']];
foreach ($data as $name => $value) {
$this->assertEqual($value, $cachedData[$name]);
}
}
}
public function tearDown() {
FileCache::removeStorage($this->storage);
}