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; } }