$this->verifyFiles($check, $results);
}
- /**
- * Test searching by tag
- */
- function testSearchByTag() {
- $userId = \OC::$server->getUserSession()->getUser()->getUId();
- $id1 = $this->sharedCache->get('bar.txt')['fileid'];
- $id2 = $this->sharedCache->get('subdir/another too.txt')['fileid'];
- $id3 = $this->sharedCache->get('subdir/not a text file.xml')['fileid'];
- $id4 = $this->sharedCache->get('subdir/another.txt')['fileid'];
- $tagManager = \OC::$server->getTagManager()->load('files', [], false, $userId);
- $tagManager->tagAs($id1, 'tag1');
- $tagManager->tagAs($id1, 'tag2');
- $tagManager->tagAs($id2, 'tag1');
- $tagManager->tagAs($id3, 'tag1');
- $tagManager->tagAs($id4, 'tag2');
- $results = $this->sharedStorage->getCache()->searchByTag('tag1', $userId);
- $check = array(
- array(
- 'name' => 'bar.txt',
- 'path' => 'bar.txt'
- ),
- array(
- 'name' => 'another too.txt',
- 'path' => 'subdir/another too.txt'
- ),
- array(
- 'name' => 'not a text file.xml',
- 'path' => 'subdir/not a text file.xml'
- ),
- );
- $this->verifyFiles($check, $results);
- $tagManager->delete(array('tag1', 'tag2'));
- }
-
- /**
- * Test searching by tag for multiple sections of the tree
- */
- function testSearchByTagTree() {
- $userId = \OC::$server->getUserSession()->getUser()->getUId();
- $this->sharedStorage->mkdir('subdir/emptydir');
- $this->sharedStorage->mkdir('subdir/emptydir2');
- $this->ownerStorage->getScanner()->scan('');
- $allIds = array(
- $this->sharedCache->get('')['fileid'],
- $this->sharedCache->get('bar.txt')['fileid'],
- $this->sharedCache->get('subdir/another too.txt')['fileid'],
- $this->sharedCache->get('subdir/not a text file.xml')['fileid'],
- $this->sharedCache->get('subdir/another.txt')['fileid'],
- $this->sharedCache->get('subdir/emptydir')['fileid'],
- $this->sharedCache->get('subdir/emptydir2')['fileid'],
- );
- $tagManager = \OC::$server->getTagManager()->load('files', [], false, $userId);
- foreach ($allIds as $id) {
- $tagManager->tagAs($id, 'tag1');
- }
- $results = $this->sharedStorage->getCache()->searchByTag('tag1', $userId);
- $check = array(
- array(
- 'name' => 'shareddir',
- 'path' => ''
- ),
- array(
- 'name' => 'bar.txt',
- 'path' => 'bar.txt'
- ),
- array(
- 'name' => 'another.txt',
- 'path' => 'subdir/another.txt'
- ),
- array(
- 'name' => 'another too.txt',
- 'path' => 'subdir/another too.txt'
- ),
- array(
- 'name' => 'emptydir',
- 'path' => 'subdir/emptydir'
- ),
- array(
- 'name' => 'emptydir2',
- 'path' => 'subdir/emptydir2'
- ),
- array(
- 'name' => 'not a text file.xml',
- 'path' => 'subdir/not a text file.xml'
- ),
- );
- $this->verifyFiles($check, $results);
- $tagManager->delete(array('tag1'));
- }
-
function testGetFolderContentsInRoot() {
$results = $this->user2View->getDirectoryContent('/');
return $this->searchResultToCacheEntries($result);
}
- /**
- * Search for files by tag of a given users.
- *
- * Note that every user can tag files differently.
- *
- * @param string|int $tag name or tag id
- * @param string $userId owner of the tags
- * @return ICacheEntry[] file data
- */
- public function searchByTag($tag, $userId) {
- $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' .
- '`mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, ' .
- '`encrypted`, `etag`, `permissions`, `checksum` ' .
- 'FROM `*PREFIX*filecache` `file`, ' .
- '`*PREFIX*vcategory_to_object` `tagmap`, ' .
- '`*PREFIX*vcategory` `tag` ' .
- // JOIN filecache to vcategory_to_object
- 'WHERE `file`.`fileid` = `tagmap`.`objid` ' .
- // JOIN vcategory_to_object to vcategory
- 'AND `tagmap`.`type` = `tag`.`type` ' .
- 'AND `tagmap`.`categoryid` = `tag`.`id` ' .
- // conditions
- 'AND `file`.`storage` = ? ' .
- 'AND `tag`.`type` = \'files\' ' .
- 'AND `tag`.`uid` = ? ';
- if (is_int($tag)) {
- $sql .= 'AND `tag`.`id` = ? ';
- } else {
- $sql .= 'AND `tag`.`category` = ? ';
- }
- $result = $this->connection->executeQuery(
- $sql,
- [
- $this->getNumericStorageId(),
- $userId,
- $tag
- ]
- );
-
- $files = $result->fetchAll();
-
- return array_map(function (array $data) {
- return self::cacheEntryFromData($data, $this->mimetypeLoader);
- }, $files);
- }
-
/**
* Re-calculate the folder size and the size of all parent folders
*
return [];
}
- public function searchByTag($tag, $userId) {
- return [];
- }
-
public function searchQuery(ISearchQuery $query) {
return [];
}
return $results;
}
- /**
- * search for files by mimetype
- *
- * @param string|int $tag name or tag id
- * @param string $userId owner of the tags
- * @return array
- */
- public function searchByTag($tag, $userId) {
- $results = $this->getCache()->searchByTag($tag, $userId);
- return $this->formatSearchResults($results);
- }
-
/**
* update the folder size and the size of all parent folders
*
return array_map(array($this, 'formatCacheEntry'), $results);
}
- /**
- * search for files by tag
- *
- * @param string|int $tag name or tag id
- * @param string $userId owner of the tags
- * @return ICacheEntry[] file data
- */
- public function searchByTag($tag, $userId) {
- $results = $this->getCache()->searchByTag($tag, $userId);
- return array_map(array($this, 'formatCacheEntry'), $results);
- }
-
/**
* update the folder size and the size of all parent folders
*
return [];
}
- public function searchByTag($tag, $userId) {
- return [];
- }
-
public function getIncomplete() {
return [];
}
*/
public function searchQuery(ISearchQuery $query);
- /**
- * Search for files by tag of a given users.
- *
- * Note that every user can tag files differently.
- *
- * @param string|int $tag name or tag id
- * @param string $userId owner of the tags
- * @return ICacheEntry[] file data
- * @since 9.0.0
- * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this
- */
- public function searchByTag($tag, $userId);
-
/**
* find a folder in the cache which has not been fully scanned
*
$this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
}
- function testSearchByTag() {
- $userId = $this->getUniqueId('user');
- \OC::$server->getUserManager()->createUser($userId, $userId);
- $this->loginAsUser($userId);
- $user = new \OC\User\User($userId, null, \OC::$server->getEventDispatcher());
-
- $file1 = 'folder';
- $file2 = 'folder/foobar';
- $file3 = 'folder/foo';
- $file4 = 'folder/foo2';
- $file5 = 'folder/foo3';
- $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
- $fileData = array();
- $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
- $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
- $fileData['foo2'] = array('size' => 25, 'mtime' => 28, 'mimetype' => 'foo/file');
- $fileData['foo3'] = array('size' => 88, 'mtime' => 34, 'mimetype' => 'foo/file');
-
- $id1 = $this->cache->put($file1, $data1);
- $id2 = $this->cache->put($file2, $fileData['foobar']);
- $id3 = $this->cache->put($file3, $fileData['foo']);
- $id4 = $this->cache->put($file4, $fileData['foo2']);
- $id5 = $this->cache->put($file5, $fileData['foo3']);
-
- $tagManager = \OC::$server->getTagManager()->load('files', [], false, $userId);
- $this->assertTrue($tagManager->tagAs($id1, 'tag1'));
- $this->assertTrue($tagManager->tagAs($id1, 'tag2'));
- $this->assertTrue($tagManager->tagAs($id2, 'tag2'));
- $this->assertTrue($tagManager->tagAs($id3, 'tag1'));
- $this->assertTrue($tagManager->tagAs($id4, 'tag2'));
-
- // use tag name
- $results = $this->cache->searchByTag('tag1', $userId);
-
- $this->assertEquals(2, count($results));
-
- usort($results, function ($value1, $value2) {
- return $value1['name'] >= $value2['name'];
- });
-
- $this->assertEquals('folder', $results[0]['name']);
- $this->assertEquals('foo', $results[1]['name']);
-
- // use tag id
- $tags = $tagManager->getTagsForUser($userId);
- $this->assertNotEmpty($tags);
- $tags = array_filter($tags, function ($tag) {
- return $tag->getName() === 'tag2';
- });
- $results = $this->cache->searchByTag(current($tags)->getId(), $userId);
- $this->assertEquals(3, count($results));
-
- usort($results, function ($value1, $value2) {
- return $value1['name'] >= $value2['name'];
- });
-
- $this->assertEquals('folder', $results[0]['name']);
- $this->assertEquals('foo2', $results[1]['name']);
- $this->assertEquals('foobar', $results[2]['name']);
-
- $tagManager->delete('tag1');
- $tagManager->delete('tag2');
-
- $this->logout();
- $user = \OC::$server->getUserManager()->get($userId);
- if ($user !== null) {
- $user->delete();
- }
- }
-
function testSearchQueryByTag() {
$userId = static::getUniqueID('user');
\OC::$server->getUserManager()->createUser($userId, $userId);
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
}
- public function testSearchByTag() {
- $manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
- */
- $view = $this->createMock(View::class);
- $root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
- $root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $storage = $this->createMock(Storage::class);
- $storage->method('getId')->willReturn('');
- $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
-
- $mount = $this->createMock(IMountPoint::class);
- $mount->expects($this->once())
- ->method('getStorage')
- ->will($this->returnValue($storage));
- $mount->expects($this->once())
- ->method('getInternalPath')
- ->will($this->returnValue('foo'));
-
- $storage->expects($this->once())
- ->method('getCache')
- ->will($this->returnValue($cache));
-
- $cache->expects($this->once())
- ->method('searchByTag')
- ->with('tag1', 'user1')
- ->will($this->returnValue(array(
- array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
- )));
-
- $root->expects($this->once())
- ->method('getMountsIn')
- ->with('/bar/foo')
- ->will($this->returnValue(array()));
-
- $root->expects($this->once())
- ->method('getMount')
- ->with('/bar/foo')
- ->will($this->returnValue($mount));
-
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
- $result = $node->searchByTag('tag1', 'user1');
- $this->assertEquals(1, count($result));
- $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
- }
-
public function testSearchSubStorages() {
$manager = $this->createMock(Manager::class);
/**
$this->assertSame([], $this->cache->searchByMime('foo'));
}
- public function testSearchByTag() {
- $this->assertSame([], $this->cache->searchByTag('foo', 'user'));
- }
-
public function testGetIncomplete() {
$this->assertSame([], $this->cache->getIncomplete());
}