diff options
author | Robin Appelman <robin@icewind.nl> | 2022-09-30 15:34:55 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-11-08 17:13:41 +0100 |
commit | 8012c85d3e9fde9c12ca67c5aa22ddffc835832f (patch) | |
tree | 4d4a1fd9eacdb02d6d4c326fb336e41a39a1c769 | |
parent | 1be1c23c056e899a06cb2830d94a5d84db772a0a (diff) | |
download | nextcloud-server-8012c85d3e9fde9c12ca67c5aa22ddffc835832f.tar.gz nextcloud-server-8012c85d3e9fde9c12ca67c5aa22ddffc835832f.zip |
update shares directly in db
Signed-off-by: Robin Appelman <robin@icewind.nl>
-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; |