1
0

Watcher.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Preview;
  8. use OCP\Files\Folder;
  9. use OCP\Files\IAppData;
  10. use OCP\Files\Node;
  11. use OCP\Files\NotFoundException;
  12. /**
  13. * Class Watcher
  14. *
  15. * @package OC\Preview
  16. *
  17. * Class that will watch filesystem activity and remove previews as needed.
  18. */
  19. class Watcher {
  20. /** @var IAppData */
  21. private $appData;
  22. /**
  23. * Watcher constructor.
  24. *
  25. * @param IAppData $appData
  26. */
  27. public function __construct(IAppData $appData) {
  28. $this->appData = $appData;
  29. }
  30. public function postWrite(Node $node) {
  31. $this->deleteNode($node);
  32. }
  33. protected function deleteNode(Node $node) {
  34. // We only handle files
  35. if ($node instanceof Folder) {
  36. return;
  37. }
  38. try {
  39. if (is_null($node->getId())) {
  40. return;
  41. }
  42. $folder = $this->appData->getFolder((string)$node->getId());
  43. $folder->delete();
  44. } catch (NotFoundException $e) {
  45. //Nothing to do
  46. }
  47. }
  48. public function versionRollback(array $data) {
  49. if (isset($data['node'])) {
  50. $this->deleteNode($data['node']);
  51. }
  52. }
  53. }