diff options
author | grnd-alt <salimbelakkaf@outlook.de> | 2024-11-18 13:59:53 +0100 |
---|---|---|
committer | grnd-alt <salimbelakkaf@outlook.de> | 2024-12-03 20:56:36 +0100 |
commit | 8d953aeb8de809aab95371b2af1ef04e9d9d099f (patch) | |
tree | adbd29882ed266c6bf03ca5f5e63f945cdd21825 /lib | |
parent | 2d02d835978a82bcff4845adc702d8033b4fcb60 (diff) | |
download | nextcloud-server-8d953aeb8de809aab95371b2af1ef04e9d9d099f.tar.gz nextcloud-server-8d953aeb8de809aab95371b2af1ef04e9d9d099f.zip |
refactor(tags): move favorite event dispatching to tags.php
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/TagManager.php | 19 | ||||
-rw-r--r-- | lib/private/Tags.php | 39 |
2 files changed, 31 insertions, 27 deletions
diff --git a/lib/private/TagManager.php b/lib/private/TagManager.php index f99653f2c05..5c346e14430 100644 --- a/lib/private/TagManager.php +++ b/lib/private/TagManager.php @@ -11,6 +11,7 @@ use OC\Tagging\TagMapper; use OCP\Db\Exception as DBException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; use OCP\IDBConnection; use OCP\ITagManager; @@ -23,16 +24,14 @@ use Psr\Log\LoggerInterface; * @template-implements IEventListener<UserDeletedEvent> */ class TagManager implements ITagManager, IEventListener { - private TagMapper $mapper; - private IUserSession $userSession; - private IDBConnection $connection; - private LoggerInterface $logger; - public function __construct(TagMapper $mapper, IUserSession $userSession, IDBConnection $connection, LoggerInterface $logger) { - $this->mapper = $mapper; - $this->userSession = $userSession; - $this->connection = $connection; - $this->logger = $logger; + public function __construct( + private TagMapper $mapper, + private IUserSession $userSession, + private IDBConnection $connection, + private LoggerInterface $logger, + private IEventDispatcher $dispatcher, + ) { } /** @@ -57,7 +56,7 @@ class TagManager implements ITagManager, IEventListener { } $userId = $this->userSession->getUser()->getUId(); } - return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $defaultTags); + return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $this->dispatcher, $this->userSession, $defaultTags); } /** diff --git a/lib/private/Tags.php b/lib/private/Tags.php index d59c1bd6928..0a37f4c9f4e 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -11,8 +11,12 @@ use OC\Tagging\Tag; use OC\Tagging\TagMapper; use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\NodeAddedToFavorite; +use OCP\Files\Events\NodeRemovedFromFavorite; use OCP\IDBConnection; use OCP\ITags; +use OCP\IUserSession; use OCP\Share_Backend; use Psr\Log\LoggerInterface; @@ -21,10 +25,6 @@ class Tags implements ITags { * Used for storing objectid/categoryname pairs while rescanning. */ private static array $relations = []; - private string $type; - private string $user; - private IDBConnection $db; - private LoggerInterface $logger; private array $tags = []; /** @@ -39,11 +39,6 @@ class Tags implements ITags { private array $owners = []; /** - * The Mapper we are using to communicate our Tag objects to the database. - */ - private TagMapper $mapper; - - /** * The sharing backend for objects of $this->type. Required if * $this->includeShared === true to determine ownership of items. */ @@ -62,14 +57,18 @@ class Tags implements ITags { * * since 20.0.0 $includeShared isn't used anymore */ - public function __construct(TagMapper $mapper, string $user, string $type, LoggerInterface $logger, IDBConnection $connection, array $defaultTags = []) { - $this->mapper = $mapper; - $this->user = $user; - $this->type = $type; + public function __construct( + private TagMapper $mapper, + private string $user, + private string $type, + private LoggerInterface $logger, + private IDBConnection $db, + private IEventDispatcher $dispatcher, + private IUserSession $userSession, + array $defaultTags = [], + ) { $this->owners = [$this->user]; $this->tags = $this->mapper->loadTags($this->owners, $this->type); - $this->db = $connection; - $this->logger = $logger; if (count($defaultTags) > 0 && count($this->tags) === 0) { $this->addMultiple($defaultTags, true); @@ -502,7 +501,7 @@ class Tags implements ITags { * @param string $tag The id or name of the tag * @return boolean Returns false on error. */ - public function tagAs($objid, $tag) { + public function tagAs($objid, $tag, string $path = '') { if (is_string($tag) && !is_numeric($tag)) { $tag = trim($tag); if ($tag === '') { @@ -532,6 +531,9 @@ class Tags implements ITags { ]); return false; } + if ($tag === ITags::TAG_FAVORITE) { + $this->dispatcher->dispatchTyped(new NodeAddedToFavorite($this->userSession->getUser(), $objid, $path)); + } return true; } @@ -542,7 +544,7 @@ class Tags implements ITags { * @param string $tag The id or name of the tag * @return boolean */ - public function unTag($objid, $tag) { + public function unTag($objid, $tag, string $path = '') { if (is_string($tag) && !is_numeric($tag)) { $tag = trim($tag); if ($tag === '') { @@ -569,6 +571,9 @@ class Tags implements ITags { ]); return false; } + if ($tag === ITags::TAG_FAVORITE) { + $this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite($this->userSession->getUser(), $objid, $path)); + } return true; } |