setDescription('List all addressbooks of a user') ->addArgument('uid', InputArgument::REQUIRED, 'User for whom all addressbooks will be listed'); } protected function execute(InputInterface $input, OutputInterface $output): int { $user = $input->getArgument('uid'); if (!$this->userManager->userExists($user)) { throw new \InvalidArgumentException("User <$user> is unknown."); } $addressBooks = $this->cardDavBackend->getAddressBooksForUser("principals/users/$user"); $addressBookTableData = []; foreach ($addressBooks as $book) { // skip system / contacts integration address book if ($book['uri'] === SystemAddressbook::URI_SHARED) { continue; } $readOnly = false; $readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; if (isset($book[$readOnlyIndex])) { $readOnly = $book[$readOnlyIndex]; } $addressBookTableData[] = [ $book['uri'], $book['{DAV:}displayname'], $book['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'] ?? $book['principaluri'], $book['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'], $readOnly ? ' x ' : ' ✓ ', ]; } if (count($addressBookTableData) > 0) { $table = new Table($output); $table->setHeaders(['Database ID', 'URI', 'Displayname', 'Owner principal', 'Owner displayname', 'Writable']) ->setRows($addressBookTableData); $table->render(); } else { $output->writeln("User <$user> has no addressbooks"); } return self::SUCCESS; } }