diff options
author | Joas Schilling <coding@schilljs.com> | 2020-10-05 15:57:13 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-10-06 17:49:23 +0300 |
commit | 9f99f859a18c3882b6318e668eb3e5c08f3edebb (patch) | |
tree | 60d8b0bf7163e549b861e8f4f5c423c59d26bfd9 /lib | |
parent | b186852f9d387ac3517ae62804d5b81f178376c9 (diff) |
Make sure getUsersFavoritingObject can be run without a user
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/TagManager.php | 52 | ||||
-rw-r--r-- | lib/private/Tags.php | 17 |
2 files changed, 33 insertions, 36 deletions
diff --git a/lib/private/TagManager.php b/lib/private/TagManager.php index 96786c58a1a..4613b6247f4 100644 --- a/lib/private/TagManager.php +++ b/lib/private/TagManager.php @@ -38,32 +38,27 @@ namespace OC; use OC\Tagging\TagMapper; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\ITagManager; +use OCP\ITags; +use OCP\IUserSession; -class TagManager implements \OCP\ITagManager { +class TagManager implements ITagManager { - /** - * User session - * - * @var \OCP\IUserSession - */ + /** @var TagMapper */ + private $mapper; + + /** @var IUserSession */ private $userSession; - /** - * TagMapper - * - * @var TagMapper - */ - private $mapper; + /** @var IDBConnection */ + private $connection; - /** - * Constructor. - * - * @param TagMapper $mapper Instance of the TagMapper abstraction layer. - * @param \OCP\IUserSession $userSession the user session - */ - public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) { + public function __construct(TagMapper $mapper, IUserSession $userSession, IDBConnection $connection) { $this->mapper = $mapper; $this->userSession = $userSession; + $this->connection = $connection; } /** @@ -90,4 +85,23 @@ class TagManager implements \OCP\ITagManager { } return new Tags($this->mapper, $userId, $type, $defaultTags); } + + /** + * Get all users who favorited an object + * + * @param string $objectType + * @param int $objectId + * @return array + */ + public function getUsersFavoritingObject(string $objectType, int $objectId): array { + $query = $this->connection->getQueryBuilder(); + $query->select('uid') + ->from('vcategory_to_object', 'o') + ->innerJoin('o', 'vcategory', 'c', $query->expr()->eq('o.categoryid', 'c.id')) + ->where($query->expr()->eq('objid', $query->createNamedParameter($objectId, IQueryBuilder::PARAM_INT))) + ->andWhere($query->expr()->eq('c.type', $query->createNamedParameter($objectType))) + ->andWhere($query->expr()->eq('c.category', $query->createNamedParameter(ITags::TAG_FAVORITE))); + + return $query->execute()->fetchAll(\PDO::FETCH_COLUMN); + } } diff --git a/lib/private/Tags.php b/lib/private/Tags.php index 22c6c68ba6c..3fc66c69d6c 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -642,23 +642,6 @@ class Tags implements ITags { } /** - * Get all users who favorited an object - */ - public function getUsersFavoritingObject($objId) { - $entries = []; - - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); - $query->select('uid') - ->from('vcategory_to_object', 'o') - ->innerJoin('o', 'vcategory', 'c', $query->expr()->eq('o.categoryid', 'c.id')) - ->where($query->expr()->eq('objid', $query->createNamedParameter($objId, IQueryBuilder::PARAM_INT))) - ->andWhere($query->expr()->eq('c.type', $query->createNamedParameter($this->type))) - ->andWhere($query->expr()->eq('c.category', $query->createNamedParameter(ITags::TAG_FAVORITE))); - - return $query->execute()->fetchAll(\PDO::FETCH_COLUMN); - } - - /** * Creates a tag/object relation. * * @param int $objid The id of the object |