Skip broken shares when transferring ownership (#26527)

This commit is contained in:
Vincent Petry 2016-11-07 20:20:16 +01:00 committed by Roeland Jago Douma
parent cebb689925
commit 2b61b89391
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 21 additions and 15 deletions

View File

@ -224,22 +224,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();
}