Transfer ownership function polishing

Signed-off-by: Sascha Wiswedel <sascha.wiswedel@nextcloud.com>
This commit is contained in:
Sascha Wiswedel 2019-12-06 14:30:05 +01:00 committed by Roeland Jago Douma
parent a65269ffcd
commit f1319e1bc5
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 13 additions and 13 deletions

View File

@ -83,7 +83,7 @@ class OwnershipTransferService {
// target user has to be ready // target user has to be ready
if (!$this->encryptionManager->isReadyForUser($destinationUid)) { if (!$this->encryptionManager->isReadyForUser($destinationUid)) {
throw new TransferOwnershipException("The target user is not ready to accept files. The user has at least to be logged in once.", 2); 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'); $date = date('Y-m-d H-i-s');
@ -156,8 +156,8 @@ class OwnershipTransferService {
$size = $view->getFileInfo($sourcePath, false)->getSize(false); $size = $view->getFileInfo($sourcePath, false)->getSize(false);
$freeSpace = $view->free_space($destinationUid . '/files/'); $freeSpace = $view->free_space($destinationUid . '/files/');
if ($size > $freeSpace) { if ($size > $freeSpace) {
$output->writeln('<error>Target user does not have enough free space available</error>'); $output->writeln('<error>Target user does not have enough free space available.</error>');
throw new \Exception('Execution terminated'); throw new \Exception('Execution terminated.');
} }
$output->writeln("Analysing files of $sourceUid ..."); $output->writeln("Analysing files of $sourceUid ...");
@ -185,7 +185,7 @@ class OwnershipTransferService {
// no file is allowed to be encrypted // no file is allowed to be encrypted
if (!empty($encryptedFiles)) { if (!empty($encryptedFiles)) {
$output->writeln("<error>Some files are encrypted - please decrypt them first</error>"); $output->writeln("<error>Some files are encrypted - please decrypt them first.</error>");
foreach ($encryptedFiles as $encryptedFile) { foreach ($encryptedFiles as $encryptedFile) {
/** @var FileInfo $encryptedFile */ /** @var FileInfo $encryptedFile */
$output->writeln(" " . $encryptedFile->getPath()); $output->writeln(" " . $encryptedFile->getPath());
@ -196,7 +196,7 @@ class OwnershipTransferService {
private function collectUsersShares(string $sourceUid, private function collectUsersShares(string $sourceUid,
OutputInterface $output): array { OutputInterface $output): array {
$output->writeln("Collecting all share information for files and folder of $sourceUid ..."); $output->writeln("Collecting all share information for files and folders of $sourceUid ...");
$shares = []; $shares = [];
$progress = new ProgressBar($output); $progress = new ProgressBar($output);
@ -235,7 +235,7 @@ class OwnershipTransferService {
$finalTarget = $finalTarget . '/' . basename($sourcePath); $finalTarget = $finalTarget . '/' . basename($sourcePath);
} }
if ($view->rename($sourcePath, $finalTarget) === false) { if ($view->rename($sourcePath, $finalTarget) === false) {
throw new TransferOwnershipException("Could not transfer files", 1); throw new TransferOwnershipException("Could not transfer files.", 1);
} }
if (!is_dir("$sourceUid/files")) { if (!is_dir("$sourceUid/files")) {
// because the files folder is moved away we need to recreate it // because the files folder is moved away we need to recreate it

View File

@ -23,15 +23,15 @@
<div> <div>
<h3>{{ t('files', 'Transfer ownership') }} </h3> <h3>{{ t('files', 'Transfer ownership') }} </h3>
<p> <p>
{{ t('files', 'Here you can select a directory that is transferred to another user. It may take some time until the process is done.') }} {{ t('files', 'Select a file or directory to be transferred to another user. It may take some time until the process is done.') }}
</p> </p>
<form @submit.prevent="submit"> <form @submit.prevent="submit">
<ol> <ol>
<li> <li>
<div class="step-header"> <div class="step-header">
{{ t('files', 'Directory to move') }} {{ t('files', 'File or directory be transferred') }}
</div> </div>
<span v-if="directory === undefined">{{ t('files', 'No directory selected') }}</span> <span v-if="directory === undefined">{{ t('files', 'Nothing selected') }}</span>
<span v-else>{{ directory }}</span> <span v-else>{{ directory }}</span>
<button class="primary" @click.prevent="start"> <button class="primary" @click.prevent="start">
{{ t('files', 'Select') }} {{ t('files', 'Select') }}
@ -61,7 +61,7 @@
<li> <li>
<input type="submit" <input type="submit"
class="primary" class="primary"
:value="t('files', 'Submit')" :value="t('files', 'Transfer')"
:disabled="!canSubmit"> :disabled="!canSubmit">
<span class="error">{{ submitError }}</span> <span class="error">{{ submitError }}</span>
</li> </li>
@ -80,7 +80,7 @@ import Vue from 'vue'
import logger from '../logger' import logger from '../logger'
const picker = getFilePickerBuilder(t('files', 'Select directory to transfer')) const picker = getFilePickerBuilder(t('files', 'Select a file or directory to be transferred'))
.setMultiSelect(false) .setMultiSelect(false)
.setModal(true) .setModal(true)
.setType(1) .setType(1)
@ -127,7 +127,7 @@ export default {
picker.pick() picker.pick()
.then(dir => dir === '' ? '/' : dir) .then(dir => dir === '' ? '/' : dir)
.then(dir => { .then(dir => {
logger.debug(`path ${dir} selected for transfer ownership`) logger.debug(`path ${dir} selected for transferring ownership`)
if (!dir.startsWith('/')) { if (!dir.startsWith('/')) {
throw new Error(t('files', 'Invalid path selected')) throw new Error(t('files', 'Invalid path selected'))
} }
@ -135,7 +135,7 @@ export default {
// /ocs/v2.php/apps/files/api/v1/transferownership // /ocs/v2.php/apps/files/api/v1/transferownership
this.directory = dir this.directory = dir
}).catch(error => { }).catch(error => {
logger.error(`Selecting dir for transfer aborted: ${error.message || 'Unknown error'}`, { error }) logger.error(`Selecting object for transfer aborted: ${error.message || 'Unknown error'}`, { error })
this.directoryPickerError = error.message || t('files', 'Unknown error') this.directoryPickerError = error.message || t('files', 'Unknown error')
}) })