From 6423c6cffcfde583154c9bbba2725240083d39e9 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Tue, 17 Apr 2018 22:36:08 +0530 Subject: [PATCH] Update public link share in trasnsfer ownership command 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 --- apps/files/lib/Command/TransferOwnership.php | 32 +++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/files/lib/Command/TransferOwnership.php b/apps/files/lib/Command/TransferOwnership.php index 15772f1eb2cd..83ec63bab412 100644 --- a/apps/files/lib/Command/TransferOwnership.php +++ b/apps/files/lib/Command/TransferOwnership.php @@ -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 @@ -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); } }