addArgument( 'uid', InputArgument::REQUIRED, 'User whose unshares to clear' ); } protected function execute(InputInterface $input, OutputInterface $output): int { $user = (string)$input->getArgument('uid'); if (!$this->userManager->userExists($user)) { throw new \InvalidArgumentException("User $user is unknown"); } $principal = $this->principal->getPrincipalByPath('principals/users/' . $user); if ($principal === null) { throw new \InvalidArgumentException("Unable to fetch principal for user $user "); } $shares = $this->mapper->getSharesByPrincipals([$principal['uri']], 'calendar'); $unshares = array_filter($shares, static fn ($share) => $share['access'] === BackendAlias::ACCESS_UNSHARED); if (count($unshares) === 0) { $output->writeln("User $user has no calendar unshares"); return self::SUCCESS; } $rows = array_map(fn ($share) => $this->formatCalendarUnshare($share), $shares); $table = new Table($output); $table ->setHeaders(['Share Id', 'Calendar Id', 'Calendar URI', 'Calendar Name']) ->setRows($rows) ->render(); $output->writeln(''); /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Please confirm to delete the above calendar unshare entries [y/n]', false); if ($helper->ask($input, $output, $question)) { $this->mapper->deleteUnsharesByPrincipal($principal['uri'], 'calendar'); $output->writeln("Calendar unshares for user $user deleted"); } return self::SUCCESS; } private function formatCalendarUnshare(array $share): array { $calendarInfo = $this->caldav->getCalendarById($share['resourceid']); $resourceUri = 'Resource not found'; $resourceName = ''; if ($calendarInfo !== null) { $resourceUri = $calendarInfo['uri']; $resourceName = $calendarInfo['{DAV:}displayname']; } return [ $share['id'], $share['resourceid'], $resourceUri, $resourceName, ]; } }