aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Service
diff options
context:
space:
mode:
authorTobia De Koninck <LEDfan@users.noreply.github.com>2020-01-03 08:43:39 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2020-02-03 11:15:56 +0100
commit7c56144f4927ed56d02c197710833c2b10c2f65d (patch)
tree7e83aa441d61636403136d8e7cc4f5864154ef57 /apps/files/lib/Service
parent411058e47cd42871b2099190ac67f47b9bd17e30 (diff)
downloadnextcloud-server-7c56144f4927ed56d02c197710833c2b10c2f65d.tar.gz
nextcloud-server-7c56144f4927ed56d02c197710833c2b10c2f65d.zip
Add option to transfer-ownership to move data
This will move the home folder of own user to another user. Only allowed if that other user's home folder is empty. Can be used as workaround to rename users. Signed-off-by: Tobia De Koninck <LEDfan@users.noreply.github.com>
Diffstat (limited to 'apps/files/lib/Service')
-rw-r--r--apps/files/lib/Service/OwnershipTransferService.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php
index 8530edd17b1..8af894a0167 100644
--- a/apps/files/lib/Service/OwnershipTransferService.php
+++ b/apps/files/lib/Service/OwnershipTransferService.php
@@ -71,12 +71,16 @@ class OwnershipTransferService {
* @param IUser $destinationUser
* @param string $path
*
+ * @param OutputInterface|null $output
+ * @param bool $move
* @throws TransferOwnershipException
+ * @throws \OC\User\NoUserException
*/
public function transfer(IUser $sourceUser,
IUser $destinationUser,
string $path,
- ?OutputInterface $output = null): void {
+ ?OutputInterface $output = null,
+ bool $move = false): void {
$output = $output ?? new NullOutput();
$sourceUid = $sourceUser->getUID();
$destinationUid = $destinationUser->getUID();
@@ -87,8 +91,12 @@ class OwnershipTransferService {
throw new TransferOwnershipException("The target user is not ready to accept files. The user has at least to have logged in once.", 2);
}
- $date = date('Y-m-d H-i-s');
- $finalTarget = "$destinationUid/files/transferred from $sourceUid on $date";
+ if ($move) {
+ $finalTarget = "$destinationUid/files/";
+ } else {
+ $date = date('Y-m-d H-i-s');
+ $finalTarget = "$destinationUid/files/transferred from $sourceUid on $date";
+ }
// setup filesystem
Filesystem::initMountPoints($sourceUid);
@@ -99,6 +107,11 @@ class OwnershipTransferService {
throw new TransferOwnershipException("Unknown path provided: $path", 1);
}
+ if ($move && (!$view->is_dir($finalTarget) || count($view->getDirectoryContent($finalTarget)) > 0)) {
+ throw new TransferOwnershipException("Destination path does not exists or is not empty", 1);
+ }
+
+
// analyse source folder
$this->analyse(
$sourceUid,