setName('dav:delete-calendar') ->setDescription('Delete a dav calendar') ->addArgument('uid', InputArgument::REQUIRED, 'User who owns the calendar') ->addArgument('name', InputArgument::OPTIONAL, 'Name of the calendar to delete') ->addOption('birthday', null, InputOption::VALUE_NONE, 'Delete the birthday calendar') ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force delete skipping trashbin'); } protected function execute( InputInterface $input, OutputInterface $output, ): int { /** @var string $user */ $user = $input->getArgument('uid'); if (!$this->userManager->userExists($user)) { throw new \InvalidArgumentException( 'User <' . $user . '> is unknown.'); } $birthday = $input->getOption('birthday'); if ($birthday !== false) { $name = BirthdayService::BIRTHDAY_CALENDAR_URI; } else { /** @var string $name */ $name = $input->getArgument('name'); if (!$name) { throw new \InvalidArgumentException( 'Please specify a calendar name or --birthday'); } } $calendarInfo = $this->calDav->getCalendarByUri( 'principals/users/' . $user, $name); if ($calendarInfo === null) { throw new \InvalidArgumentException( 'User <' . $user . '> has no calendar named <' . $name . '>. You can run occ dav:list-calendars to list calendars URIs for this user.'); } $calendar = new Calendar( $this->calDav, $calendarInfo, $this->l10n, $this->config, $this->logger ); $force = $input->getOption('force'); if ($force) { $calendar->disableTrashbin(); } $calendar->delete(); return self::SUCCESS; } }