Expire.php 1.9 KB

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