22
33declare (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
249namespace OCA \Files_Sharing \Command ;
2510
2611use OC \Core \Command \Base ;
2712use OCA \Files_Sharing \OrphanHelper ;
2813use Symfony \Component \Console \Input \InputInterface ;
14+ use Symfony \Component \Console \Input \InputOption ;
2915use Symfony \Component \Console \Output \OutputInterface ;
3016
3117class 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}
0 commit comments