diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index a30eccfd83804..a4952e602d814 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1994,6 +1994,8 @@ 'OC\\TagManager' => $baseDir . '/lib/private/TagManager.php', 'OC\\Tagging\\Tag' => $baseDir . '/lib/private/Tagging/Tag.php', 'OC\\Tagging\\TagMapper' => $baseDir . '/lib/private/Tagging/TagMapper.php', + 'OC\\Tagging\\TagRelation' => $baseDir . '/lib/private/Tagging/TagRelation.php', + 'OC\\Tagging\\TagRelationMapper' => $baseDir . '/lib/private/Tagging/TagRelationMapper.php', 'OC\\Tags' => $baseDir . '/lib/private/Tags.php', 'OC\\Talk\\Broker' => $baseDir . '/lib/private/Talk/Broker.php', 'OC\\Talk\\ConversationOptions' => $baseDir . '/lib/private/Talk/ConversationOptions.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 9ca1852a0712d..90cd1d1544d0b 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -2035,6 +2035,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\TagManager' => __DIR__ . '/../../..' . '/lib/private/TagManager.php', 'OC\\Tagging\\Tag' => __DIR__ . '/../../..' . '/lib/private/Tagging/Tag.php', 'OC\\Tagging\\TagMapper' => __DIR__ . '/../../..' . '/lib/private/Tagging/TagMapper.php', + 'OC\\Tagging\\TagRelation' => __DIR__ . '/../../..' . '/lib/private/Tagging/TagRelation.php', + 'OC\\Tagging\\TagRelationMapper' => __DIR__ . '/../../..' . '/lib/private/Tagging/TagRelationMapper.php', 'OC\\Tags' => __DIR__ . '/../../..' . '/lib/private/Tags.php', 'OC\\Talk\\Broker' => __DIR__ . '/../../..' . '/lib/private/Talk/Broker.php', 'OC\\Talk\\ConversationOptions' => __DIR__ . '/../../..' . '/lib/private/Talk/ConversationOptions.php', diff --git a/lib/private/Tagging/TagRelation.php b/lib/private/Tagging/TagRelation.php new file mode 100644 index 0000000000000..b5e1b0dcdefde --- /dev/null +++ b/lib/private/Tagging/TagRelation.php @@ -0,0 +1,32 @@ +addType('objid', 'integer'); + $this->addType('categoryid', 'integer'); + $this->addType('type', 'string'); + } +} diff --git a/lib/private/Tagging/TagRelationMapper.php b/lib/private/Tagging/TagRelationMapper.php new file mode 100644 index 0000000000000..f37cc47b7b837 --- /dev/null +++ b/lib/private/Tagging/TagRelationMapper.php @@ -0,0 +1,32 @@ + + */ +class TagRelationMapper extends QBMapper { + + public function __construct(IDBConnection $db) { + parent::__construct($db, 'vcategory_to_object', TagRelation::class); + } + + public function deleteByObjidAndTagIds(int $objid, array $tagIds): void { + $qb = $this->db->getQueryBuilder(); + $qb->delete($this->getTableName()) + ->where($qb->expr()->eq('objid', $qb->createNamedParameter($objid, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)) + ->andWhere($qb->expr()->in('categoryid', $qb->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY)), IQueryBuilder::PARAM_INT_ARRAY); + + $qb->executeStatement(); + } +} diff --git a/lib/private/Tags.php b/lib/private/Tags.php index d59c1bd692853..b8387f14a955e 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -451,25 +451,35 @@ public function purgeObjects(array $ids): bool { /** * Get favorites for an object type * - * @return array|false An array of object ids. + * @return list An array of object ids. */ - public function getFavorites() { - if (!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { - return []; - } + public function getFavorites(): array { + $select = $this->db->getQueryBuilder(); + $subSelect = $this->db->getQueryBuilder(); - try { - return $this->getIdsForTag(ITags::TAG_FAVORITE); - } catch (\Exception $e) { - \OCP\Server::get(LoggerInterface::class)->error( - $e->getMessage(), - [ - 'app' => 'core', - 'exception' => $e, - ] - ); - return []; + $subSelect->select('id') + ->from(self::TAG_TABLE) + ->where($subSelect->expr()->eq('uid', $select->createNamedParameter($this->user, IQueryBuilder::PARAM_STR), IQueryBuilder::PARAM_STR)) + ->andWhere($subSelect->expr()->eq('type', $select->createNamedParameter($this->type, IQueryBuilder::PARAM_STR), IQueryBuilder::PARAM_STR)) + ->andWhere($subSelect->expr()->eq('category', $select->createNamedParameter(self::TAG_FAVORITE, IQueryBuilder::PARAM_STR), IQueryBuilder::PARAM_STR)) + ->orderBy('id'); + + $select->select('objid') + ->from(self::RELATION_TABLE) + ->where($select->expr()->in('categoryid', $select->createFunction($subSelect->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)) + ->andWhere($select->expr()->eq('type', $select->createNamedParameter($this->type, IQueryBuilder::PARAM_STR), IQueryBuilder::PARAM_STR)) + ->orderBy('objid'); + + $result = $select->executeQuery(); + + $ids = []; + while ($row = $result->fetch()) { + $ids[] = (int)$row['objid']; } + + $result->closeCursor(); + + return $ids; } /**