summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2023-11-09 14:45:34 -0100
committerMaxence Lange <maxence@artificial-owl.com>2023-11-09 14:45:41 -0100
commita99b35f7453b72738122f0a6f971f111bc1be6f9 (patch)
tree65d074c3e4f0fb61fae24763699c0b4c2d573e00
parentfbdd4d753062f8196b95f4eff9ac5c465c194ee8 (diff)
removing deprecated event
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--appinfo/info.xml4
-rw-r--r--lib/AppInfo/Application.php23
-rw-r--r--lib/Listeners/UserAccountListener.php (renamed from lib/Listeners/DeprecatedListener.php)36
3 files changed, 25 insertions, 38 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index ba05010d..17090074 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -35,7 +35,7 @@
<database>pgsql</database>
<database>sqlite</database>
<database>mysql</database>
- <nextcloud min-version="26" max-version="28" />
+ <nextcloud min-version="28" max-version="28" />
</dependencies>
<background-jobs>
@@ -77,4 +77,4 @@
<contactsmenu>
<provider>OCA\Social\Providers\ContactsMenuProvider</provider>
</contactsmenu>
-</info> \ No newline at end of file
+</info>
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 764212df..024fca58 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -32,18 +32,17 @@ declare(strict_types=1);
namespace OCA\Social\AppInfo;
use OCA\Social\Dashboard\SocialWidget;
-use OCA\Social\Listeners\DeprecatedListener;
use OCA\Social\Listeners\ProfileSectionListener;
+use OCA\Social\Listeners\UserAccountListener;
use OCA\Social\Notification\Notifier;
use OCA\Social\Search\UnifiedSearchProvider;
use OCA\Social\WellKnown\WebfingerHandler;
+use OCP\Accounts\UserUpdatedEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
-use OCP\IUser;
use OCP\Profile\BeforeTemplateRenderedEvent;
-use Symfony\Component\EventDispatcher\GenericEvent;
require_once __DIR__ . '/../../vendor/autoload.php';
@@ -66,26 +65,14 @@ class Application extends App implements IBootstrap {
$context->registerSearchProvider(UnifiedSearchProvider::class);
$context->registerWellKnownHandler(WebfingerHandler::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, ProfileSectionListener::class);
- $context->registerDashboardWidget(SocialWidget::class);
+ $context->registerEventListener(UserUpdatedEvent::class, UserAccountListener::class);
- $this->registerDeprecatedListener();
+ $context->registerDashboardWidget(SocialWidget::class);
}
public function boot(IBootContext $context): void {
$manager = $context->getServerContainer()
- ->getNotificationManager();
+ ->getNotificationManager();
$manager->registerNotifierService(Notifier::class);
}
-
-
- public function registerDeprecatedListener(): void {
- $dispatcher = \OC::$server->getEventDispatcher();
- $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) {
- /** @var IUser $user */
- $user = $event->getSubject();
- /** @var DeprecatedListener $deprecatedListener */
- $deprecatedListener = \OC::$server->get(DeprecatedListener::class);
- $deprecatedListener->userAccountUpdated($user);
- });
- }
}
diff --git a/lib/Listeners/DeprecatedListener.php b/lib/Listeners/UserAccountListener.php
index 435a276b..d51f4cf6 100644
--- a/lib/Listeners/DeprecatedListener.php
+++ b/lib/Listeners/UserAccountListener.php
@@ -29,32 +29,32 @@ declare(strict_types=1);
namespace OCA\Social\Listeners;
-use OCA\Social\Exceptions\ItemAlreadyExistsException;
-use OCA\Social\Exceptions\SocialAppConfigException;
-use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Service\AccountService;
-use OCP\IUser;
-
-class DeprecatedListener {
- private AccountService $accountService;
+use OCP\Accounts\UserUpdatedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Psr\Log\LoggerInterface;
+/**
+ * @template-implements IEventListener<\OCP\EventDispatcher\Event>
+ */
+class UserAccountListener implements IEventListener {
public function __construct(
- AccountService $accountService
+ private AccountService $accountService,
+ private LoggerInterface $logger
) {
- $this->accountService = $accountService;
}
- /**
- * @param IUser $user
- *
- * @return void
- * @throws SocialAppConfigException
- * @throws UrlCloudException
- */
- public function userAccountUpdated(IUser $user): void {
+ public function handle(Event $event): void {
+ if (!($event instanceof UserUpdatedEvent)) {
+ return;
+ }
+
+ $user = $event->getUser();
try {
$this->accountService->cacheLocalActorByUsername($user->getUID());
- } catch (ItemAlreadyExistsException $e) {
+ } catch (\Exception $e) {
+ $this->logger->warning('issue while updating user account', ['exception' => $e]);
}
}
}