1
0

Expire.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_Versions\Command;
  8. use OC\Command\FileAccess;
  9. use OCA\Files_Versions\Storage;
  10. use OCP\Command\ICommand;
  11. use OCP\Files\StorageNotAvailableException;
  12. use OCP\IUserManager;
  13. use Psr\Log\LoggerInterface;
  14. class Expire implements ICommand {
  15. use FileAccess;
  16. public function __construct(
  17. private string $user,
  18. private string $fileName,
  19. ) {
  20. }
  21. public function handle(): void {
  22. /** @var IUserManager $userManager */
  23. $userManager = \OC::$server->get(IUserManager::class);
  24. if (!$userManager->userExists($this->user)) {
  25. // User has been deleted already
  26. return;
  27. }
  28. try {
  29. Storage::expire($this->fileName, $this->user);
  30. } catch (StorageNotAvailableException $e) {
  31. // In case of external storage and session credentials, the expiration
  32. // fails because the command does not have those credentials
  33. $logger = \OC::$server->get(LoggerInterface::class);
  34. $logger->warning($e->getMessage(), [
  35. 'exception' => $e,
  36. 'uid' => $this->user,
  37. 'fileName' => $this->fileName,
  38. ]);
  39. }
  40. }
  41. }