2015-11-05 05:37:31 -05:00
|
|
|
<?php
|
2024-05-27 11:39:07 -04:00
|
|
|
|
2016-01-12 09:02:16 -05:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-01-12 09:02:16 -05:00
|
|
|
*/
|
2015-11-05 05:37:31 -05:00
|
|
|
namespace OCA\DAV\Command;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\CardDAV\CardDavBackend;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class CreateAddressBook extends Command {
|
2023-07-05 10:15:43 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IUserManager $userManager,
|
|
|
|
|
private CardDavBackend $cardDavBackend,
|
2015-11-25 09:24:50 -05:00
|
|
|
) {
|
2015-11-05 05:37:31 -05:00
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-05 10:15:43 -04:00
|
|
|
protected function configure(): void {
|
2015-11-05 05:37:31 -05:00
|
|
|
$this
|
2024-08-23 09:10:27 -04:00
|
|
|
->setName('dav:create-addressbook')
|
|
|
|
|
->setDescription('Create a dav addressbook')
|
|
|
|
|
->addArgument('user',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'User for whom the addressbook will be created')
|
|
|
|
|
->addArgument('name',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'Name of the addressbook');
|
2015-11-05 05:37:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 09:12:11 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2015-11-05 05:37:31 -05:00
|
|
|
$user = $input->getArgument('user');
|
|
|
|
|
if (!$this->userManager->userExists($user)) {
|
|
|
|
|
throw new \InvalidArgumentException("User <$user> in unknown.");
|
|
|
|
|
}
|
2015-11-25 06:27:25 -05:00
|
|
|
|
2015-11-05 05:37:31 -05:00
|
|
|
$name = $input->getArgument('name');
|
2016-02-03 09:43:45 -05:00
|
|
|
$this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
|
2023-07-05 10:15:43 -04:00
|
|
|
return self::SUCCESS;
|
2015-11-05 05:37:31 -05:00
|
|
|
}
|
|
|
|
|
}
|