CleanupExpiredAuthorizationCode.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\IJob;
  11. use OCP\BackgroundJob\TimedJob;
  12. use OCP\DB\Exception;
  13. use Psr\Log\LoggerInterface;
  14. class CleanupExpiredAuthorizationCode extends TimedJob {
  15. public function __construct(
  16. ITimeFactory $timeFactory,
  17. private AccessTokenMapper $accessTokenMapper,
  18. private LoggerInterface $logger,
  19. ) {
  20. parent::__construct($timeFactory);
  21. // 30 days
  22. $this->setInterval(60 * 60 * 24 * 30);
  23. $this->setTimeSensitivity(IJob::TIME_INSENSITIVE);
  24. }
  25. /**
  26. * @param mixed $argument
  27. * @inheritDoc
  28. */
  29. protected function run($argument): void {
  30. try {
  31. $this->accessTokenMapper->cleanupExpiredAuthorizationCode();
  32. } catch (Exception $e) {
  33. $this->logger->warning('Failed to cleanup tokens with expired authorization code', ['exception' => $e]);
  34. }
  35. }
  36. }