|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-only |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\DAV\Command; |
| 11 | + |
| 12 | +use OCA\DAV\Service\AbsenceService; |
| 13 | +use OCP\IUserManager; |
| 14 | +use Symfony\Component\Console\Command\Command; |
| 15 | +use Symfony\Component\Console\Input\InputArgument; |
| 16 | +use Symfony\Component\Console\Input\InputInterface; |
| 17 | +use Symfony\Component\Console\Output\OutputInterface; |
| 18 | + |
| 19 | +class SetAbsenceCommand extends Command { |
| 20 | + |
| 21 | + public function __construct( |
| 22 | + private IUserManager $userManager, |
| 23 | + private AbsenceService $absenceService, |
| 24 | + ) { |
| 25 | + parent::__construct(); |
| 26 | + } |
| 27 | + |
| 28 | + protected function configure(): void { |
| 29 | + $this->setName('dav:absence:set'); |
| 30 | + $this->addArgument( |
| 31 | + 'user-id', |
| 32 | + InputArgument::REQUIRED, |
| 33 | + 'User ID of the affected account' |
| 34 | + ); |
| 35 | + $this->addArgument( |
| 36 | + 'first-day', |
| 37 | + InputArgument::REQUIRED, |
| 38 | + 'Inclusive start day formatted as YYYY-MM-DD' |
| 39 | + ); |
| 40 | + $this->addArgument( |
| 41 | + 'last-day', |
| 42 | + InputArgument::REQUIRED, |
| 43 | + 'Inclusive end day formatted as YYYY-MM-DD' |
| 44 | + ); |
| 45 | + $this->addArgument( |
| 46 | + 'short-message', |
| 47 | + InputArgument::REQUIRED, |
| 48 | + 'Short message' |
| 49 | + ); |
| 50 | + $this->addArgument( |
| 51 | + 'message', |
| 52 | + InputArgument::REQUIRED, |
| 53 | + 'Message' |
| 54 | + ); |
| 55 | + $this->addArgument( |
| 56 | + 'replacement-user-id', |
| 57 | + InputArgument::OPTIONAL, |
| 58 | + 'Replacement user id' |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + public function execute(InputInterface $input, OutputInterface $output): int { |
| 63 | + $userId = $input->getArgument('user-id'); |
| 64 | + |
| 65 | + $user = $this->userManager->get($userId); |
| 66 | + if ($user === null) { |
| 67 | + $output->writeln('<error>User not found</error>'); |
| 68 | + return 1; |
| 69 | + } |
| 70 | + |
| 71 | + $replacementUserId = $input->getArgument('replacement-user-id'); |
| 72 | + if ($replacementUserId === null) { |
| 73 | + $replacementUser = null; |
| 74 | + } else { |
| 75 | + $replacementUser = $this->userManager->get($replacementUserId); |
| 76 | + if ($replacementUser === null) { |
| 77 | + $output->writeln('<error>Replacement user not found</error>'); |
| 78 | + return 2; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + $this->absenceService->createOrUpdateAbsence( |
| 83 | + $user, |
| 84 | + $input->getArgument('first-day'), |
| 85 | + $input->getArgument('last-day'), |
| 86 | + $input->getArgument('short-message'), |
| 87 | + $input->getArgument('message'), |
| 88 | + $replacementUser?->getUID(), |
| 89 | + $replacementUser?->getDisplayName(), |
| 90 | + ); |
| 91 | + |
| 92 | + return 0; |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments