Skip to content

Commit cf9b02a

Browse files
fix: review comments
Signed-off-by: Luka Trovic <luka@nextcloud.com>
1 parent 33e7339 commit cf9b02a

2 files changed

Lines changed: 22 additions & 25 deletions

File tree

apps/files_sharing/lib/Command/FixBrokenShares.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,40 @@
22

33
declare(strict_types=1);
44
/**
5-
* @copyright Copyright (c) 2023 Robin Appelman <robin@icewind.nl>
6-
*
7-
* @license GNU AGPL version 3 or any later version
8-
*
9-
* This program is free software: you can redistribute it and/or modify
10-
* it under the terms of the GNU Affero General Public License as
11-
* published by the Free Software Foundation, either version 3 of the
12-
* License, or (at your option) any later version.
13-
*
14-
* This program is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
* GNU Affero General Public License for more details.
18-
*
19-
* You should have received a copy of the GNU Affero General Public License
20-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21-
*
5+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
227
*/
238

249
namespace OCA\Files_Sharing\Command;
2510

2611
use OC\Core\Command\Base;
2712
use OCA\Files_Sharing\OrphanHelper;
2813
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
2915
use Symfony\Component\Console\Output\OutputInterface;
3016

3117
class FixBrokenShares extends Base {
32-
private OrphanHelper $orphanHelper;
33-
34-
public function __construct(OrphanHelper $orphanHelper) {
18+
public function __construct(
19+
private OrphanHelper $orphanHelper
20+
) {
3521
parent::__construct();
36-
$this->orphanHelper = $orphanHelper;
3722
}
3823

3924
protected function configure(): void {
4025
$this
4126
->setName('sharing:fix-broken-shares')
42-
->setDescription('Fix broken shares after transfer ownership');
27+
->setDescription('Fix broken shares after transfer ownership')
28+
->addOption(
29+
'dry-run',
30+
null,
31+
InputOption::VALUE_NONE,
32+
'only show which shares would be updated'
33+
);
4334
}
4435

4536
public function execute(InputInterface $input, OutputInterface $output): int {
4637
$shares = $this->orphanHelper->getAllShares();
38+
$dryRun = $input->getOption('dry-run');
4739

4840
foreach ($shares as $share) {
4941
if ($this->orphanHelper->isShareValid($share['owner'], $share['fileid']) || !$this->orphanHelper->fileExists($share['fileid'])) {
@@ -53,11 +45,15 @@ public function execute(InputInterface $input, OutputInterface $output): int {
5345
$owner = $this->orphanHelper->findOwner($share['fileid']);
5446

5547
if (!empty($owner)) {
56-
$this->orphanHelper->updateShareOwner($share['id'], $owner);
57-
$output->writeln("Share {$share['id']} updated to owner $owner");
48+
if ($dryRun) {
49+
$output->writeln("Share {$share['id']} can be updated to owner $owner");
50+
} else {
51+
$this->orphanHelper->updateShareOwner($share['id'], $owner);
52+
$output->writeln("Share {$share['id']} updated to owner $owner");
53+
}
5854
}
5955
}
6056

61-
return 0;
57+
return static::SUCCESS;
6258
}
6359
}

apps/files_sharing/lib/OrphanHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function findOwner(int $fileId): ?string {
9999
return null;
100100
}
101101
foreach ($mounts as $mount) {
102+
// Only the mount of owner has the internal path value
102103
if ($mount->getInternalPath()) {
103104
return $mount->getUser()->getUID();
104105
}

0 commit comments

Comments
 (0)