Expire.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /**
  34. * @var string
  35. */
  36. private $fileName;
  37. /**
  38. * @var string
  39. */
  40. private $user;
  41. public function __construct(string $user, string $fileName) {
  42. $this->user = $user;
  43. $this->fileName = $fileName;
  44. }
  45. public function handle() {
  46. /** @var IUserManager $userManager */
  47. $userManager = \OC::$server->get(IUserManager::class);
  48. if (!$userManager->userExists($this->user)) {
  49. // User has been deleted already
  50. return;
  51. }
  52. try {
  53. Storage::expire($this->fileName, $this->user);
  54. } catch (StorageNotAvailableException $e) {
  55. // In case of external storage and session credentials, the expiration
  56. // fails because the command does not have those credentials
  57. /** @var LoggerInterface */
  58. $logger = \OC::$server->get(LoggerInterface::class);
  59. $logger->warning($e->getMessage(), [
  60. 'exception' => $e,
  61. 'uid' => $this->user,
  62. 'fileName' => $this->fileName,
  63. ]);
  64. }
  65. }
  66. }