Skip to content

Commit 06ab96d

Browse files
committed
fix: do error on upload when a tag is not found anymore
- als removes a listener to CacheEntryInsertedEvent since CacheEntryUpdatedEvent will be called as well - logs a warning instead Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent a6ba7cd commit 06ab96d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

lib/AppInfo/Application.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use OCP\AppFramework\Bootstrap\IBootContext;
1515
use OCP\AppFramework\Bootstrap\IBootstrap;
1616
use OCP\AppFramework\Bootstrap\IRegistrationContext;
17-
use OCP\Files\Cache\CacheEntryInsertedEvent;
1817
use OCP\Files\Cache\CacheEntryUpdatedEvent;
1918
use OCP\WorkflowEngine\Events\RegisterOperationsEvent;
2019

@@ -26,7 +25,6 @@ public function __construct() {
2625
}
2726

2827
public function register(IRegistrationContext $context): void {
29-
$context->registerEventListener(CacheEntryInsertedEvent::class, CacheListener::class);
3028
$context->registerEventListener(CacheEntryUpdatedEvent::class, CacheListener::class);
3129

3230
$context->registerEventListener(RegisterOperationsEvent::class, RegisterFlowOperationsListener::class);

lib/Operation.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
use OCP\WorkflowEngine\IManager;
3232
use OCP\WorkflowEngine\IRuleMatcher;
3333
use OCP\WorkflowEngine\ISpecificOperation;
34+
use Psr\Log\LoggerInterface;
3435
use RuntimeException;
3536
use UnexpectedValueException;
3637

3738
class Operation implements ISpecificOperation, IComplexOperation {
39+
protected array $issuedTagNotFoundWarnings = [];
40+
3841
public function __construct(
3942
protected readonly ISystemTagObjectMapper $objectMapper,
4043
protected readonly ISystemTagManager $tagManager,
@@ -46,7 +49,8 @@ public function __construct(
4649
protected readonly IRootFolder $rootFolder,
4750
protected readonly File $fileEntity,
4851
protected readonly IUserSession $userSession,
49-
protected readonly IGroupManager $groupManager
52+
protected readonly IGroupManager $groupManager,
53+
protected readonly LoggerInterface $logger,
5054
) {
5155
}
5256

@@ -64,7 +68,19 @@ public function checkOperations(IStorage $storage, int $fileId, string $file): v
6468
$matches = $matcher->getFlows(false);
6569

6670
foreach ($matches as $match) {
67-
$this->objectMapper->assignTags((string) $fileId, 'files', explode(',', $match['operation']));
71+
try {
72+
$this->objectMapper->assignTags((string)$fileId, 'files', explode(',', $match['operation']));
73+
} catch (TagNotFoundException $e) {
74+
$msg = sprintf('The tag to assign (ID %s) cannot be found anymore. The related rule is %s.',
75+
$match['operation'],
76+
$match['scope_type'] === 0 ? 'global' : 'owned by ' . $match['scope_actor_id']
77+
);
78+
if (isset($this->issuedTagNotFoundWarnings[md5($msg)])) {
79+
continue;
80+
}
81+
$this->issuedTagNotFoundWarnings[md5($msg)] = true;
82+
$this->logger->error($msg);
83+
}
6884
}
6985
}
7086

tests/OperationTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\WorkflowEngine\IManager;
3131
use OCP\WorkflowEngine\IRuleMatcher;
3232
use PHPUnit\Framework\MockObject\MockObject;
33+
use Psr\Log\LoggerInterface;
3334
use Test\TestCase;
3435

3536
class OperationTest extends TestCase {
@@ -45,6 +46,7 @@ class OperationTest extends TestCase {
4546
protected \OCA\WorkflowEngine\Entity\File&MockObject $fileEntity;
4647
protected IUserSession&MockObject $userSession;
4748
protected IGroupManager&MockObject $groupManager;
49+
protected LoggerInterface&MockObject $logger;
4850
protected Operation $operation;
4951

5052
protected function setUp(): void {
@@ -62,6 +64,7 @@ protected function setUp(): void {
6264
$this->fileEntity = $this->createMock(\OCA\WorkflowEngine\Entity\File::class);
6365
$this->userSession = $this->createMock(IUserSession::class);
6466
$this->groupManager = $this->createMock(IGroupManager::class);
67+
$this->logger = $this->createMock(LoggerInterface::class);
6568

6669
$this->checkManager->expects($this->any())
6770
->method('getRuleMatcher')
@@ -81,7 +84,8 @@ protected function setUp(): void {
8184
$this->rootFolder,
8285
$this->fileEntity,
8386
$this->userSession,
84-
$this->groupManager
87+
$this->groupManager,
88+
$this->logger,
8589
);
8690
}
8791

0 commit comments

Comments
 (0)