InputOption::VALUE_REQUIRED,
'selectively provide the path to transfer. For example --path="folder_name"',
''
- );
+ )->addOption(
+ 'move',
+ null,
+ InputOption::VALUE_NONE,
+ 'move data from source user to root directory of destination user, which must be empty'
+ );
}
protected function execute(InputInterface $input, OutputInterface $output) {
$sourceUserObject,
$destinationUserObject,
ltrim($input->getOption('path'), '/'),
- $output
+ $output,
+ $input->getOption('move') === true
);
} catch (TransferOwnershipException $e) {
$output->writeln("<error>" . $e->getMessage() . "</error>");
* @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();
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);
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,