1
0

WatcherConnector.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 OC\SystemConfig;
  9. use OCP\Files\IRootFolder;
  10. use OCP\Files\Node;
  11. class WatcherConnector {
  12. /** @var IRootFolder */
  13. private $root;
  14. /** @var SystemConfig */
  15. private $config;
  16. /**
  17. * WatcherConnector constructor.
  18. *
  19. * @param IRootFolder $root
  20. * @param SystemConfig $config
  21. */
  22. public function __construct(IRootFolder $root,
  23. SystemConfig $config) {
  24. $this->root = $root;
  25. $this->config = $config;
  26. }
  27. /**
  28. * @return Watcher
  29. */
  30. private function getWatcher(): Watcher {
  31. return \OCP\Server::get(Watcher::class);
  32. }
  33. public function connectWatcher() {
  34. // Do not connect if we are not setup yet!
  35. if ($this->config->getValue('instanceid', null) !== null) {
  36. $this->root->listen('\OC\Files', 'postWrite', function (Node $node) {
  37. $this->getWatcher()->postWrite($node);
  38. });
  39. \OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback');
  40. }
  41. }
  42. }