mirror of
https://github.com/nextcloud/server.git
synced 2026-11-07 00:14:42 +01:00
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\Sharing\Command;
|
|
|
|
use NCU\Sharing\Exception\ShareInvalidException;
|
|
use NCU\Sharing\Share;
|
|
use NCU\Sharing\ShareAccessContext;
|
|
use OCP\IUserManager;
|
|
use OCP\L10N\IFactory;
|
|
use OCP\Server;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
final class CreateShare extends SharingBase {
|
|
#[\Override]
|
|
public function configure(): void {
|
|
$this
|
|
->setName('sharing:create-share')
|
|
->setDescription('Create a new share.')
|
|
->addArgument('owner', InputArgument::REQUIRED, 'User ID of the owner');
|
|
parent::configure();
|
|
}
|
|
|
|
#[\Override]
|
|
public function execute(InputInterface $input, OutputInterface $output): int {
|
|
/** @var string $ownerUid */
|
|
$ownerUid = $input->getArgument('owner');
|
|
$owner = Server::get(IUserManager::class)->get($ownerUid);
|
|
if ($owner === null) {
|
|
throw new ShareInvalidException('The owner does not exist: ' . $ownerUid, Server::get(IFactory::class)->get('sharing')->t('The owner does not exist: %s', [$ownerUid]));
|
|
}
|
|
|
|
return $this->wrapExecution($input, $output, fn (): Share => $this->manager->createShare(new ShareAccessContext($owner)));
|
|
}
|
|
}
|