From 2ca51919db2f1dc425778a4ecf9816c09c8155ed Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Thu, 7 Nov 2024 19:36:36 +0100 Subject: fix(sharing): add command to fix broken shares after ownership transferring Signed-off-by: Luka Trovic --- apps/files_sharing/lib/Command/FixShareOwners.php | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 apps/files_sharing/lib/Command/FixShareOwners.php (limited to 'apps/files_sharing/lib/Command') diff --git a/apps/files_sharing/lib/Command/FixShareOwners.php b/apps/files_sharing/lib/Command/FixShareOwners.php new file mode 100644 index 00000000000..1cf5f82f5a8 --- /dev/null +++ b/apps/files_sharing/lib/Command/FixShareOwners.php @@ -0,0 +1,65 @@ +setName('sharing:fix-share-owners') + ->setDescription('Fix owner of broken shares after transfer ownership on old versions') + ->addOption( + 'dry-run', + null, + InputOption::VALUE_NONE, + 'only show which shares would be updated' + ); + } + + public function execute(InputInterface $input, OutputInterface $output): int { + $shares = $this->orphanHelper->getAllShares(); + $dryRun = $input->getOption('dry-run'); + $count = 0; + + foreach ($shares as $share) { + if ($this->orphanHelper->isShareValid($share['owner'], $share['fileid']) || !$this->orphanHelper->fileExists($share['fileid'])) { + continue; + } + + $owner = $this->orphanHelper->findOwner($share['fileid']); + + if ($owner !== null) { + if ($dryRun) { + $output->writeln("Share with id {$share['id']} (target: {$share['target']}) can be updated to owner $owner"); + } else { + $this->orphanHelper->updateShareOwner($share['id'], $owner); + $output->writeln("Share with id {$share['id']} (target: {$share['target']}) updated to owner $owner"); + } + $count++; + } + } + + if ($count === 0) { + $output->writeln('No broken shares detected'); + } + + return static::SUCCESS; + } +} -- cgit v1.2.3