@@ -31,85 +31,85 @@ |
||
31 | 31 | |
32 | 32 | class Updater { |
33 | 33 | |
34 | - /** |
|
35 | - * @param array $params |
|
36 | - */ |
|
37 | - public static function renameHook($params) { |
|
38 | - self::renameChildren($params['oldpath'], $params['newpath']); |
|
39 | - self::moveShareToShare($params['newpath']); |
|
40 | - } |
|
34 | + /** |
|
35 | + * @param array $params |
|
36 | + */ |
|
37 | + public static function renameHook($params) { |
|
38 | + self::renameChildren($params['oldpath'], $params['newpath']); |
|
39 | + self::moveShareToShare($params['newpath']); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Fix for https://github.com/owncloud/core/issues/20769 |
|
44 | - * |
|
45 | - * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
46 | - * In this case we need to update the parent of the moved share. Since they are |
|
47 | - * effectively handing over ownership of the file the rest of the code needs to know |
|
48 | - * they need to build up the reshare tree. |
|
49 | - * |
|
50 | - * @param string $path |
|
51 | - */ |
|
52 | - private static function moveShareToShare($path) { |
|
53 | - $userFolder = \OC::$server->getUserFolder(); |
|
42 | + /** |
|
43 | + * Fix for https://github.com/owncloud/core/issues/20769 |
|
44 | + * |
|
45 | + * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
46 | + * In this case we need to update the parent of the moved share. Since they are |
|
47 | + * effectively handing over ownership of the file the rest of the code needs to know |
|
48 | + * they need to build up the reshare tree. |
|
49 | + * |
|
50 | + * @param string $path |
|
51 | + */ |
|
52 | + private static function moveShareToShare($path) { |
|
53 | + $userFolder = \OC::$server->getUserFolder(); |
|
54 | 54 | |
55 | - // If the user folder can't be constructed (e.g. link share) just return. |
|
56 | - if ($userFolder === null) { |
|
57 | - return; |
|
58 | - } |
|
55 | + // If the user folder can't be constructed (e.g. link share) just return. |
|
56 | + if ($userFolder === null) { |
|
57 | + return; |
|
58 | + } |
|
59 | 59 | |
60 | - $src = $userFolder->get($path); |
|
60 | + $src = $userFolder->get($path); |
|
61 | 61 | |
62 | - $shareManager = \OC::$server->getShareManager(); |
|
62 | + $shareManager = \OC::$server->getShareManager(); |
|
63 | 63 | |
64 | - $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1); |
|
65 | - $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1)); |
|
66 | - $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1)); |
|
64 | + $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1); |
|
65 | + $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1)); |
|
66 | + $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1)); |
|
67 | 67 | |
68 | - // If the path we move is not a share we don't care |
|
69 | - if (empty($shares)) { |
|
70 | - return; |
|
71 | - } |
|
68 | + // If the path we move is not a share we don't care |
|
69 | + if (empty($shares)) { |
|
70 | + return; |
|
71 | + } |
|
72 | 72 | |
73 | - // Check if the destination is inside a share |
|
74 | - $mountManager = \OC::$server->getMountManager(); |
|
75 | - $dstMount = $mountManager->find($src->getPath()); |
|
76 | - if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
77 | - return; |
|
78 | - } |
|
73 | + // Check if the destination is inside a share |
|
74 | + $mountManager = \OC::$server->getMountManager(); |
|
75 | + $dstMount = $mountManager->find($src->getPath()); |
|
76 | + if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
77 | + return; |
|
78 | + } |
|
79 | 79 | |
80 | - $newOwner = $dstMount->getShare()->getShareOwner(); |
|
80 | + $newOwner = $dstMount->getShare()->getShareOwner(); |
|
81 | 81 | |
82 | - //Ownership is moved over |
|
83 | - foreach ($shares as $share) { |
|
84 | - /** @var IShare $share */ |
|
85 | - if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) { |
|
86 | - $shareManager->deleteShare($share); |
|
87 | - continue; |
|
88 | - } |
|
89 | - $share->setShareOwner($newOwner); |
|
90 | - $share->setPermissions($share->getPermissions() & $dstMount->getShare()->getPermissions()); |
|
91 | - $shareManager->updateShare($share); |
|
92 | - } |
|
93 | - } |
|
82 | + //Ownership is moved over |
|
83 | + foreach ($shares as $share) { |
|
84 | + /** @var IShare $share */ |
|
85 | + if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) { |
|
86 | + $shareManager->deleteShare($share); |
|
87 | + continue; |
|
88 | + } |
|
89 | + $share->setShareOwner($newOwner); |
|
90 | + $share->setPermissions($share->getPermissions() & $dstMount->getShare()->getPermissions()); |
|
91 | + $shareManager->updateShare($share); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * rename mount point from the children if the parent was renamed |
|
97 | - * |
|
98 | - * @param string $oldPath old path relative to data/user/files |
|
99 | - * @param string $newPath new path relative to data/user/files |
|
100 | - */ |
|
101 | - private static function renameChildren($oldPath, $newPath) { |
|
102 | - $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $newPath); |
|
103 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $oldPath); |
|
95 | + /** |
|
96 | + * rename mount point from the children if the parent was renamed |
|
97 | + * |
|
98 | + * @param string $oldPath old path relative to data/user/files |
|
99 | + * @param string $newPath new path relative to data/user/files |
|
100 | + */ |
|
101 | + private static function renameChildren($oldPath, $newPath) { |
|
102 | + $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $newPath); |
|
103 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $oldPath); |
|
104 | 104 | |
105 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
106 | - $mountedShares = $mountManager->findIn('/' . \OC_User::getUser() . '/files/' . $oldPath); |
|
107 | - foreach ($mountedShares as $mount) { |
|
108 | - if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
109 | - $mountPoint = $mount->getMountPoint(); |
|
110 | - $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
111 | - $mount->moveMount($target); |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
105 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
106 | + $mountedShares = $mountManager->findIn('/' . \OC_User::getUser() . '/files/' . $oldPath); |
|
107 | + foreach ($mountedShares as $mount) { |
|
108 | + if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
109 | + $mountPoint = $mount->getMountPoint(); |
|
110 | + $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
111 | + $mount->moveMount($target); |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | 115 | } |