Skip to content

fix: do error on upload when a tag is not found anymore #1212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function __construct() {

#[\Override]
public function register(IRegistrationContext $context): void {
$context->registerEventListener(CacheEntryInsertedEvent::class, CacheListener::class);
$context->registerEventListener(CacheEntryUpdatedEvent::class, CacheListener::class);

$context->registerEventListener(RegisterOperationsEvent::class, RegisterFlowOperationsListener::class);
Expand Down
18 changes: 17 additions & 1 deletion lib/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
use OCP\WorkflowEngine\IManager;
use OCP\WorkflowEngine\IRuleMatcher;
use OCP\WorkflowEngine\ISpecificOperation;
use Psr\Log\LoggerInterface;
use RuntimeException;
use UnexpectedValueException;

class Operation implements ISpecificOperation, IComplexOperation {
protected array $issuedTagNotFoundWarnings = [];

public function __construct(
protected readonly ISystemTagObjectMapper $objectMapper,
protected readonly ISystemTagManager $tagManager,
Expand All @@ -47,6 +50,7 @@ public function __construct(
protected readonly File $fileEntity,
protected readonly IUserSession $userSession,
protected readonly IGroupManager $groupManager,
protected readonly LoggerInterface $logger,
) {
}

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

foreach ($matches as $match) {
$this->objectMapper->assignTags((string)$fileId, 'files', explode(',', $match['operation']));
try {
$this->objectMapper->assignTags((string)$fileId, 'files', explode(',', $match['operation']));
} catch (TagNotFoundException $e) {
$msg = sprintf('The tag to assign (ID %s) cannot be found anymore. The related rule is %s.',
$match['operation'],
$match['scope_type'] === 0 ? 'global' : 'owned by ' . $match['scope_actor_id']
);
if (isset($this->issuedTagNotFoundWarnings[md5($msg)])) {
continue;
}
$this->issuedTagNotFoundWarnings[md5($msg)] = true;
$this->logger->warning($msg);
}
}
}

Expand Down
Loading