You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

changewatcher.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Robin Appelman <icewind@owncloud.com>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\Files_Sharing\Propagation;
  23. use OC\Files\Cache\ChangePropagator;
  24. use OC\Files\Filesystem;
  25. use OC\Files\View;
  26. use OCA\Files_Sharing\SharedMount;
  27. /**
  28. * Watch for changes made in a shared mount and propagate the changes to the share owner
  29. */
  30. class ChangeWatcher {
  31. /**
  32. * The user view for the logged in user
  33. *
  34. * @var \OC\Files\View
  35. */
  36. private $baseView;
  37. /**
  38. * @param \OC\Files\View $baseView the view for the logged in user
  39. */
  40. public function __construct(View $baseView) {
  41. $this->baseView = $baseView;
  42. }
  43. public function writeHook($params) {
  44. $path = $params['path'];
  45. $fullPath = $this->baseView->getAbsolutePath($path);
  46. $mount = $this->baseView->getMount($path);
  47. if ($mount instanceof SharedMount) {
  48. $this->propagateForOwner($mount->getShare(), $mount->getInternalPath($fullPath), $mount->getOwnerPropagator());
  49. }
  50. }
  51. public function renameHook($params) {
  52. $path1 = $params['oldpath'];
  53. $path2 = $params['newpath'];
  54. $fullPath1 = $this->baseView->getAbsolutePath($path1);
  55. $fullPath2 = $this->baseView->getAbsolutePath($path2);
  56. $mount1 = $this->baseView->getMount($path1);
  57. $mount2 = $this->baseView->getMount($path2);
  58. if ($mount1 instanceof SharedMount and $mount1->getInternalPath($fullPath1) !== '') {
  59. $this->propagateForOwner($mount1->getShare(), $mount1->getInternalPath($fullPath1), $mount1->getOwnerPropagator());
  60. }
  61. if ($mount1 !== $mount2 and $mount2 instanceof SharedMount and $mount2->getInternalPath($fullPath2) !== '') {
  62. $this->propagateForOwner($mount2->getShare(), $mount2->getInternalPath($fullPath2), $mount2->getOwnerPropagator());
  63. }
  64. }
  65. /**
  66. * @param array $share
  67. * @param string $internalPath
  68. * @param \OC\Files\Cache\ChangePropagator $propagator
  69. */
  70. private function propagateForOwner($share, $internalPath, ChangePropagator $propagator) {
  71. // note that we have already set up the filesystem for the owner when mounting the share
  72. $view = new View('/' . $share['uid_owner'] . '/files');
  73. $shareRootPath = $view->getPath($share['item_source']);
  74. if (!is_null($shareRootPath)) {
  75. $path = $shareRootPath . '/' . $internalPath;
  76. $path = Filesystem::normalizePath($path);
  77. $propagator->addChange($path);
  78. $propagator->propagateChanges();
  79. }
  80. }
  81. }