-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Luka Trovic <[email protected]>
- Loading branch information
1 parent
33e7339
commit cf9b02a
Showing
2 changed files
with
22 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,48 +2,40 @@ | |
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2023 Robin Appelman <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Files_Sharing\Command; | ||
|
||
use OC\Core\Command\Base; | ||
use OCA\Files_Sharing\OrphanHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class FixBrokenShares extends Base { | ||
private OrphanHelper $orphanHelper; | ||
|
||
public function __construct(OrphanHelper $orphanHelper) { | ||
public function __construct( | ||
private OrphanHelper $orphanHelper | ||
) { | ||
parent::__construct(); | ||
$this->orphanHelper = $orphanHelper; | ||
} | ||
|
||
protected function configure(): void { | ||
$this | ||
->setName('sharing:fix-broken-shares') | ||
->setDescription('Fix broken shares after transfer ownership'); | ||
->setDescription('Fix broken shares after transfer ownership') | ||
->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'); | ||
|
||
foreach ($shares as $share) { | ||
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 { | |
$owner = $this->orphanHelper->findOwner($share['fileid']); | ||
|
||
if (!empty($owner)) { | ||
Check notice Code scanning / Psalm RiskyTruthyFalsyComparison Note
Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead.
|
||
$this->orphanHelper->updateShareOwner($share['id'], $owner); | ||
$output->writeln("Share {$share['id']} updated to owner $owner"); | ||
if ($dryRun) { | ||
$output->writeln("Share {$share['id']} can be updated to owner $owner"); | ||
} else { | ||
$this->orphanHelper->updateShareOwner($share['id'], $owner); | ||
$output->writeln("Share {$share['id']} updated to owner $owner"); | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
return static::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters