X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FState%2FDeleteCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FState%2FDeleteCommand.php;h=402f878aae83507414b4b487ea0221480c19cb55;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/State/DeleteCommand.php b/vendor/drupal/console/src/Command/State/DeleteCommand.php new file mode 100644 index 000000000..402f878aa --- /dev/null +++ b/vendor/drupal/console/src/Command/State/DeleteCommand.php @@ -0,0 +1,120 @@ +state = $state; + $this->keyValue = $keyValue; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('state:delete') + ->setDescription($this->trans('commands.state.delete.description')) + ->addArgument( + 'name', + InputArgument::OPTIONAL, + $this->trans('commands.state.delete.arguments.name') + ); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + $name = $input->getArgument('name'); + if (!$name) { + $names = array_keys($this->keyValue->get('state')->getAll()); + $name = $io->choiceNoList( + $this->trans('commands.state.delete.arguments.name'), + $names + ); + $input->setArgument('name', $name); + } + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + $name = $input->getArgument('name'); + if (!$name) { + $io->error($this->trans('commands.state.delete.messages.enter-name')); + + return 1; + } + + if (!$this->state->get($name)) { + $io->error( + sprintf( + $this->trans('commands.state.delete.messages.state-not-exists'), + $name + ) + ); + + return 1; + } + + try { + $this->state->delete($name); + } catch (\Exception $e) { + $io->error($e->getMessage()); + + return 1; + } + + $io->success( + sprintf( + $this->trans('commands.state.delete.messages.deleted'), + $name + ) + ); + + return 0; + } +}