Skip to content

Commit

Permalink
Update public link share in trasnsfer ownership command
Browse files Browse the repository at this point in the history
The public link share wasn't updated in the command.
This resulted in failure, when the public links were
accessed after the files were transferred. This change
helps to update the share for public links. And hence
access to the links won't cause any failure.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Apr 17, 2018
1 parent 06c30ef commit 6423c6c
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions apps/files/lib/Command/TransferOwnership.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,21 @@ private function restoreShares(OutputInterface $output) {
}
$this->shareManager->deleteShare($share);
} else {
if ($share->getShareOwner() === $this->sourceUser) {
$share->setShareOwner($this->destinationUser);
}
if ($share->getSharedBy() === $this->sourceUser) {
$share->setSharedBy($this->destinationUser);
$sharedWith = $share->getSharedWith();
/**
* Scenario where share is made by source user to a user different
* from destination user
*/
if (($sharedWith !== null) && ($sharedWith !== $this->sourceUser) && ($sharedWith !== $this->destinationUser)) {
$this->shareManager->deleteShare($share);
continue;
} else {
if ($share->getShareOwner() === $this->sourceUser) {
$share->setShareOwner($this->destinationUser);
}
if ($share->getSharedBy() === $this->sourceUser) {
$share->setSharedBy($this->destinationUser);
}
}
/*
* If the share is already moved then updateShare would cause exception
Expand All @@ -321,8 +331,16 @@ private function restoreShares(OutputInterface $output) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$sharePath = ltrim($share->getNode()->getPath(), '/');
if (strpos($sharePath, $this->finalTarget) !== false) {
//The share is already moved
continue;
/**
* The share is already moved. So as an alternative we
* create a new share and update the share with the
* details from old share.
*/
$targetFolder = '/' . rtrim(basename($this->finalTarget), '/') . '/' . ltrim(basename($share->getTarget()), '/');
$token = $share->getToken();
$share = $this->shareManager->createShare($share);
$share->setToken($token);
$share->setTarget($targetFolder);
}
}

Expand Down

0 comments on commit 6423c6c

Please sign in to comment.