Skip to content

Commit 1e3bc59

Browse files
committed
refactor: Add new modern events for system tag lifecycle
The old one was deprecated in 22.0.0 but didn't had a replacement. Signed-off-by: Carl Schwan <[email protected]>
1 parent 4d00f49 commit 1e3bc59

File tree

21 files changed

+423
-346
lines changed

21 files changed

+423
-346
lines changed

apps/admin_audit/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
'OCA\\AdminAudit\\Actions\\Action' => $baseDir . '/../lib/Actions/Action.php',
1111
'OCA\\AdminAudit\\Actions\\Files' => $baseDir . '/../lib/Actions/Files.php',
1212
'OCA\\AdminAudit\\Actions\\Sharing' => $baseDir . '/../lib/Actions/Sharing.php',
13-
'OCA\\AdminAudit\\Actions\\TagManagement' => $baseDir . '/../lib/Actions/TagManagement.php',
1413
'OCA\\AdminAudit\\Actions\\Trashbin' => $baseDir . '/../lib/Actions/Trashbin.php',
1514
'OCA\\AdminAudit\\Actions\\Versions' => $baseDir . '/../lib/Actions/Versions.php',
1615
'OCA\\AdminAudit\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
@@ -26,5 +25,6 @@
2625
'OCA\\AdminAudit\\Listener\\GroupManagementEventListener' => $baseDir . '/../lib/Listener/GroupManagementEventListener.php',
2726
'OCA\\AdminAudit\\Listener\\SecurityEventListener' => $baseDir . '/../lib/Listener/SecurityEventListener.php',
2827
'OCA\\AdminAudit\\Listener\\SharingEventListener' => $baseDir . '/../lib/Listener/SharingEventListener.php',
28+
'OCA\\AdminAudit\\Listener\\TagEventListener' => $baseDir . '/../lib/Listener/TagEventListener.php',
2929
'OCA\\AdminAudit\\Listener\\UserManagementEventListener' => $baseDir . '/../lib/Listener/UserManagementEventListener.php',
3030
);

apps/admin_audit/composer/composer/autoload_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ComposerStaticInitAdminAudit
2525
'OCA\\AdminAudit\\Actions\\Action' => __DIR__ . '/..' . '/../lib/Actions/Action.php',
2626
'OCA\\AdminAudit\\Actions\\Files' => __DIR__ . '/..' . '/../lib/Actions/Files.php',
2727
'OCA\\AdminAudit\\Actions\\Sharing' => __DIR__ . '/..' . '/../lib/Actions/Sharing.php',
28-
'OCA\\AdminAudit\\Actions\\TagManagement' => __DIR__ . '/..' . '/../lib/Actions/TagManagement.php',
2928
'OCA\\AdminAudit\\Actions\\Trashbin' => __DIR__ . '/..' . '/../lib/Actions/Trashbin.php',
3029
'OCA\\AdminAudit\\Actions\\Versions' => __DIR__ . '/..' . '/../lib/Actions/Versions.php',
3130
'OCA\\AdminAudit\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
@@ -41,6 +40,7 @@ class ComposerStaticInitAdminAudit
4140
'OCA\\AdminAudit\\Listener\\GroupManagementEventListener' => __DIR__ . '/..' . '/../lib/Listener/GroupManagementEventListener.php',
4241
'OCA\\AdminAudit\\Listener\\SecurityEventListener' => __DIR__ . '/..' . '/../lib/Listener/SecurityEventListener.php',
4342
'OCA\\AdminAudit\\Listener\\SharingEventListener' => __DIR__ . '/..' . '/../lib/Listener/SharingEventListener.php',
43+
'OCA\\AdminAudit\\Listener\\TagEventListener' => __DIR__ . '/..' . '/../lib/Listener/TagEventListener.php',
4444
'OCA\\AdminAudit\\Listener\\UserManagementEventListener' => __DIR__ . '/..' . '/../lib/Listener/UserManagementEventListener.php',
4545
);
4646

apps/admin_audit/lib/Actions/TagManagement.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

apps/admin_audit/lib/AppInfo/Application.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use OCA\AdminAudit\Actions\Console;
1414
use OCA\AdminAudit\Actions\Files;
1515
use OCA\AdminAudit\Actions\Sharing;
16-
use OCA\AdminAudit\Actions\TagManagement;
1716
use OCA\AdminAudit\Actions\Trashbin;
1817
use OCA\AdminAudit\Actions\Versions;
1918
use OCA\AdminAudit\AuditLogger;
@@ -27,6 +26,7 @@
2726
use OCA\AdminAudit\Listener\GroupManagementEventListener;
2827
use OCA\AdminAudit\Listener\SecurityEventListener;
2928
use OCA\AdminAudit\Listener\SharingEventListener;
29+
use OCA\AdminAudit\Listener\TagEventListener;
3030
use OCA\AdminAudit\Listener\UserManagementEventListener;
3131
use OCA\Files_Versions\Events\VersionRestoredEvent;
3232
use OCP\App\Events\AppDisableEvent;
@@ -60,7 +60,7 @@
6060
use OCP\Share;
6161
use OCP\Share\Events\ShareCreatedEvent;
6262
use OCP\Share\Events\ShareDeletedEvent;
63-
use OCP\SystemTag\ManagerEvent;
63+
use OCP\SystemTag\Events\TagCreatedEvent;
6464
use OCP\User\Events\BeforeUserLoggedInEvent;
6565
use OCP\User\Events\BeforeUserLoggedOutEvent;
6666
use OCP\User\Events\PasswordUpdatedEvent;
@@ -130,6 +130,9 @@ public function register(IRegistrationContext $context): void {
130130
// Cache events
131131
$context->registerEventListener(CacheEntryInsertedEvent::class, CacheEventListener::class);
132132
$context->registerEventListener(CacheEntryRemovedEvent::class, CacheEventListener::class);
133+
134+
// System tag event
135+
$context->registerEventListener(TagCreatedEvent::class, TagEventListener::class);
133136
}
134137

135138
public function boot(IBootContext $context): void {
@@ -153,7 +156,6 @@ private function registerLegacyHooks(IAuditLogger $logger, ContainerInterface $s
153156
$this->fileHooks($logger, $eventDispatcher);
154157
$this->trashbinHooks($logger);
155158
$this->versionsHooks($logger);
156-
$this->tagHooks($logger, $eventDispatcher);
157159
}
158160

159161
private function sharingLegacyHooks(IAuditLogger $logger): void {
@@ -165,14 +167,6 @@ private function sharingLegacyHooks(IAuditLogger $logger): void {
165167
Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed');
166168
}
167169

168-
private function tagHooks(IAuditLogger $logger,
169-
IEventDispatcher $eventDispatcher): void {
170-
$eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, function (ManagerEvent $event) use ($logger): void {
171-
$tagActions = new TagManagement($logger);
172-
$tagActions->createTag($event->getTag());
173-
});
174-
}
175-
176170
private function fileHooks(IAuditLogger $logger, IEventDispatcher $eventDispatcher): void {
177171
$fileActions = new Files($logger);
178172

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH
7+
* SPDX-FileContributor: Carl Schwan
8+
* SPDX-License-Identifier: AGPL-3.0-or-later
9+
*/
10+
11+
namespace OCA\AdminAudit\Listener;
12+
13+
use OCA\AdminAudit\Actions\Action;
14+
use OCP\EventDispatcher\Event;
15+
use OCP\EventDispatcher\IEventListener;
16+
use OCP\SystemTag\Events\TagCreatedEvent;
17+
use OCP\SystemTag\Events\TagDeletedEvent;
18+
use OCP\SystemTag\Events\TagUpdatedEvent;
19+
20+
/**
21+
* @template-implements IEventListener<TagCreatedEvent|TagUpdatedEvent|TagDeletedEvent>
22+
*/
23+
class TagEventListener extends Action implements IEventListener {
24+
public function handle(Event $event): void {
25+
if (!$event instanceof TagCreatedEvent) {
26+
return;
27+
}
28+
29+
$tag = $event->getTag();
30+
31+
$this->log('System tag "%s" (%s, %s) created',
32+
[
33+
'name' => $tag->getName(),
34+
'visibility' => $tag->isUserVisible() ? 'visible' : 'invisible',
35+
'assignable' => $tag->isUserAssignable() ? 'user assignable' : 'system only',
36+
],
37+
['name', 'visibility', 'assignable']
38+
);
39+
}
40+
}

apps/systemtags/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
return array(
99
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
10-
'OCA\\SystemTags\\Activity\\Listener' => $baseDir . '/../lib/Activity/Listener.php',
1110
'OCA\\SystemTags\\Activity\\Provider' => $baseDir . '/../lib/Activity/Provider.php',
1211
'OCA\\SystemTags\\Activity\\Setting' => $baseDir . '/../lib/Activity/Setting.php',
12+
'OCA\\SystemTags\\Activity\\TagListener' => $baseDir . '/../lib/Activity/TagListener.php',
1313
'OCA\\SystemTags\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
1414
'OCA\\SystemTags\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
1515
'OCA\\SystemTags\\Command\\Files\\Add' => $baseDir . '/../lib/Command/Files/Add.php',

apps/systemtags/composer/composer/autoload_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class ComposerStaticInitSystemTags
2222

2323
public static $classMap = array (
2424
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
25-
'OCA\\SystemTags\\Activity\\Listener' => __DIR__ . '/..' . '/../lib/Activity/Listener.php',
2625
'OCA\\SystemTags\\Activity\\Provider' => __DIR__ . '/..' . '/../lib/Activity/Provider.php',
2726
'OCA\\SystemTags\\Activity\\Setting' => __DIR__ . '/..' . '/../lib/Activity/Setting.php',
27+
'OCA\\SystemTags\\Activity\\TagListener' => __DIR__ . '/..' . '/../lib/Activity/TagListener.php',
2828
'OCA\\SystemTags\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
2929
'OCA\\SystemTags\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
3030
'OCA\\SystemTags\\Command\\Files\\Add' => __DIR__ . '/..' . '/../lib/Command/Files/Add.php',

0 commit comments

Comments
 (0)