Make TAG_FAVORITE public

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
Daniel Kesselberg 2020-02-11 21:40:01 +01:00
parent d2d7e37b7b
commit 6235175b6d
No known key found for this signature in database
GPG Key ID: 36E3664E099D0614
4 changed files with 17 additions and 15 deletions

View File

@ -24,7 +24,6 @@
namespace OCA\Files\Service; namespace OCA\Files\Service;
use OC\Tags;
use OCA\Files\Activity\FavoriteProvider; use OCA\Files\Activity\FavoriteProvider;
use OCP\Activity\IManager; use OCP\Activity\IManager;
use OCP\Files\Folder; use OCP\Files\Folder;
@ -92,14 +91,14 @@ class TagService {
$newTags = array_diff($tags, $currentTags); $newTags = array_diff($tags, $currentTags);
foreach ($newTags as $tag) { foreach ($newTags as $tag) {
if ($tag === Tags::TAG_FAVORITE) { if ($tag === ITags::TAG_FAVORITE) {
$this->addActivity(true, $fileId, $path); $this->addActivity(true, $fileId, $path);
} }
$this->tagger->tagAs($fileId, $tag); $this->tagger->tagAs($fileId, $tag);
} }
$deletedTags = array_diff($currentTags, $tags); $deletedTags = array_diff($currentTags, $tags);
foreach ($deletedTags as $tag) { foreach ($deletedTags as $tag) {
if ($tag === Tags::TAG_FAVORITE) { if ($tag === ITags::TAG_FAVORITE) {
$this->addActivity(false, $fileId, $path); $this->addActivity(false, $fileId, $path);
} }
$this->tagger->unTag($fileId, $tag); $this->tagger->unTag($fileId, $tag);

View File

@ -25,9 +25,9 @@
namespace OCA\Files\Tests\Service; namespace OCA\Files\Tests\Service;
use OC\Tags;
use OCA\Files\Service\TagService; use OCA\Files\Service\TagService;
use OCP\Activity\IManager; use OCP\Activity\IManager;
use OCP\ITags;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -172,7 +172,7 @@ class TagServiceTest extends \Test\TestCase {
); );
// set tags // set tags
$this->tagService->updateFileTags('subdir/test.txt', [Tags::TAG_FAVORITE]); $this->tagService->updateFileTags('subdir/test.txt', [ITags::TAG_FAVORITE]);
// remove tag // remove tag
$this->tagService->updateFileTags('subdir/test.txt', []); $this->tagService->updateFileTags('subdir/test.txt', []);

View File

@ -48,8 +48,9 @@ use OC\Tagging\Tag;
use OC\Tagging\TagMapper; use OC\Tagging\TagMapper;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\ILogger; use OCP\ILogger;
use OCP\ITags;
class Tags implements \OCP\ITags { class Tags implements ITags {
/** /**
* Tags * Tags
@ -112,8 +113,6 @@ class Tags implements \OCP\ITags {
const TAG_TABLE = '*PREFIX*vcategory'; const TAG_TABLE = '*PREFIX*vcategory';
const RELATION_TABLE = '*PREFIX*vcategory_to_object'; const RELATION_TABLE = '*PREFIX*vcategory_to_object';
const TAG_FAVORITE = '_$!<Favorite>!$_';
/** /**
* Constructor. * Constructor.
* *
@ -186,7 +185,7 @@ class Tags implements \OCP\ITags {
$tagMap = array(); $tagMap = array();
foreach($this->tags as $tag) { foreach($this->tags as $tag) {
if($tag->getName() !== self::TAG_FAVORITE) { if($tag->getName() !== ITags::TAG_FAVORITE) {
$tagMap[] = $this->tagMap($tag); $tagMap[] = $this->tagMap($tag);
} }
} }
@ -624,12 +623,12 @@ class Tags implements \OCP\ITags {
* @return array|false An array of object ids. * @return array|false An array of object ids.
*/ */
public function getFavorites() { public function getFavorites() {
if(!$this->userHasTag(self::TAG_FAVORITE, $this->user)) { if(!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) {
return []; return [];
} }
try { try {
return $this->getIdsForTag(self::TAG_FAVORITE); return $this->getIdsForTag(ITags::TAG_FAVORITE);
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
@ -647,10 +646,10 @@ class Tags implements \OCP\ITags {
* @return boolean * @return boolean
*/ */
public function addToFavorites($objid) { public function addToFavorites($objid) {
if(!$this->userHasTag(self::TAG_FAVORITE, $this->user)) { if(!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) {
$this->add(self::TAG_FAVORITE); $this->add(ITags::TAG_FAVORITE);
} }
return $this->tagAs($objid, self::TAG_FAVORITE); return $this->tagAs($objid, ITags::TAG_FAVORITE);
} }
/** /**
@ -660,7 +659,7 @@ class Tags implements \OCP\ITags {
* @return boolean * @return boolean
*/ */
public function removeFromFavorites($objid) { public function removeFromFavorites($objid) {
return $this->unTag($objid, self::TAG_FAVORITE); return $this->unTag($objid, ITags::TAG_FAVORITE);
} }
/** /**

View File

@ -53,6 +53,10 @@ use OC\Tags;
*/ */
interface ITags { interface ITags {
/**
* @since 19.0.0
*/
public const TAG_FAVORITE = '_$!<Favorite>!$_';
/** /**
* Check if any tags are saved for this type and user. * Check if any tags are saved for this type and user.