CleanupExpiredAuthorizationCode.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\OAuth2\BackgroundJob;
  8. use OCA\OAuth2\Db\AccessTokenMapper;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\BackgroundJob\TimedJob;
  11. use OCP\DB\Exception;
  12. use Psr\Log\LoggerInterface;
  13. class CleanupExpiredAuthorizationCode extends TimedJob {
  14. public function __construct(
  15. ITimeFactory $timeFactory,
  16. private AccessTokenMapper $accessTokenMapper,
  17. private LoggerInterface $logger,
  18. ) {
  19. parent::__construct($timeFactory);
  20. // 30 days
  21. $this->setInterval(60 * 60 * 24 * 30);
  22. $this->setTimeSensitivity(self::TIME_INSENSITIVE);
  23. }
  24. /**
  25. * @param mixed $argument
  26. * @inheritDoc
  27. */
  28. protected function run($argument): void {
  29. try {
  30. $this->accessTokenMapper->cleanupExpiredAuthorizationCode();
  31. } catch (Exception $e) {
  32. $this->logger->warning('Failed to cleanup tokens with expired authorization code', ['exception' => $e]);
  33. }
  34. }
  35. }