tableService = $tableService; $this->logger = $logger; } protected function configure(): void { $this ->setName('tables:add') ->setDescription('Add a table.') ->addArgument( 'user-id', InputArgument::REQUIRED, 'User ID of the user' ) ->addArgument( 'title', InputArgument::REQUIRED, 'Title for the table.' ) ->addOption( 'emoji', 'e', InputOption::VALUE_OPTIONAL, 'Add an emoji.' ) ->addOption( 'template', 't', InputOption::VALUE_OPTIONAL, 'Insert structure and data from template.' ) ; } /** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output): int { $userId = $input->getArgument('user-id'); $title = $input->getArgument('title'); $emoji = $input->getOption('emoji') ?: ''; $template = $input->getOption('template') ?: ''; try { $table = $this->tableService->create($title, $template, $emoji, $userId); $arr = $table->jsonSerialize(); unset($arr['hasShares']); unset($arr['isShared']); unset($arr['onSharePermissions']); unset($arr['rowsCount']); unset($arr['ownerDisplayName']); $output->writeln(json_encode($arr, JSON_PRETTY_PRINT)); } catch (InternalError|PermissionError|Exception $e) { $output->writeln('Error occurred: ' . $e->getMessage()); $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } return 0; } }