2023-08-29 09:57:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-05-30 18:13:41 +00:00
|
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-08-29 09:57:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
class CleanupExpiredAuthorizationCode extends TimedJob {
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
ITimeFactory $timeFactory,
|
|
|
|
private AccessTokenMapper $accessTokenMapper,
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
) {
|
|
|
|
parent::__construct($timeFactory);
|
|
|
|
// 30 days
|
|
|
|
$this->setInterval(60 * 60 * 24 * 30);
|
2024-10-07 15:36:55 +00:00
|
|
|
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
|
2023-08-29 09:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $argument
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2023-10-04 11:20:57 +00:00
|
|
|
protected function run($argument): void {
|
2023-08-29 09:57:00 +00:00
|
|
|
try {
|
|
|
|
$this->accessTokenMapper->cleanupExpiredAuthorizationCode();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->logger->warning('Failed to cleanup tokens with expired authorization code', ['exception' => $e]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|