summaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib/Command')
-rw-r--r--apps/files/lib/Command/TransferOwnership.php44
1 files changed, 25 insertions, 19 deletions
diff --git a/apps/files/lib/Command/TransferOwnership.php b/apps/files/lib/Command/TransferOwnership.php
index 378654d5bf8..78487ce4d96 100644
--- a/apps/files/lib/Command/TransferOwnership.php
+++ b/apps/files/lib/Command/TransferOwnership.php
@@ -97,12 +97,12 @@ class TransferOwnership extends Command {
if (!$sourceUserObject instanceof IUser) {
$output->writeln("<error>Unknown source user $this->sourceUser</error>");
- return;
+ return 1;
}
if (!$destinationUserObject instanceof IUser) {
$output->writeln("<error>Unknown destination user $this->destinationUser</error>");
- return;
+ return 1;
}
$this->sourceUser = $sourceUserObject->getUID();
@@ -111,7 +111,7 @@ class TransferOwnership extends Command {
// target user has to be ready
if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
$output->writeln("<error>The target user is not ready to accept files. The user has at least to be logged in once.</error>");
- return;
+ return 2;
}
$date = date('c');
@@ -193,7 +193,7 @@ class TransferOwnership extends Command {
$output->writeln("Collecting all share information for files and folder of $this->sourceUser ...");
$progress = new ProgressBar($output, count($this->shares));
- foreach([\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) {
+ foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) {
$offset = 0;
while (true) {
$sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset);
@@ -229,22 +229,28 @@ class TransferOwnership extends Command {
$progress = new ProgressBar($output, count($this->shares));
foreach($this->shares as $share) {
- if ($share->getSharedWith() === $this->destinationUser) {
- // Unmount the shares before deleting, so we don't try to get the storage later on.
- $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
- if ($shareMountPoint) {
- $this->mountManager->removeMount($shareMountPoint->getMountPoint());
- }
- $this->shareManager->deleteShare($share);
- } else {
- if ($share->getShareOwner() === $this->sourceUser) {
- $share->setShareOwner($this->destinationUser);
- }
- if ($share->getSharedBy() === $this->sourceUser) {
- $share->setSharedBy($this->destinationUser);
- }
+ try {
+ if ($share->getSharedWith() === $this->destinationUser) {
+ // Unmount the shares before deleting, so we don't try to get the storage later on.
+ $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
+ if ($shareMountPoint) {
+ $this->mountManager->removeMount($shareMountPoint->getMountPoint());
+ }
+ $this->shareManager->deleteShare($share);
+ } else {
+ if ($share->getShareOwner() === $this->sourceUser) {
+ $share->setShareOwner($this->destinationUser);
+ }
+ if ($share->getSharedBy() === $this->sourceUser) {
+ $share->setSharedBy($this->destinationUser);
+ }
- $this->shareManager->updateShare($share);
+ $this->shareManager->updateShare($share);
+ }
+ } catch (\OCP\Files\NotFoundException $e) {
+ $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
+ } catch (\Exception $e) {
+ $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
}
$progress->advance();
}