diff options
author | Robin Appelman <robin@icewind.nl> | 2022-09-30 15:34:55 +0200 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-11-08 22:38:33 +0000 |
commit | 54177019f2541e12d3971f6120c4a6ab99672374 (patch) | |
tree | f1364d3f2694a9f9e11c3c9d9ddfd365da5df716 /core | |
parent | 52f10b18eedb6eda250d720b32ac794b073aa3f6 (diff) | |
download | nextcloud-server-54177019f2541e12d3971f6120c4a6ab99672374.tar.gz nextcloud-server-54177019f2541e12d3971f6120c4a6ab99672374.zip |
update shares directly in db
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'core')
-rw-r--r-- | core/Command/Maintenance/RepairShareOwnership.php | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/core/Command/Maintenance/RepairShareOwnership.php b/core/Command/Maintenance/RepairShareOwnership.php index 1175ff469b7..1f5d5a44a8b 100644 --- a/core/Command/Maintenance/RepairShareOwnership.php +++ b/core/Command/Maintenance/RepairShareOwnership.php @@ -40,16 +40,13 @@ use Symfony\Component\Console\Output\OutputInterface; class RepairShareOwnership extends Command { private IDBConnection $dbConnection; - private IManager $shareManager; private IUserManager $userManager; public function __construct( IDBConnection $dbConnection, - IManager $shareManager, IUserManager $userManager ) { $this->dbConnection = $dbConnection; - $this->shareManager = $shareManager; $this->userManager = $userManager; parent::__construct(); } @@ -65,6 +62,7 @@ class RepairShareOwnership extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { $dryRun = $input->getOption('dry-run'); $userId = $input->getArgument('user'); + $this->dbConnection->beginTransaction(); if ($userId) { $user = $this->userManager->get($userId); if (!$user) { @@ -86,13 +84,15 @@ class RepairShareOwnership extends Command { foreach ($found as $item) { $output->writeln($item); } + $this->dbConnection->commit(); + return 0; } protected function repairWrongShareOwnershipForUser(IUser $user, bool $dryRun = true): array { $qb = $this->dbConnection->getQueryBuilder(); $brokenShare = $qb - ->select('s.id', 'm.user_id', 's.uid_owner', 's.uid_initiator', 's.share_with', 's.share_type', 's.file_target') + ->select('s.id', 'm.user_id', 's.uid_owner', 's.uid_initiator', 's.share_with', 's.file_target') ->from('share', 's') ->join('s', 'filecache', 'f', $qb->expr()->eq('s.item_source', $qb->expr()->castColumn('f.fileid', IQueryBuilder::PARAM_STR))) ->join('s', 'mounts', 'm', $qb->expr()->eq('f.storage', 'm.storage_id')) @@ -104,9 +104,14 @@ class RepairShareOwnership extends Command { $found = []; + $update = $this->dbConnection->getQueryBuilder(); + $update->update('share') + ->set('uid_owner', $update->createParameter('share_owner')) + ->set('uid_initiator', $update->createParameter('share_initiator')) + ->where($update->expr()->eq('id', $update->createParameter('share_id'))); + foreach ($brokenShare as $queryResult) { $shareId = (int) $queryResult['id']; - $shareType = (int) $queryResult['share_type']; $fileTarget = $queryResult['file_target']; $initiator = $queryResult['uid_initiator']; $receiver = $queryResult['share_with']; @@ -119,15 +124,14 @@ class RepairShareOwnership extends Command { continue; } - $provider = $this->shareManager->getProviderForType($shareType); - $share = $provider->getShareById($shareId); - - if ($share->getShareOwner() === $share->getSharedBy()) { - $share->setSharedBy($mountOwner); + $update->setParameter('share_id', $shareId, IQueryBuilder::PARAM_INT); + $update->setParameter('share_owner', $mountOwner); + if ($initiator === $owner) { + $update->setParameter('share_initiator', $mountOwner); + } else { + $update->setParameter('share_initiator', $initiator); } - $share->setShareOwner($mountOwner); - - $this->shareManager->updateShare($share); + $update->executeStatement(); } return $found; |