Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-10-18 16:42:25 +0300
committerRobin Appelman <robin@icewind.nl>2022-11-08 19:13:52 +0300
commit7dc8e6a01448fd028f5e60f7e0cb1cdb7c911815 (patch)
tree70c01ae065355679ef6c021a09b5aa236b36979e
parente09fabd47c4c184c43726b3af79ff44b030a3e42 (diff)
fix repairing non user shares when repairing all shares
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--core/Command/Maintenance/RepairShareOwnership.php43
1 files changed, 33 insertions, 10 deletions
diff --git a/core/Command/Maintenance/RepairShareOwnership.php b/core/Command/Maintenance/RepairShareOwnership.php
index 1101cffd0cc..267e0ca1d48 100644
--- a/core/Command/Maintenance/RepairShareOwnership.php
+++ b/core/Command/Maintenance/RepairShareOwnership.php
@@ -31,7 +31,6 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
-use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -70,15 +69,7 @@ class RepairShareOwnership extends Command {
}
$shares = $this->getWrongShareOwnershipForUser($user);
} else {
- $shares = [];
- $userCount = $this->userManager->countSeenUsers();
- $progress = new ProgressBar($output, $userCount);
- $this->userManager->callForSeenUsers(function (IUser $user) use (&$shares, $progress) {
- $progress->advance();
- $shares = array_merge($shares, $this->getWrongShareOwnershipForUser($user));
- });
- $progress->finish();
- $output->writeln("");
+ $shares = $this->getWrongShareOwnership();
}
if ($shares) {
@@ -108,6 +99,38 @@ class RepairShareOwnership extends Command {
}
/**
+ * @return array{shareId: int, fileTarget: string, initiator: string, receiver: string, owner: string, mountOwner: string}[]
+ * @throws \OCP\DB\Exception
+ */
+ protected function getWrongShareOwnership(): array {
+ $qb = $this->dbConnection->getQueryBuilder();
+ $brokenShares = $qb
+ ->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'))
+ ->where($qb->expr()->neq('m.user_id', 's.uid_owner'))
+ ->andWhere($qb->expr()->eq($qb->func()->concat($qb->expr()->literal('/'), 'm.user_id', $qb->expr()->literal('/')), 'm.mount_point'))
+ ->executeQuery()
+ ->fetchAll();
+
+ $found = [];
+
+ foreach ($brokenShares as $share) {
+ $found[] = [
+ 'shareId' => (int) $share['id'],
+ 'fileTarget' => $share['file_target'],
+ 'initiator' => $share['uid_initiator'],
+ 'receiver' => $share['share_with'],
+ 'owner' => $share['uid_owner'],
+ 'mountOwner' => $share['user_id'],
+ ];
+ }
+
+ return $found;
+ }
+
+ /**
* @param IUser $user
* @return array{shareId: int, fileTarget: string, initiator: string, receiver: string, owner: string, mountOwner: string}[]
* @throws \OCP\DB\Exception