/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $id = $input->getOption('id'); try { $data = $this->demoRepository->getById($id); $table = $this->getHelper('table'); $table->setHeaders(array(__('ID'), __('Title'), __('Created'), __('Updated'), __('Visible'), __('Active')))->setRows([[$data->getId(), $data->getTitle(), $data->getCreationTime(), $data->getUpdateTime(), $data->getIsVisible() ? __('Yes') : __('No'), $data->getIsActive() ? __('Yes') : __('No')]]); $table->render($output); } catch (\Exception $ex) { $output->writeln('<error>' . $ex->getMessage() . '</error>'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); $id = $input->getOption('id'); try { if (!$input->getOption('force')) { $data = $this->demoRepository->getById($id); $output->writeln('Id :' . $data->getId()); $output->writeln('Title :' . $data->getTitle()); $question = new ConfirmationQuestion('Are you sure you want to delete this record? ', false); if (!$helper->ask($input, $output, $question)) { return; } } $data = $this->demoRepository->deleteById($id); if ($data) { $output->writeln('<info>Record deleted!</info>'); } else { $output->writeln('<error>Unable to delete record!</error>'); } } catch (\Exception $ex) { $output->writeln('<error>' . $ex->getMessage() . '</error>'); } }