123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace OCA\Files_Sharing;
- use OCP\Constants;
- use OCP\Share\IShare;
- class Updater {
-
- public static function renameHook($params) {
- self::renameChildren($params['oldpath'], $params['newpath']);
- self::moveShareToShare($params['newpath']);
- }
-
- private static function moveShareToShare($path) {
- $userFolder = \OC::$server->getUserFolder();
-
- if ($userFolder === null) {
- return;
- }
- $src = $userFolder->get($path);
- $shareManager = \OC::$server->getShareManager();
- $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1);
- $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1));
- $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1));
-
- if (empty($shares)) {
- return;
- }
-
- $mountManager = \OC::$server->getMountManager();
- $dstMount = $mountManager->find($src->getPath());
- if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) {
- return;
- }
- $newOwner = $dstMount->getShare()->getShareOwner();
-
- foreach ($shares as $share) {
-
- if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) {
- $shareManager->deleteShare($share);
- continue;
- }
- $share->setShareOwner($newOwner);
- $share->setPermissions($share->getPermissions() & $dstMount->getShare()->getPermissions());
- $shareManager->updateShare($share);
- }
- }
-
- private static function renameChildren($oldPath, $newPath) {
- $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath);
- $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath);
- $mountManager = \OC\Files\Filesystem::getMountManager();
- $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath);
- foreach ($mountedShares as $mount) {
- if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) {
- $mountPoint = $mount->getMountPoint();
- $target = str_replace($absOldPath, $absNewPath, $mountPoint);
- $mount->moveMount($target);
- }
- }
- }
- }
|