Expire.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_Versions\Command;
  25. use OC\Command\FileAccess;
  26. use OCA\Files_Versions\Storage;
  27. use OCP\Command\ICommand;
  28. use OCP\Files\StorageNotAvailableException;
  29. use OCP\IUserManager;
  30. use Psr\Log\LoggerInterface;
  31. class Expire implements ICommand {
  32. use FileAccess;
  33. public function __construct(
  34. private string $user,
  35. private string $fileName,
  36. ) {
  37. }
  38. public function handle(): void {
  39. /** @var IUserManager $userManager */
  40. $userManager = \OC::$server->get(IUserManager::class);
  41. if (!$userManager->userExists($this->user)) {
  42. // User has been deleted already
  43. return;
  44. }
  45. try {
  46. Storage::expire($this->fileName, $this->user);
  47. } catch (StorageNotAvailableException $e) {
  48. // In case of external storage and session credentials, the expiration
  49. // fails because the command does not have those credentials
  50. $logger = \OC::$server->get(LoggerInterface::class);
  51. $logger->warning($e->getMessage(), [
  52. 'exception' => $e,
  53. 'uid' => $this->user,
  54. 'fileName' => $this->fileName,
  55. ]);
  56. }
  57. }
  58. }