From f4146e745951f2af296a55552310c9dcaa78776c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Mon, 9 Dec 2024 22:59:21 +0100 Subject: [PATCH] feat(occ): Output token validity even when age is cached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- lib/Push.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/Push.php b/lib/Push.php index 4adb1a106..3e232030a 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -530,27 +530,29 @@ protected function sendNotificationsToProxies(): void { protected function validateToken(int $tokenId, int $maxAge): bool { $age = $this->cache->get('t' . $tokenId); - if ($age !== null) { - return $age > $maxAge; - } - try { - // Check if the token is still valid... - $token = $this->tokenProvider->getTokenById($tokenId); - $this->cache->set('t' . $tokenId, $token->getLastCheck(), 600); - if ($token->getLastCheck() > $maxAge) { - $this->printInfo('Device token is valid'); - } else { - $this->printInfo('Device token "last checked" is older than 60 days: ' . $token->getLastCheck()); + if ($age === null) { + try { + // Check if the token is still valid... + $token = $this->tokenProvider->getTokenById($tokenId); + $this->cache->set('t' . $tokenId, $token->getLastCheck(), 600); + $age = $token->getLastCheck(); + } catch (InvalidTokenException) { + // Token does not exist anymore, should drop the push device entry + $this->printInfo('InvalidTokenException is thrown'); + $this->deletePushToken($tokenId); + $this->cache->set('t' . $tokenId, 0, 600); + return false; } - return $token->getLastCheck() > $maxAge; - } catch (InvalidTokenException) { - // Token does not exist anymore, should drop the push device entry - $this->printInfo('InvalidTokenException is thrown'); - $this->deletePushToken($tokenId); - $this->cache->set('t' . $tokenId, 0, 600); - return false; } + + if ($age > $maxAge) { + $this->printInfo('Device token is valid'); + return true; + } + + $this->printInfo('Device token "last checked" is older than 60 days: ' . $age); + return false; } /**