Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: vobjects may contain the same tag with different ids
It's possible that tags with the same category exist with different ids because there's no unique index on the database.

How to reproduce:

- Remove the favorite tag
- Select 2 or more files
- Tag as favorite (with the batch action)

Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Dec 5, 2024
commit 5e7625d08ce155b5e57589ffc67b4a26576f5b01
42 changes: 26 additions & 16 deletions lib/private/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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;
}

/**
Expand Down