You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nextcloud-server/apps/oauth2/lib/BackgroundJob/CleanupExpiredAuthorization...

43 lines
1.1 KiB

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\OAuth2\BackgroundJob;
use OCA\OAuth2\Db\AccessTokenMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\Exception;
use Psr\Log\LoggerInterface;
final class CleanupExpiredAuthorizationCode extends TimedJob {
public function __construct(
ITimeFactory $timeFactory,
private readonly AccessTokenMapper $accessTokenMapper,
private readonly LoggerInterface $logger,
) {
parent::__construct($timeFactory);
// 30 days
$this->setInterval(60 * 60 * 24 * 30);
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
}
/**
* @param mixed $argument
*/
#[\Override]
protected function run($argument): void {
try {
$this->accessTokenMapper->cleanupExpiredAuthorizationCode($this->time);
} catch (Exception $exception) {
$this->logger->warning('Failed to cleanup tokens with expired authorization code', ['exception' => $exception]);
}
}
}