/** * @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); }
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)); }
/** * 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; }
/** * 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'); }
/** * @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); }
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>'); } } }; }
/** * {@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); }
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.'); } } }
/** * Creates configuration file of application. * * @param InputInterface $input * @param OutputInterface $output */ protected function createConfiguration(InputInterface $input, OutputInterface $output) { $path = $this->getApplication()->getRoot() . '/.jedi.php'; $output->writeln(' - Configuration'); if (file_exists($path)) { $question = new ConfirmationQuestion(' <error>Configuration file ' . $path . ' already exists</error>' . PHP_EOL . ' <info>Overwrite? [Y/n]</info> ', true, '/^(y|j)/i'); if (!$this->questionHelper->ask($input, $output, $question)) { return; } } $fs = new Filesystem(); $question = new Question(' <info>Enter path to web directory relative to ' . $this->getApplication()->getRoot() . ':</info> ' . PHP_EOL . ' (or do not specify if you are already in the web directory)' . PHP_EOL); $question->setValidator(function ($answer) use($fs) { $path = $answer; if ($answer === null) { $path = $this->getApplication()->getRoot(); } elseif (!$fs->isAbsolutePath($answer)) { $path = $this->getApplication()->getRoot() . '/' . $answer; } if (!is_dir($path)) { throw new \RuntimeException('Directory "' . $path . '" is missing'); } return $answer; }); $webDir = $this->questionHelper->ask($input, $output, $question); $content = file_get_contents($this->tmplDir . '/.jedi.php'); $content = str_replace(['%web-dir%', '%env-dir%'], [addslashes($webDir), addslashes($this->envDir)], $content); $fs->dumpFile($path, $content); $output->writeln(' Created configuration file of application <comment>' . $path . '</comment>'); }
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>'); } }
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; }
/** * {@inheritdoc} */ public function ask(InputInterface $input, OutputInterface $output, Question $question) { if (null !== $this->attempts && null === $question->getMaxAttempts()) { $question->setMaxAttempts($this->attempts); } return QuestionHelper::ask($input, $output, $question); }
/** * 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(); } }
/** * @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; }
/** * 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); }
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'); } }
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())); }
/** * 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; }
/** * Construct a default slicer file. * * @return string */ public function buildFile() { $data = []; /** @var Question $question */ foreach ($this->getQuestions() as $key => $question) { /** @var QuestionHelper $helper */ $result = $this->helper->ask($this->input, $this->output, $question); $data[$key] = $result; } $data = $this->constructFileStructure($data); $file = print_r(json_encode($data, JSON_PRETTY_PRINT), TRUE); echo $file . PHP_EOL . PHP_EOL; $confirm = new ConfirmationQuestion(PHP_EOL . '<question>How does this look? Continue creating the file?</question> [<comment>yes</comment>] ', TRUE); if (TRUE === $this->helper->ask($this->input, $this->output, $confirm)) { return $file; } return ''; }
/** * @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); } }
/** * 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: '******'Use master key to decrypt all files'); $user = $this->keyManager->getMasterKeyId(); $password = $this->keyManager->getMasterKeyPassword(); } else { $recoveryKeyId = $this->keyManager->getRecoveryKeyId(); if (!empty($user)) { $output->writeln('You can only decrypt the users files if you know'); $output->writeln('the users password or if he activated the recovery key.'); $output->writeln(''); $questionUseLoginPassword = new ConfirmationQuestion('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 user\'s login password: '******'No recovery key available for user ' . $user); return false; } else { $user = $recoveryKeyId; } } } else { $output->writeln('You can only decrypt the files of all users if the'); $output->writeln('recovery key is enabled by the admin and activated by the users.'); $output->writeln(''); $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; }
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); }
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); }
/** * @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)); } } }
/** * Ask a question and validate the result * * @param string|Question $question * @param bool|callable $validator * @param bool|int $attempts * @param null|string $default * * @return string */ public function askAndValidate($question, $validator = false, $attempts = false, $default = null) { $question = $question instanceof Question ? $question : new Question($question, $default); if ($attempts) { $question->setMaxAttempts($attempts); } if ($validator) { $question->setValidator($validator); } return $this->questionHelper->ask($this->input, $this->output, $question); }
/** * Retrieves at least one answer to at least one question * * @return boolean Return true, if at least one answer was retrieved, false * otherwise */ public function retrieveAnswers() { $this->currentField->refreshDisplay(); $answer = $this->questionHelper->ask($this->input, $this->output, $this->currentField->getDisplay()->getSymfonyQuestion()); if ($this->currentField instanceof \Feeld\Field\CommonProperties\IdentifierInterface && $this->currentField->hasId()) { foreach ($this->getCurrentCollection()->getValueMapper() as $vm) { $vm->set($this->currentField->getId(), $answer); } } return true; }
private function chooseIncludeExamples() { $default = 'i'; $choices = ['i' => 'Include examples', 'e' => 'Export to a separate file', 's' => 'Skip examples']; $question = new ChoiceQuestion("Do you want to include code examples (default: {$default})?", $choices, $default); $question->setMultiselect(false); $question->setAutocompleterValues(null); $question->setValidator(function ($val) { return $val; }); return $this->helper->ask($this->input, $this->output, $question); }
protected function execute(InputInterface $input, OutputInterface $output) { $oldRoot = $this->util->getKeyStorageRoot(); $newRoot = $input->getArgument('newRoot'); if ($newRoot === null) { $question = new ConfirmationQuestion('No storage root given, do you want to reset the key storage root to the default location? (y/n) ', false); if (!$this->questionHelper->ask($input, $output, $question)) { return; } $newRoot = ''; } $oldRootDescription = $oldRoot !== '' ? $oldRoot : 'default storage location'; $newRootDescription = $newRoot !== '' ? $newRoot : 'default storage location'; $output->writeln("Change key storage root from <info>{$oldRootDescription}</info> to <info>{$newRootDescription}</info>"); $success = $this->moveAllKeys($oldRoot, $newRoot, $output); if ($success) { $this->util->setKeyStorageRoot($newRoot); $output->writeln(''); $output->writeln("Key storage root successfully changed to <info>{$newRootDescription}</info>"); } }
/** * Configure and dispatch question. * * @param Question $question * @return mixed */ private function dispatch(Question $question) { $question->setMaxAttempts($this->maxAttempts); if ($this->hidden) { $question->setHidden($this->hidden)->setHiddenFallback($this->hiddenFallback); } //Reset options $this->maxAttempts = self::MAX_ATTEMPTS; $this->hidden = false; $this->hiddenFallback = true; return $this->helper->ask($this->input, $this->output, $question); }
protected function execute(InputInterface $input, OutputInterface $output) { try { if ($this->encryptionManager->isEnabled() === true) { $output->write('Disable server side encryption... '); $this->config->setAppValue('core', 'encryption_enabled', 'no'); $output->writeln('done.'); } else { $output->writeln('Server side encryption not enabled. Nothing to do.'); return; } $uid = $input->getArgument('user'); if ($uid === '') { $message = 'your ownCloud'; } else { $message = "{$uid}'s account"; } $output->writeln("\n"); $output->writeln("You are about to start to decrypt all files stored in {$message}."); $output->writeln('It will depend on the encryption module and your setup if this is possible.'); $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(); $user = $input->getArgument('user'); $result = $this->decryptAll->decryptAll($input, $output, $user); if ($result === false) { $output->writeln(' aborted.'); $output->writeln('Server side encryption remains enabled'); $this->config->setAppValue('core', 'encryption_enabled', 'yes'); } else { if ($uid !== '') { $output->writeln('Server side encryption remains enabled'); $this->config->setAppValue('core', 'encryption_enabled', 'yes'); } } $this->resetSingleUserAndTrashbin(); } else { $output->write('Enable server side encryption... '); $this->config->setAppValue('core', 'encryption_enabled', 'yes'); $output->writeln('done.'); $output->writeln('aborted'); } } catch (\Exception $e) { // enable server side encryption again if something went wrong $this->config->setAppValue('core', 'encryption_enabled', 'yes'); $this->resetSingleUserAndTrashbin(); throw $e; } }