ConfirmationQuestion example


    public function continueWithExistingTables($databaseName, PDO $pdo)
    {
        $service = new DatabaseService($pdo);
        $tableCount = $service->getTableCount();
        if ($tableCount == 0) {
            return true;
        }

        $question = new ConfirmationQuestion(
            sprintf(
                'The database %s already contains %s tables. Continue? (yes/no) [no]',
                $databaseName,
                $tableCount
            ),
            false
        );

        return $this->askQuestion($question);
    }

    
/** * Ask for confirmation * * @param string|Question $question * * @return string */
    public function askConfirmation($question, bool $default = true)
    {
        $question = $question instanceof ConfirmationQuestion
            ? $question
            : new ConfirmationQuestion($question$default);

        return $this->questionHelper->ask($this->input, $this->output, $question);
    }

    /** * Ask a question and validate the result * * @param string|Question $question * @param bool|callable $validator * @param bool|int $attempts * @param string|null $default * * @return string */
/** * {@inheritdoc} */
    protected function configure(): void
    {
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $helper = $this->getHelper('question');

        $question = new ConfirmationQuestion('This will delete all files unnecessary to build the administration. Do you want to continue? (y/n)');

        if (!$helper->ask($input$output$question)) {
            $output->writeln('Command aborted!');

            return 0;
        }

        $adminDir = \dirname((string) (new \ReflectionClass(Administration::class))->getFileName());
        $output->writeln('Deleting unnecessary files of the administration after the build process...');
        $progressBar = new ProgressBar($output, 100);

        
try {
            $this->createApp($dir$details$input->getOption('theme'));
        } catch (\RuntimeException $e) {
            $io->error($e->getMessage());

            return self::FAILURE;
        }

        $doInstall = $input->getOption('install');

        if (!$doInstall && $input->isInteractive()) {
            $question = new ConfirmationQuestion('Would you like to install your app? ', false);
            $doInstall = $io->askQuestion($question);
        }

        if ($doInstall) {
            $this->appLifecycle->install(
                Manifest::createFromXmlFile($dir . '/manifest.xml'),
                true,
                Context::createDefaultContext()
            );

            $io->success(sprintf('App %s has been successfully installed.', $details['name']));
        }
return $value;
        };

        $dbUser = $io->ask('Database user', 'app', $emptyValidation);
        $dbPass = $io->askHidden('Database password') ?: '';
        $dbHost = $io->ask('Database host', 'localhost', $emptyValidation);
        $dbPort = $io->ask('Database port', '3306', $emptyValidation);
        $dbName = $io->ask('Database name', 'shopware', $emptyValidation);
        $dbSslCa = $io->ask('Database SSL CA Path', '');
        $dbSslCert = $io->ask('Database SSL Cert Path', '');
        $dbSslKey = $io->ask('Database SSL Key Path', '');
        $dbSslDontVerify = $io->askQuestion(new ConfirmationQuestion('Skip verification of the database server\'s SSL certificate?', false));

        $dsnWithoutDb = sprintf(
            'mysql://%s:%s@%s:%d',
            (string) $dbUser,
            rawurlencode((string) $dbPass),
            (string) $dbHost,
            (int) $dbPort
        );
        $dsn = $dsnWithoutDb . '/' . $dbName;

        $params = ['url' => $dsnWithoutDb, 'charset' => 'utf8mb4'];

        
if ($mediaService->getAdapterType() !== 'local' && !$input->getOption('force')) {
            $output->writeln(
                "<error>Using the sw:media:optimize-command with remote filesystem adapters (you are using adapter '{$mediaService->getAdapterType()}') is discouraged!</error> Due to the nature of the task, all files will be downloaded, optimized and uploaded again. This can take a very long time, depending on the number of files that need to be optimized. "
            );

            $doProceed = $this->getHelper('question')->ask(
                $input,
                $output,
                new ConfirmationQuestion('Do you still wish to proceed? (y/N) ', false)
            );

            if (!$doProceed) {
                return 1;
            }
        }

        $path = 'media';
        if ($input->getArgument('path')) {
            if (strpos($input->getArgument('path'), 'media') !== 0) {
                $output->writeln('<error>Only subpaths of "media"-directory supported.</error>');

                


    /** * @return bool */
    protected function shouldSkipImport()
    {
        if (!$this->IOHelper->isInteractive()) {
            return true;
        }

        $question = new ConfirmationQuestion(
            'The database already contains shopware tables. Skip import? (yes/no) [yes]',
            true
        );
        $skipImport = $this->IOHelper->ask($question);

        return (bool) $skipImport;
    }

    /** * @return DatabaseConnectionInformation */
    
Home | Imprint | This part of the site doesn't use cookies.