Skip to content

Commit 77140cf

Browse files
committed
fix: Revert change to Tags
Let's keep this for a later refactor Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 3584712 commit 77140cf

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

lib/private/Tagging/TagMapper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OC\Tagging;
1010

11+
use OCP\AppFramework\Db\DoesNotExistException;
1112
use OCP\AppFramework\ORM\Repository;
1213

1314
/**
@@ -33,4 +34,17 @@ public function loadTags(array $owners, string $type): array {
3334
'name' => 'ASC',
3435
]));
3536
}
37+
38+
public function tagExists(Tag $tag): bool {
39+
try {
40+
$this->findOneBy([
41+
'uid' => $tag->owner,
42+
'type' => $tag->type,
43+
'category' => $tag->name,
44+
]);
45+
return true;
46+
} catch (DoesNotExistException) {
47+
return false;
48+
}
49+
}
3650
}

lib/private/Tags.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,8 @@ public function addMultiple(string|array $names, bool $sync = false, ?int $id =
320320
*/
321321
protected function save(): void {
322322
foreach ($this->tags as $tag) {
323-
try {
323+
if (!$this->mapper->tagExists($tag)) {
324324
$this->mapper->insert($tag);
325-
} catch (Exception $e) {
326-
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
327-
$this->logger->error($e->getMessage(), [
328-
'exception' => $e,
329-
'app' => 'core',
330-
]);
331-
}
332325
}
333326
}
334327

0 commit comments

Comments
 (0)