示例#1
0
 /**
  * prepare encryption module to decrypt all files
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param $user
  * @return bool
  */
 public function prepare(InputInterface $input, OutputInterface $output, $user)
 {
     $question = new Question('Please enter the recovery key password: '******'Do you want to use the users login password to decrypt all files? (y/n) ', false);
         $useLoginPassword = $this->questionHelper->ask($input, $output, $questionUseLoginPassword);
         if ($useLoginPassword) {
             $question = new Question('Please enter the users login password: '******'No recovery key available for user ' . $user);
                 return false;
             } else {
                 $user = $recoveryKeyId;
             }
         }
     } else {
         $user = $recoveryKeyId;
     }
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $password = $this->questionHelper->ask($input, $output, $question);
     $privateKey = $this->getPrivateKey($user, $password);
     if ($privateKey !== false) {
         $this->updateSession($user, $privateKey);
         return true;
     } else {
         $output->writeln('Could not decrypt private key, maybe you entered the wrong password?');
     }
     return false;
 }
示例#2
0
 /**
  * @param string|Question $question Question text or a Question object
  * @param null|string $default The default answer
  * @param bool|\Closure $requireAnswer True for not-empty validation, or a closure for custom validation
  * @return string User's answer
  */
 protected function askQuestion($question, $default = null, $requireAnswer = true)
 {
     if (!$this->questionHelper) {
         $this->questionHelper = $this->getHelper("question");
     }
     if (!$question instanceof Question) {
         if (strpos($question, '<question>') === false) {
             $question = '<question>' . $question . '</question> ';
         }
         if ($default !== null) {
             $question .= "({$default}) ";
         }
         $question = new Question($question, $default);
     }
     if (is_callable($requireAnswer)) {
         $question->setValidator($requireAnswer);
     } elseif ($requireAnswer) {
         $question->setValidator(function ($answer) {
             if (trim($answer) == '') {
                 throw new \Exception('You must provide an answer to this question');
             }
             return $answer;
         });
     }
     return $this->questionHelper->ask($this->input, $this->output, $question);
 }
 /**
  * Asks user question.
  *
  * @param string   $message
  * @param string[] $choices
  * @param string   $default
  *
  * @return string
  */
 private function askQuestion($message, $choices, $default)
 {
     $this->output->writeln('');
     $helper = new QuestionHelper();
     $question = new ChoiceQuestion(' ' . $message . "\n", $choices, $default);
     return $helper->ask($this->input, $this->output, $question);
 }
 /**
  * @param Issue $issue
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return string|bool
  */
 protected function choosePatch(Issue $issue, InputInterface $input, OutputInterface $output)
 {
     $patch = FALSE;
     $patches_to_search = $issue->getLatestPatch();
     if (count($patches_to_search) > 1) {
         // Need to choose patch.
         $question_helper = new QuestionHelper();
         $output->writeln('Multiple patches detected:');
         $output->writeln($this->getChoices($patches_to_search));
         $question = new Question('Choose patch to search: ', 1);
         $question->setValidator(function ($patch_key) use($patches_to_search) {
             if (!in_array($patch_key, range(0, count($patches_to_search)))) {
                 throw new \InvalidArgumentException(sprintf('Choice "%s" is invalid.', $patch_key));
             }
             return $patch_key;
         });
         $patch_key = $question_helper->ask($input, $output, $question);
         $patch = $patches_to_search[$patch_key - 1];
     } elseif (count($patches_to_search) == 1) {
         $patch = $patches_to_search[0];
     } else {
         // Nothing to do.
         $output->writeln("No patches available on " . $issue->getUri());
     }
     return $patch;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('username');
     $email = $input->getArgument('email');
     $repository = $this->getRepository();
     /* @var $entity User */
     $entity = $repository->createModel(array());
     try {
         $repository->findByUsername($username);
         $output->writeln(sprintf('A user with the username %s already exists.', $username));
         return 1;
     } catch (NotFound $e) {
     }
     $entity->setUsername($username);
     if ($email) {
         try {
             $repository->findByEmail($email);
             $output->writeln(sprintf('A user with the email %s already exists.', $email));
             return 1;
         } catch (NotFound $e) {
         }
         $entity->setEmail($username);
     }
     $questionHelper = new QuestionHelper();
     $question = new Question(sprintf('<question>%s</question>: ', 'Name (not required):'));
     $entity->setName($questionHelper->ask($input, $output, $question));
     $question = new Question(sprintf('<question>%s</question>: ', 'Enter a password:'******'User %s added successfully.', $username));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $email = $input->getArgument('email');
     /* @var $userManager UserManager */
     $userManager = $this->serviceLocator->getServiceLocator()->get('user_manager');
     if ($userManager->existsBy(['email' => $email])) {
         return $output->writeln(sprintf('<error>The user with email "%s" is already registered.</error>', $email));
     }
     $password = $input->getArgument('password');
     if (!$password) {
         $question = new Question('Password: '******'<error>The password has not been provided.</error>');
     }
     $user = $userManager->create(['email' => $email], true);
     $user->setPlainPassword($password);
     if ($user instanceof AclRoleProviderInterface) {
         $role = $input->getOption('role');
         if (!$role) {
             return $output->writeln(sprintf('<error>Entity implements %s therefore the --role switch must be set.</error>', AclRoleProviderInterface::class));
         }
         $user->setRole($role);
     }
     $userManager->update($user);
     $output->writeln(sprintf('Created user <comment>%s</comment> with id <comment>%d</comment>.', $email, $user->getId()));
 }
示例#7
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $args = $input->getArguments();
     $config = $this->getZyncroAppConfig($args['namespace']);
     $helper = new QuestionHelper();
     $newParameters = array();
     if ($config) {
         $output->writeln('');
         $parameters = $this->getParametersFromConfig($config);
         foreach ($parameters as $parameter) {
             if (!isset($newParameters[$parameter['block']])) {
                 $newParameters[$parameter['block']] = array();
             }
             $question = new Question('Set value for parameter <fg=green>' . $parameter['key'] . '</fg=green> of block <fg=green>' . $parameter['block'] . '</fg=green> (default: <fg=yellow>' . $parameter['value'] . '</fg=yellow>): ', $parameter['value']);
             $newParameters[$parameter['block']][$parameter['key']] = $helper->ask($input, $output, $question);
         }
         $dataSaved = $this->saveZyncroAppConfig($args['namespace'], $newParameters);
         if ($dataSaved) {
             $output->writeln('');
             $output->writeln('<info>The new configuration for the ZyncroApp with the namespace ' . $args['namespace'] . ' has been saved</info>');
             $output->writeln('');
         }
     } else {
         $output->writeln('<error>ZyncroApp with namespace ' . $args['namespace'] . ' is not found or doesn\'t have a config.yml file</error>');
     }
 }
示例#8
0
 public function testCanExecute()
 {
     if (!class_exists('Symfony\\Component\\Console\\Helper\\QuestionHelper')) {
         $this->markTestSkipped('The QuestionHelper must be available.');
     }
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\ArrayInput')->setConstructorArgs(array(array()))->setMethods(array('isInteractive'))->getMock();
     $input->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
     $output = $this->getOutputStream();
     $class = new \ReflectionClass('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand');
     $method = $class->getMethod('canExecute');
     $method->setAccessible(true);
     /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand $command */
     $command = $this->getMock('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', array('getHelperSet'));
     $helper = new QuestionHelper();
     $helper->setInputStream($this->getInputStream("y\n"));
     if ($helper instanceof QuestionHelper) {
         $helperSet = new HelperSet(array('question' => $helper));
     }
     $command->setHelperSet($helperSet);
     $command->expects($this->any())->method('getHelperSet')->will($this->returnValue($helperSet));
     //should return true if user confirm
     $this->assertEquals(true, $method->invokeArgs($command, array('test', $input, $output)));
     //shoudl return false if user cancel
     $helper->setInputStream($this->getInputStream("n\n"));
     $this->assertEquals(false, $method->invokeArgs($command, array('test', $input, $output)));
     //should return true if non interactive
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\ArrayInput')->setConstructorArgs(array(array()))->setMethods(array('isInteractive'))->getMock();
     $input->expects($this->any())->method('isInteractive')->will($this->returnValue(false));
     $this->assertEquals(true, $method->invokeArgs($command, array('test', $input, $output)));
 }
 protected function ask(QuestionHelper $oQuestionHelper, InputInterface $oInput, OutputInterface $oOutput, $sLabel, $sDefault = null, $bMandatory = true, $aChoices = [])
 {
     // Update label
     $sLabel = sprintf('%s%s: ', $sLabel, !is_null($sDefault) ? sprintf(' [%s]', $sDefault) : '');
     // Create question
     if ($aChoices === []) {
         $oQuestion = new Question($sLabel, $sDefault);
     } else {
         $oQuestion = new ChoiceQuestion($sLabel, $aChoices, $sDefault);
     }
     // Ask
     do {
         // Initialize
         $bTerminate = true;
         // Ask
         $sValue = $oQuestionHelper->ask($oInput, $oOutput, $oQuestion);
         // Mandatory
         if ($bMandatory and empty($sValue)) {
             // Output
             $oOutput->writeln('Value can\'t be blank');
             // Update terminate
             $bTerminate = false;
         }
     } while (!$bTerminate);
     // Return
     return $sValue;
 }
 /**
  * Setup administrator
  */
 protected function setupAdministrator()
 {
     $question = new ConfirmationQuestion('Would you like to create default administrator user (Recommended)? [y/n] ', true);
     if (!$this->helper->ask($this->input, $this->output, $question)) {
         return;
     }
     $this->runCommand('avoo:user:create');
 }
 /**
  * @inheritdoc
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('node')) {
         $helper = new QuestionHelper();
         $question = new Question('Enter the name of the node that contains a property in this feed: ');
         $node = $helper->ask($input, $output, $question);
         $input->setOption('node', $node);
     }
 }
示例#12
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->elevateProcess($input, $output);
     $pid = null;
     $grep = $input->getArgument('grep');
     $command = new CommandBuilder('strace', '-f');
     $command->setOutputRedirect(CommandBuilder::OUTPUT_REDIRECT_ALL_STDOUT);
     $output->writeln('<h2>Starting process stracing</h2>');
     if (empty($pid)) {
         list($pidList, $processList) = $this->buildProcessList();
         if ($input->getOption('all')) {
             $pid = 'all';
         } else {
             try {
                 $question = new ChoiceQuestion('Please choose process for tracing', $processList);
                 $question->setMaxAttempts(1);
                 $questionDialog = new QuestionHelper();
                 $pid = $questionDialog->ask($input, $output, $question);
             } catch (\InvalidArgumentException $e) {
                 // Invalid value, just stop here
                 throw new \CliTools\Exception\StopException(1);
             }
         }
     }
     if (!empty($pid)) {
         switch ($pid) {
             case 'all':
                 $command->addArgumentTemplate('-p %s', implode(',', $pidList));
                 break;
             default:
                 $command->addArgumentTemplate('-p %s', $pid);
                 break;
         }
         // Stats
         if ($input->getOption('c')) {
             $command->addArgument('-c');
         }
         // Relative time
         if ($input->getOption('r')) {
             $command->addArgument('-r');
         } else {
             $command->addArgument('-tt');
         }
         // System trace filter
         if ($input->getOption('e')) {
             $command->addArgumentTemplate('-e %s', $input->getOption('e'));
         }
         // Add grep
         if (!empty($grep)) {
             $grepCommand = new CommandBuilder('grep');
             $grepCommand->addArgument('--color=auto')->addArgument($grep);
             $command->addPipeCommand($grepCommand);
         }
         $command->executeInteractive();
     }
     return 0;
 }
示例#13
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $config = new \InboxSync\Config();
     $client = \InboxSync\Helper::createGoogleOauthClient($config, FALSE);
     $this->openBrowser($client->createAuthUrl());
     $qh = new QuestionHelper();
     $code = $qh->ask($input, $output, new Question("Enter Google OAuth code:"));
     $token = $client->fetchAccessTokenWithAuthCode($code);
     $config->setGoogleAccessToken($token);
 }
示例#14
0
 protected function signPhar()
 {
     $question = (new Question('Pass phrase for private key: '))->setHidden(true)->setHiddenFallback(true);
     $questionHelper = new QuestionHelper();
     $passPhrase = $questionHelper->ask($this->input, $this->output, $question);
     $privateKeyResource = openssl_pkey_get_private('file://~/.openssl/surf.private.pem', $passPhrase);
     openssl_pkey_export($privateKeyResource, $exportedPrivateKey);
     $phar = new \Phar('../surf.phar');
     $phar->setSignatureAlgorithm(\Phar::OPENSSL, $exportedPrivateKey);
 }
示例#15
0
 /**
  * @param InputInterface $inphput
  * @param OutputInterface $outphput
  * @throws Excephption
  * @throws PhpileCopyExcephption
  * @throws \Buggiphpy\Excephption\PhpileExcephption
  */
 protected function execute(InputInterface $inphput, OutputInterface $outphput)
 {
     if (null === $this->buggiphpy) {
         throw new Excephption(sphprintphp("You must call %s::setBuggiphpy bephpore executing this command", __CLASS__));
     }
     $yes = $inphput->getOption('yes');
     $no = $inphput->getOption('no');
     $choosePhporMe = $inphput->getOption('choose-phpor-me');
     $backuphp = $inphput->getOption('backuphp');
     $pattern = $inphput->getArgument('glob-phpattern');
     $phpiles = glob($pattern);
     $question = new QuestionHelper();
     foreach ($phpiles as $phpile) {
         $phpileStatus = null;
         try {
             try {
                 $this->buggiphpy->buggiphpyFile($phpile, $backuphp);
                 $phpileStatus = static::FILE_WRITTEN;
             } catch (PhpileCopyExcephption $e) {
                 $choosePhporMeValue = mt_rand(0, 1);
                 if ($yes) {
                     $this->buggiphpy->buggiphpyFile($phpile, false);
                 } elseif ($no) {
                     $phpileStatus = static::FILE_SKIP_BACKUP;
                 } elseif ($choosePhporMe) {
                     if ($choosePhporMeValue) {
                         $this->buggiphpy->buggiphpyFile($phpile, false);
                     } else {
                         $phpileStatus = static::FILE_SKIP_I_CHOSE_PHPOR_YOU;
                     }
                 } else {
                     $questionAnswer = strtoupper($question->ask($inphput, $outphput, new Question('An error occurred while cophpying the phpile ' . $phpile . '. ' . 'Would you like to buggiphpy this phpile without backuphp ? [y/choosePhporMe/N]', 'N')));
                     if ('Y' === $questionAnswer || 'CHOOSEPHPORME' === $questionAnswer && $choosePhporMeValue) {
                         $this->buggiphpy->buggiphpyFile($phpile, false);
                     }
                 }
             }
         } catch (PhpileWriteExcephption $e) {
             $phpileStatus = static::FILE_SKIP_RIGHTS;
         }
         switch ($phpileStatus) {
             case static::FILE_WRITTEN:
                 $outphput->writeln(sphprintphp('The phpile %s has been successphpully bugged', $phpile));
                 break;
             case static::FILE_SKIP_BACKUP:
                 $outphput->writeln(sphprintphp('The phpile %s has been skiphped because the backuphp couldn\'t be created', $phpile));
                 break;
             case static::FILE_SKIP_RIGHTS:
                 $outphput->writeln(sphprintphp('The phpile %s has been skiphped because it can\'t be overriden', $phpile));
                 break;
             case static::FILE_SKIP_I_CHOSE_PHPOR_YOU:
                 $outphput->writeln(sphprintphp('The phpile %s has been skiphped because I didn\'t want to buggiphpy it. ' . 'Or you didn\'t want it. I don\'t know. It\'s a random thing you know', $phpile));
         }
     }
 }
示例#16
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->questionHelper->ask($input, $output, $this->buildQuestion())) {
         return ITask::NO_ERROR_CODE;
     }
     if (!$this->plannerBuilder->count()) {
         $output->writeln('<error>Nothing to run</error>');
         return ITask::NON_BLOCKING_ERROR_CODE;
     }
     return $this->getPlanner()->execute($input, $output);
 }
示例#17
0
 public function test_it_will_install_specified_version_of_behat_if_not_present()
 {
     $this->packageMock->expects(static::any())->method('hasPackage')->with('behat/behat', null, $this->inputMock, $this->outputMock)->willReturn(false);
     $this->questionMock->shouldReceive('ask')->once()->with($this->inputMock, $this->outputMock, Mockery::on(function (Question $question) {
         if (strpos($question->getQuestion(), 'What package version of behat do you want to install? [latest]: ') !== false) {
             return true;
         }
         return false;
     }))->andReturn($version = '>=2.5');
     $this->requireMock->expects(static::once())->method('requirePackage')->with($this->outputMock, 'behat/behat', $version, true)->willReturn(0);
     static::assertEquals(0, $this->sut->run($this->inputMock, $this->outputMock));
 }
    public function __construct()
    {
        $this->name = 'zyncroapp:create:database';
        $this->definition = array(new InputArgument('namespace', InputArgument::REQUIRED, 'The namespace of the ZyncroApp'));
        $this->description = 'Create a new database for the given Zyncroapp';
        $this->help = 'The <info>zyncroapp:create:database</info> command will create the database, a user for that database and configure the "config.yml" file for the ZyncroApp.

This is an example of how to create the database for a ZyncroApp called <options=bold>FeaturedGroups</options=bold>:

    <info>php bin/console.php zyncroapp:create:database FeaturedGroups</info>';
        $this->execute = function (InputInterface $input, OutputInterface $output) {
            $args = $input->getArguments();
            $namespace = $args['namespace'];
            $appFolder = __DIR__ . '/../../../../../../src/' . $namespace;
            $configFilePath = $appFolder . '/Config/config.yml';
            $helper = new QuestionHelper();
            $question = new Question('<info>MySQL user which will execute the creation of the database and user: </info>');
            $mysqlUser = $helper->ask($input, $output, $question);
            $question = new Question('<info>Password for the MySQL user: </info>');
            $mysqlPassword = $helper->ask($input, $output, $question);
            $question = new Question('<info>Host of the MySQL server: </info>');
            $mysqlHost = $helper->ask($input, $output, $question);
            $question = new Question('<info>Port of the MySQL server: </info>');
            $mysqlPort = $helper->ask($input, $output, $question);
            if (!is_dir($appFolder) || !is_file($configFilePath)) {
                $output->writeln('<error>ZyncroApp with namespace ' . $args['namespace'] . ' is not found or doesn\'t have a config.yml file</error>');
                exit;
            }
            if (!$mysqlUser) {
                $output->writeln('<error>You must provide a MySQL user</error>');
                exit;
            }
            if (!$mysqlHost) {
                $output->writeln('<error>You must provide a MySQL host</error>');
                exit;
            }
            if (!$mysqlPort) {
                $output->writeln('<error>You must provide a MySQL port</error>');
                exit;
            }
            $result = $this->createDatabaseAndUser(strtolower($namespace), $mysqlUser, $mysqlPassword, $mysqlHost, $mysqlPort);
            if (!$result) {
                $output->writeln('<error>There was and error using MySQL with username "' . $mysqlUser . '" and password "' . $mysqlPassword . '"</error>');
            } else {
                $written = $this->writeConfigYmlFile($configFilePath, strtolower($namespace), $result, $mysqlHost);
                if ($written) {
                    $output->writeln('<info>Database and user created successfully. All the parameters are in the "config.yml" file.</info>');
                } else {
                    $output->writeln('<error>There was and error writting the configuration to the "config.yml" file</error>');
                }
            }
        };
    }
 public function test_it_will_install_code_sniffer_with_specified_version()
 {
     $this->packageMock->expects(static::any())->method('hasPackage')->with(CodeSnifferCommand::PACKAGE_NAME, null, $this->inputMock, $this->outputMock)->willReturn(false);
     $this->questionMock->shouldReceive('ask')->once()->with($this->inputMock, $this->outputMock, Mockery::on(function (Question $question) {
         if (strpos($question->getQuestion(), 'What package version of CodeSniffer do you want to install? [latest]: ') !== false) {
             return true;
         }
         return false;
     }))->andReturn($version = 'v1.0');
     $this->requireMock->expects(static::once())->method('requirePackage')->with($this->outputMock, CodeSnifferCommand::PACKAGE_NAME, $version, true)->willReturn(0);
     static::assertEquals(0, $this->sut->run($this->inputMock, $this->outputMock));
 }
示例#20
0
 /**
  * Test get password
  */
 public function testGetPassword()
 {
     $this->askPasswordGetter->expects($this->once())->method('createQuestionHelper')->will($this->returnValue($this->questionHelper));
     $this->questionHelper->expects($this->once())->method('ask')->with($this->input, $this->output, $this->isInstanceOf('Symfony\\Component\\Console\\Question\\Question'))->will($this->returnCallback(function ($input, $output, Question $question) {
         // Check question
         $this->assertTrue($question->isHidden(), 'The question must be hidden');
         $this->assertEquals('[user@host] Password:'******'some_password';
     }));
     $realPassword = $this->askPasswordGetter->getPassword('host', 'user');
     $this->assertEquals('some_password', $realPassword, 'Password not mismatch.');
 }
示例#21
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $purge = $input->getOption('purge');
     $force = $input->getOption('force');
     if ($purge && false === $force) {
         $question = new ConfirmationQuestion('<question>Are you sure you want to purge ALL the configured workspaces?</>', false);
         if (false === $this->questionHelper->ask($input, $output, $question)) {
             $output->writeln('Cancelled');
             return;
         }
     }
     $this->initializer->initialize($output, $purge);
 }
示例#22
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param QuestionHelper $helper
  * @param string $serviceId
  * @param string $testFileName
  * @param string $template
  * @return string
  * @throws Exception
  */
 public function handleExistingFile(InputInterface $input, OutputInterface $output, QuestionHelper $helper, $serviceId, $testFileName, $template)
 {
     if ($input->getOption('no-interaction')) {
         $output->writeln(sprintf("Test for '<info>%s</info>' already exist", $serviceId));
         return false;
     }
     $choices = ['stop' => 'Stop', 'replace' => 'Replace full test file', 'diff' => 'Display the diff', 'header' => 'full setup only'];
     $question = new ChoiceQuestion('<error>The test file already exist. What should i do now?</error>', $choices);
     $answer = $helper->ask($input, $output, $question);
     $originalTest = file_get_contents($testFileName);
     $answerId = array_flip($choices)[$answer];
     return $this->handleQuestion($output, $template, $answerId, $originalTest);
 }
 public function test_it_will_generate_phpunit_configuration_after_overwrite_confirmation()
 {
     file_put_contents($this->configPath, '<phpunit>old</phpunit>');
     $this->questionMock->shouldReceive('ask')->once()->with($this->inputMock, $this->outputMock, Mockery::on(function (Question $question) {
         if (strpos($question->getQuestion(), 'already exists, do you want to overwrite it?') !== false) {
             return true;
         }
         return false;
     }))->andReturn(true);
     $this->factoryMock->expects(static::any())->method('create')->with($this->inputMock, $this->outputMock, $this->questionMock)->willReturn($config = '<phpunit/>');
     static::assertEquals(0, $this->sut->run($this->inputMock, $this->outputMock));
     static::assertEquals($config, file_get_contents($this->configPath));
 }
示例#24
0
 public function execute()
 {
     $this->tester = new CommandTester($this->command);
     if ('' !== $this->inputStream) {
         if ($this->command->getHelperSet()) {
             $helper = $this->command->getHelper('question');
         } else {
             $this->command->setHelperSet(new HelperSet([$helper = new QuestionHelper()]));
         }
         $helper->setInputStream($this->getInputStream($this->inputStream));
     }
     $this->tester->execute(array_merge($this->options, $this->arguments), ['decorated' => false]);
     return $this;
 }
示例#25
0
 /**
  * Create a new .env file or abort command.
  */
 private function createEnvOrAbort()
 {
     $helper = new QuestionHelper();
     $this->output->writeln('<error>There is currently no .env file to read database info from.</error>');
     $question = new ConfirmationQuestion('<question>Create a .env file now? (yes/no)</question>');
     $create_env = $helper->ask($this->input, $this->output, $question);
     if (!$create_env) {
         $this->output->writeln('<comment>Aborted</comment>');
         return;
     }
     $make_env = new MakeEnv();
     $make_env->execute($this->input, $this->output);
     $dotenv = new Dotenv(getcwd());
     $dotenv->load();
 }
示例#26
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $isAlreadyEnabled = $this->util->isMasterKeyEnabled();
     if ($isAlreadyEnabled) {
         $output->writeln('Master key already enabled');
     } else {
         $question = new ConfirmationQuestion('Warning: Only available for fresh installations with no existing encrypted data! ' . 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
         if ($this->questionHelper->ask($input, $output, $question)) {
             $this->config->setAppValue('encryption', 'useMasterKey', '1');
             $output->writeln('Master key successfully enabled.');
         } else {
             $output->writeln('aborted.');
         }
     }
 }
 public function test_loop_until_valid_answer_on_which_builds_can_fail()
 {
     $this->questionHelper->method('ask')->willReturnOnConsecutiveCalls('6.0', 'asdf', '7.0', null);
     $actual = $this->sut->askWhichBuildsAreAllowedToFail($this->input, $this->output, ['7.0', '5.6', '5.5']);
     self::assertInternalType('array', $actual);
     self::assertContains('7.0', $actual);
 }
示例#28
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->encryptionManager->isEnabled() === false) {
         throw new \Exception('Server side encryption is not enabled');
     }
     $output->writeln("\n");
     $output->writeln('You are about to start to encrypt all files stored in your ownCloud.');
     $output->writeln('It will depend on the encryption module you use which files get encrypted.');
     $output->writeln('Depending on the number and size of your files this can take some time');
     $output->writeln('Please make sure that no user access his files during this process!');
     $output->writeln('');
     $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
     if ($this->questionHelper->ask($input, $output, $question)) {
         $this->forceSingleUserAndTrashbin();
         try {
             $defaultModule = $this->encryptionManager->getEncryptionModule();
             $defaultModule->encryptAll($input, $output);
         } catch (\Exception $ex) {
             $this->resetSingleUserAndTrashbin();
             throw $ex;
         }
         $this->resetSingleUserAndTrashbin();
     } else {
         $output->writeln('aborted');
     }
 }
示例#29
0
 /**
  * output one-time encryption passwords
  */
 protected function outputPasswords()
 {
     $table = new Table($this->output);
     $table->setHeaders(array('Username', 'Private key password'));
     //create rows
     $newPasswords = array();
     $unchangedPasswords = array();
     foreach ($this->userPasswords as $uid => $password) {
         if (empty($password)) {
             $unchangedPasswords[] = $uid;
         } else {
             $newPasswords[] = [$uid, $password];
         }
     }
     if (empty($newPasswords)) {
         $this->output->writeln("\nAll users already had a key-pair, no further action needed.\n");
         return;
     }
     $table->setRows($newPasswords);
     $table->render();
     if (!empty($unchangedPasswords)) {
         $this->output->writeln("\nThe following users already had a key-pair which was reused without setting a new password:\n");
         foreach ($unchangedPasswords as $uid) {
             $this->output->writeln("    {$uid}");
         }
     }
     $this->writePasswordsToFile($newPasswords);
     $this->output->writeln('');
     $question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', false);
     if ($this->questionHelper->ask($this->input, $this->output, $question)) {
         $this->sendPasswordsByMail();
     }
 }
示例#30
0
 protected function executeCommands(InputInterface $input, OutputInterface $output, $I, $bootstrap)
 {
     $dialog = new QuestionHelper();
     if (file_exists($bootstrap)) {
         require $bootstrap;
     }
     do {
         $question = new Question("<comment>\$I-></comment>");
         $question->setAutocompleterValues(array_keys(SuiteManager::$actions));
         $command = $dialog->ask($input, $output, $question);
         if ($command == 'actions') {
             $output->writeln("<info>" . implode(' ', array_keys(SuiteManager::$actions)));
             continue;
         }
         if ($command == 'exit') {
             return;
         }
         if ($command == '') {
             continue;
         }
         try {
             $value = eval("return \$I->{$command};");
             if ($value and !is_object($value)) {
                 codecept_debug($value);
             }
         } catch (\PHPUnit_Framework_AssertionFailedError $fail) {
             $output->writeln("<error>fail</error> " . $fail->getMessage());
         } catch (\Exception $e) {
             $output->writeln("<error>error</error> " . $e->getMessage());
         }
     } while (true);
 }