2015-03-23 08:07:40 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2015-03-23 08:07:40 -04:00
|
|
|
/**
|
2024-06-02 09:26:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-03-23 08:07:40 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Files_Versions\Command;
|
|
|
|
|
|
|
|
|
|
use OC\Command\FileAccess;
|
|
|
|
|
use OCA\Files_Versions\Storage;
|
|
|
|
|
use OCP\Command\ICommand;
|
2020-11-25 03:28:38 -05:00
|
|
|
use OCP\Files\StorageNotAvailableException;
|
2021-07-14 08:48:23 -04:00
|
|
|
use OCP\IUserManager;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Server;
|
2021-07-14 08:48:23 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-03-23 08:07:40 -04:00
|
|
|
|
|
|
|
|
class Expire implements ICommand {
|
|
|
|
|
use FileAccess;
|
|
|
|
|
|
2023-08-03 09:05:09 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private string $user,
|
|
|
|
|
private string $fileName,
|
|
|
|
|
) {
|
2015-03-23 08:07:40 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-03 09:05:09 -04:00
|
|
|
public function handle(): void {
|
2021-07-14 08:48:23 -04:00
|
|
|
/** @var IUserManager $userManager */
|
2025-02-03 09:34:01 -05:00
|
|
|
$userManager = Server::get(IUserManager::class);
|
2015-06-05 05:31:49 -04:00
|
|
|
if (!$userManager->userExists($this->user)) {
|
|
|
|
|
// User has been deleted already
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 03:28:38 -05:00
|
|
|
try {
|
|
|
|
|
Storage::expire($this->fileName, $this->user);
|
|
|
|
|
} catch (StorageNotAvailableException $e) {
|
|
|
|
|
// In case of external storage and session credentials, the expiration
|
|
|
|
|
// fails because the command does not have those credentials
|
|
|
|
|
|
2025-02-03 09:34:01 -05:00
|
|
|
$logger = Server::get(LoggerInterface::class);
|
2021-07-14 08:48:23 -04:00
|
|
|
$logger->warning($e->getMessage(), [
|
|
|
|
|
'exception' => $e,
|
2020-11-25 03:28:38 -05:00
|
|
|
'uid' => $this->user,
|
|
|
|
|
'fileName' => $this->fileName,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2015-03-23 08:07:40 -04:00
|
|
|
}
|
|
|
|
|
}
|