From: Roeland Jago Douma Date: Thu, 18 Jul 2019 13:06:55 +0000 (+0200) Subject: Remove deprecated searchByTag X-Git-Tag: v17.0.0beta1~89^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F16456%2Fhead;p=nextcloud-server.git Remove deprecated searchByTag Signed-off-by: Roeland Jago Douma --- diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index c891f56f3d3..7bcb707a82b 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -238,96 +238,6 @@ class CacheTest extends TestCase { $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('/'); diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 6843c3166ae..6958e07be56 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -723,52 +723,6 @@ class Cache implements ICache { 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 * diff --git a/lib/private/Files/Cache/FailedCache.php b/lib/private/Files/Cache/FailedCache.php index b64d66dc697..8fb1623894c 100644 --- a/lib/private/Files/Cache/FailedCache.php +++ b/lib/private/Files/Cache/FailedCache.php @@ -115,10 +115,6 @@ class FailedCache implements ICache { return []; } - public function searchByTag($tag, $userId) { - return []; - } - public function searchQuery(ISearchQuery $query) { return []; } diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 7e113d13678..44402e3382a 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -247,18 +247,6 @@ class CacheJail extends CacheWrapper { 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 * diff --git a/lib/private/Files/Cache/Wrapper/CacheWrapper.php b/lib/private/Files/Cache/Wrapper/CacheWrapper.php index 223e678f323..6d7f1876e29 100644 --- a/lib/private/Files/Cache/Wrapper/CacheWrapper.php +++ b/lib/private/Files/Cache/Wrapper/CacheWrapper.php @@ -240,18 +240,6 @@ class CacheWrapper extends Cache { 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 * diff --git a/lib/private/Lockdown/Filesystem/NullCache.php b/lib/private/Lockdown/Filesystem/NullCache.php index d45d1781abe..6ac02abb740 100644 --- a/lib/private/Lockdown/Filesystem/NullCache.php +++ b/lib/private/Lockdown/Filesystem/NullCache.php @@ -111,10 +111,6 @@ class NullCache implements ICache { return []; } - public function searchByTag($tag, $userId) { - return []; - } - public function getIncomplete() { return []; } diff --git a/lib/public/Files/Cache/ICache.php b/lib/public/Files/Cache/ICache.php index 3207356cb76..b7845ccb88e 100644 --- a/lib/public/Files/Cache/ICache.php +++ b/lib/public/Files/Cache/ICache.php @@ -223,19 +223,6 @@ interface ICache { */ 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 * diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index f94b4f57078..eaea1692fe2 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -328,76 +328,6 @@ class CacheTest extends \Test\TestCase { $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); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index e1ee96c37ec..daac67cae23 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -432,57 +432,6 @@ class FolderTest extends NodeTest { $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); /** diff --git a/tests/lib/Lockdown/Filesystem/NullCacheTest.php b/tests/lib/Lockdown/Filesystem/NullCacheTest.php index 3a4e3f3a402..7773241fca1 100644 --- a/tests/lib/Lockdown/Filesystem/NullCacheTest.php +++ b/tests/lib/Lockdown/Filesystem/NullCacheTest.php @@ -139,10 +139,6 @@ class NulLCacheTest extends \Test\TestCase { $this->assertSame([], $this->cache->searchByMime('foo')); } - public function testSearchByTag() { - $this->assertSame([], $this->cache->searchByTag('foo', 'user')); - } - public function testGetIncomplete() { $this->assertSame([], $this->cache->getIncomplete()); }