From 366ce7c6fdf044c77bbe7ea13ef97788aaf155ff Mon Sep 17 00:00:00 2001 From: dantleech Date: Wed, 28 Sep 2016 20:01:35 +0100 Subject: [PATCH] Fixed confirmation questions --- src/PHPCR/Shell/Config/ConfigManager.php | 17 ++++------------- .../Console/Command/Phpcr/NodeEditCommand.php | 3 ++- .../Command/Phpcr/NodePropertySetCommand.php | 2 +- .../Command/Phpcr/NodeTypeEditCommand.php | 3 ++- .../Command/Phpcr/SessionExportCommand.php | 3 ++- .../Console/Command/Shell/ConfigInitCommand.php | 2 +- .../Shell/Console/Command/Shell/ExitCommand.php | 4 ++-- .../Subscriber/ProfileWriterSubscriber.php | 5 +++-- 8 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/PHPCR/Shell/Config/ConfigManager.php b/src/PHPCR/Shell/Config/ConfigManager.php index e585cea2..b74638f6 100644 --- a/src/PHPCR/Shell/Config/ConfigManager.php +++ b/src/PHPCR/Shell/Config/ConfigManager.php @@ -174,7 +174,7 @@ public function getPhpcrshConfig() /** * Initialize a configuration files. */ - public function initConfig(OutputInterface $output = null, $noInteraction = false) + public function initConfig(OutputInterface $output = null) { $log = function ($message) use ($output) { if ($output) { @@ -208,18 +208,9 @@ public function initConfig(OutputInterface $output = null, $noInteraction = fals } if ($this->filesystem->exists($destFile)) { - if (false === $noInteraction) { - $confirmed = $this->questionHelper->askConfirmation( - $output, - '"'.$configFilename.'" already exists, do you want to overwrite it?' - ); - - if (!$confirmed) { - continue; - } - } else { - $log(sprintf('File %s already exists, not overwriting.', $destFile)); - } + $log(sprintf('File %s already exists, not overwriting.', $destFile)); + + return; } $this->filesystem->copy($srcFile, $destFile); diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php index bbf0b0d8..ed5c1fc2 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeEditCommand.php @@ -20,6 +20,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Serializer\Serializer; class NodeEditCommand extends BasePhpcrCommand @@ -121,7 +122,7 @@ public function execute(InputInterface $input, OutputInterface $output) $error = $e->getMessage(); $output->writeln(''.$error.''); if (false === $input->getOption('no-interaction')) { - $tryAgain = $dialog->askConfirmation($output, 'Do you want to try again? (y/n)'); + $tryAgain = $dialog->ask($input, $output, new ConfirmationQuestion('Do you want to try again? (y/n)')); } $outStr = $inStr; } diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php index 3ac731f3..812cc4cd 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php @@ -65,7 +65,7 @@ public function execute(InputInterface $input, OutputInterface $output) if ($type) { $intType = PropertyType::valueFromName($type); - if ($intType === PropertyType::REFERENCE || $intType === PropertyType::WEAKREFERENCE) { + if ($intType === PropertyType::REFERENCE || $intType === PropertyType::WEAKREFERENCE) { // convert path to UUID if (false === UUIDHelper::isUuid($value)) { $path = $value; diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php index f6236bb7..099c28ec 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php @@ -19,6 +19,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; class NodeTypeEditCommand extends BasePhpcrCommand { @@ -101,7 +102,7 @@ public function execute(InputInterface $input, OutputInterface $output) $tryAgain = false; if (false === $input->getOption('no-interaction')) { - $tryAgain = $dialog->askConfirmation($output, 'Do you want to try again? (y/n)'); + $tryAgain = $dialog->ask($input, $output, new ConfirmationQuestion('Do you want to try again? (y/n)')); } if (false === $tryAgain) { diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/SessionExportCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/SessionExportCommand.php index 2add3660..18eef323 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/SessionExportCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/SessionExportCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; class SessionExportCommand extends BasePhpcrCommand { @@ -64,7 +65,7 @@ public function execute(InputInterface $input, OutputInterface $output) $confirmed = true; if (false === $input->getOption('no-interaction')) { - $confirmed = $dialog->askConfirmation($output, 'File already exists, overwrite?'); + $confirmed = $dialog->ask($input, $output, new ConfirmationQuestion('File already exists, overwrite?')); } if (false === $confirmed) { diff --git a/src/PHPCR/Shell/Console/Command/Shell/ConfigInitCommand.php b/src/PHPCR/Shell/Console/Command/Shell/ConfigInitCommand.php index f42ca560..8f797752 100644 --- a/src/PHPCR/Shell/Console/Command/Shell/ConfigInitCommand.php +++ b/src/PHPCR/Shell/Console/Command/Shell/ConfigInitCommand.php @@ -34,6 +34,6 @@ public function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $configHelper = $this->get('config.manager'); - $configHelper->initConfig($output, $input->getOption('no-interaction')); + $configHelper->initConfig($output); } } diff --git a/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php b/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php index 543b602e..065a01d3 100644 --- a/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php +++ b/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php @@ -15,6 +15,7 @@ use PHPCR\Shell\Console\Command\BaseCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; class ExitCommand extends BaseCommand { @@ -28,13 +29,12 @@ public function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->get('helper.question'); $session = $this->get('phpcr.session'); - $noInteraction = $input->getOption('no-interaction'); if ($session->hasPendingChanges()) { $res = false; if ($input->isInteractive()) { - $res = $dialog->askConfirmation($output, 'Session has pending changes, are you sure you want to quit? (Y/N)', false); + $res = $dialog->ask($input, $output, new ConfirmationQuestion('Session has pending changes, are you sure you want to quit? (Y/N)', false)); } if (false === $res) { diff --git a/src/PHPCR/Shell/Subscriber/ProfileWriterSubscriber.php b/src/PHPCR/Shell/Subscriber/ProfileWriterSubscriber.php index 5e605bdc..24810d6e 100644 --- a/src/PHPCR/Shell/Subscriber/ProfileWriterSubscriber.php +++ b/src/PHPCR/Shell/Subscriber/ProfileWriterSubscriber.php @@ -16,6 +16,7 @@ use PHPCR\Shell\Event\PhpcrShellEvents; use PHPCR\Shell\Event\ProfileInitEvent; use Symfony\Component\Console\Helper\QuestionHelper; +use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ProfileWriterSubscriber implements EventSubscriberInterface @@ -54,14 +55,14 @@ public function handleProfileInit(ProfileInitEvent $e) if (file_exists($this->profileLoader->getProfilePath($profileName))) { $res = true; if (false === $noInteraction) { - $res = $this->questionHelper->askConfirmation($output, sprintf('Update existing profile "%s"?', $profileName)); + $res = $this->questionHelper->ask($input, $output, new ConfirmationQuestion(sprintf('Update existing profile "%s"?', $profileName))); } $overwrite = true; } else { $res = true; if (false === $noInteraction) { - $res = $this->questionHelper->askConfirmation($output, sprintf('Create new profile "%s"?', $profileName)); + $res = $this->questionHelper->ask($input, $output, new ConfirmationQuestion(sprintf('Create new profile "%s"?', $profileName))); } }