Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Jun 4, 2024
1 parent 33e7339 commit cf9b02a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
46 changes: 21 additions & 25 deletions apps/files_sharing/lib/Command/FixBrokenShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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;
}
}
1 change: 1 addition & 0 deletions apps/files_sharing/lib/OrphanHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function findOwner(int $fileId): ?string {
return null;
}
foreach ($mounts as $mount) {
// Only the mount of owner has the internal path value
if ($mount->getInternalPath()) {
return $mount->getUser()->getUID();
}
Expand Down

0 comments on commit cf9b02a

Please sign in to comment.