0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-03-04 03:57:28 +00:00
nextcloud_server/apps/files_external/lib/BackgroundJob/CredentialsCleanup.php
provokateurin a7f5b452d1
fix(BackgroundJobs): Adjust intervals and time sensitivities
Signed-off-by: provokateurin <kate@provokateurin.de>
2024-11-25 08:38:58 +01:00

55 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_External\BackgroundJob;
use OCA\Files_External\Lib\Auth\Password\LoginCredentials;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Security\ICredentialsManager;
class CredentialsCleanup extends TimedJob {
private $credentialsManager;
private $userGlobalStoragesService;
private $userManager;
public function __construct(
ITimeFactory $time,
ICredentialsManager $credentialsManager,
UserGlobalStoragesService $userGlobalStoragesService,
IUserManager $userManager
) {
parent::__construct($time);
$this->credentialsManager = $credentialsManager;
$this->userGlobalStoragesService = $userGlobalStoragesService;
$this->userManager = $userManager;
// run every day
$this->setInterval(24 * 60 * 60);
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
}
protected function run($argument) {
$this->userManager->callForSeenUsers(function (IUser $user) {
$storages = $this->userGlobalStoragesService->getAllStoragesForUser($user);
$usesLoginCredentials = array_reduce($storages, function (bool $uses, StorageConfig $storage) {
return $uses || $storage->getAuthMechanism() instanceof LoginCredentials;
}, false);
if (!$usesLoginCredentials) {
$this->credentialsManager->delete($user->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER);
}
});
}
}