Merge pull request #9364 from owncloud/sharing_rename_mount_points
[sharing] rename mount point of children if parent was renamed
This commit is contained in:
commit
615d037d3e
2 changed files with 59 additions and 0 deletions
|
@ -109,6 +109,7 @@ class Shared_Updater {
|
||||||
static public function renameHook($params) {
|
static public function renameHook($params) {
|
||||||
self::correctFolders($params['newpath']);
|
self::correctFolders($params['newpath']);
|
||||||
self::correctFolders(pathinfo($params['oldpath'], PATHINFO_DIRNAME));
|
self::correctFolders(pathinfo($params['oldpath'], PATHINFO_DIRNAME));
|
||||||
|
self::renameChildren($params['oldpath'], $params['newpath']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,4 +210,26 @@ class Shared_Updater {
|
||||||
$findAndRemoveShares->execute(array());
|
$findAndRemoveShares->execute(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rename mount point from the children if the parent was renamed
|
||||||
|
*
|
||||||
|
* @param string $oldPath old path relative to data/user/files
|
||||||
|
* @param string $newPath new path relative to data/user/files
|
||||||
|
*/
|
||||||
|
static private 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('OCA\Files_Sharing\ISharedStorage')) {
|
||||||
|
$mountPoint = $mount->getMountPoint();
|
||||||
|
$target = str_replace($absOldPath, $absNewPath, $mountPoint);
|
||||||
|
$mount->moveMount($target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,4 +217,40 @@ class Test_Files_Sharing_Updater extends Test_Files_Sharing_Base {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if a folder gets renamed all children mount points should be renamed too
|
||||||
|
*/
|
||||||
|
function testRename() {
|
||||||
|
|
||||||
|
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
||||||
|
$result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||||
|
|
||||||
|
// make sure that the shared folder exists
|
||||||
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
|
||||||
|
|
||||||
|
\OC\Files\Filesystem::mkdir('oldTarget');
|
||||||
|
\OC\Files\Filesystem::mkdir('oldTarget/subfolder');
|
||||||
|
\OC\Files\Filesystem::mkdir('newTarget');
|
||||||
|
|
||||||
|
\OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
|
||||||
|
|
||||||
|
// re-login to make sure that the new mount points are initialized
|
||||||
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||||
|
|
||||||
|
\OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
|
||||||
|
|
||||||
|
// re-login to make sure that the new mount points are initialized
|
||||||
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||||
|
|
||||||
|
$this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||||
|
$result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue