From 80169af29af8e95a6626cde5fa5acd2551a0952a Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Tue, 30 Jul 2024 18:20:56 +0200 Subject: [PATCH] fix: prevent null token Signed-off-by: skjnldsv --- lib/Listener/ShareLinkAccessedListener.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Listener/ShareLinkAccessedListener.php b/lib/Listener/ShareLinkAccessedListener.php index 2f9f460..a6637b7 100644 --- a/lib/Listener/ShareLinkAccessedListener.php +++ b/lib/Listener/ShareLinkAccessedListener.php @@ -33,6 +33,7 @@ use OCP\EventDispatcher\IEventListener; use OCP\IConfig; use OCP\Share\IManager; +use Psr\Log\LoggerInterface; /** @template-implements IEventListener */ class ShareLinkAccessedListener implements IEventListener { @@ -40,6 +41,7 @@ public function __construct( private IConfig $config, private IManager $manager, private LimitMapper $mapper, + private LoggerInterface $logger ) { } @@ -53,8 +55,12 @@ public function handle(Event $event): void { return; } - // Make sure we have a valid limit $token = $event->getShare()->getToken(); + if ($token === null) { + return; + } + + // Make sure we have a valid limit try { $shareLimit = $this->mapper->get($token); $limit = $shareLimit->getLimit(); @@ -76,6 +82,8 @@ public function handle(Event $event): void { $this->mapper->update($shareLimit); } catch (DoesNotExistException $e) { // No limit is set, ignore + } catch (\Exception $e) { + $this->logger->error('Error while handling share link accessed event: ' . $e->getMessage()); } } }