public function testUpdateFileTags() { $tag1 = 'tag1'; $tag2 = 'tag2'; $subdir = $this->root->newFolder('subdir'); $testFile = $subdir->newFile('test.txt'); $testFile->putContent('test contents'); $fileId = $testFile->getId(); // set tags $this->tagService->updateFileTags('subdir/test.txt', array($tag1, $tag2)); $this->assertEquals(array($fileId), $this->tagger->getIdsForTag($tag1)); $this->assertEquals(array($fileId), $this->tagger->getIdsForTag($tag2)); // remove tag $result = $this->tagService->updateFileTags('subdir/test.txt', array($tag2)); $this->assertEquals(array(), $this->tagger->getIdsForTag($tag1)); $this->assertEquals(array($fileId), $this->tagger->getIdsForTag($tag2)); // clear tags $result = $this->tagService->updateFileTags('subdir/test.txt', array()); $this->assertEquals(array(), $this->tagger->getIdsForTag($tag1)); $this->assertEquals(array(), $this->tagger->getIdsForTag($tag2)); // non-existing file $caught = false; try { $this->tagService->updateFileTags('subdir/unexist.txt', array($tag1)); } catch (\OCP\Files\NotFoundException $e) { $caught = true; } $this->assertTrue($caught); $subdir->delete(); }
/** * Updates the info of the specified file path * The passed tags are absolute, which means they will * replace the actual tag selection. * * @NoAdminRequired * @CORS * * @param string $path path * @param array $tags array of tags */ public function updateFileTags($path, $tags = null) { $result = array(); // if tags specified or empty array, update tags if (!is_null($tags)) { try { $this->tagService->updateFileTags($path, $tags); } catch (\OCP\Files\NotFoundException $e) { return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND); } $result['tags'] = $tags; } return new DataResponse($result, Http::STATUS_OK); }
/** * Updates the info of the specified file path * The passed tags are absolute, which means they will * replace the actual tag selection. * * @NoAdminRequired * * @param string $path path * @param array|string $tags array of tags * @return DataResponse */ public function updateFileTags($path, $tags = null) { $result = []; // if tags specified or empty array, update tags if (!is_null($tags)) { try { $this->tagService->updateFileTags($path, $tags); } catch (\OCP\Files\NotFoundException $e) { return new DataResponse(['message' => $e->getMessage()], Http::STATUS_NOT_FOUND); } catch (\OCP\Files\StorageNotAvailableException $e) { return new DataResponse(['message' => $e->getMessage()], Http::STATUS_SERVICE_UNAVAILABLE); } catch (\Exception $e) { return new DataResponse(['message' => $e->getMessage()], Http::STATUS_NOT_FOUND); } $result['tags'] = $tags; } return new DataResponse($result); }