protected function execute(InputInterface $input, OutputInterface $output)
 {
     $input->setInteractive(TRUE);
     $filter = $input->getOption('filter');
     $dialog = $this->getHelper("dialog");
     /* @var $dialog DialogHelper */
     #@note @silex commande interactive
     if (!$dialog->askConfirmation($output, "Confirm database managed entities deletion(yes|no):")) {
         return 1;
     }
     $app = $this->getHelper("app")->getApplication();
     $registry = $app['orm.manager_registry'];
     /* @var $registry AbstractManagerRegistry */
     $managers = $registry->getManagers();
     foreach ($managers as $manager) {
         /* @var $manager EntityManager */
         $metadatas = $manager->getMetadataFactory()->getAllMetadata();
         foreach ($metadatas as $metadata) {
             /* @var $metadata ClassMetadata */
             if (!$metadata->isMappedSuperclass) {
                 $class = $metadata->getName();
                 if ($filter == NULL || in_array($class, $filter)) {
                     $entities = $manager->getRepository($class)->findAll();
                     foreach ($entities as $entity) {
                         $manager->remove($entity);
                     }
                     $output->writeln($class . " datas have been removed.");
                 }
             }
         }
         $manager->flush();
     }
 }
Example #2
0
 /**
  * Enables script interactivity.
  *
  * @return self
  */
 public function enableInteractivity(InputInterface $input, QuestionHelper $helper)
 {
     $input->setInteractive(true);
     $this->interactive = true;
     $this->input = $input;
     $this->helper = $helper;
     return $this;
 }
Example #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $input->setInteractive(false);
     $command = $this->getApplication()->find('doctrine:schema:drop');
     $command->run(new ArrayInput(array('command' => 'doctrine:schema:drop', '--force' => true)), $output);
     $command = $this->getApplication()->find('doctrine:schema:create');
     $command->run($input, $output);
     $command = $this->getApplication()->find('doctrine:fixtures:load');
     $command->run($input, $output);
 }
 /**
  * {@inheritdoc}
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     // Set the input to non-interactive if the yes or no options are used.
     if ($input->hasParameterOption(array('--yes', '-y')) || $input->hasParameterOption(array('--no', '-n'))) {
         $input->setInteractive(false);
     } elseif ($input->hasParameterOption(array('--shell', '-s'))) {
         $shell = new Shell($this);
         $shell->run();
         return 0;
     }
     $this->output = $output;
     return parent::doRun($input, $output);
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $userManager = $this->getUserManager();
     $input->setInteractive(true);
     $username = $this->getOptionalInteractiveArgument($input, $output, 'username', 'Please choose a username');
     $email = $this->getOptionalInteractiveArgument($input, $output, 'email', 'Please choose an email address');
     $password = $this->getOptionalInteractiveArgument($input, $output, 'password', 'Please choose a password', true);
     $roleString = $this->getOptionalInteractiveOption($input, $output, 'roles', 'Please specify a comma-separated list of roles');
     $roles = explode(',', $roleString);
     $userManager->createUser($username, $email, $password, $roles);
     $output->writeln(sprintf('Created user <comment>%s</comment>', $username));
     return 0;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $verbose = $input->getOption('verbose');
     $force = $input->getOption('force');
     $package = $input->getArgument('package');
     $doctrine = $this->getContainer()->get('doctrine');
     $router = $this->getContainer()->get('router');
     $flags = 0;
     if ($package) {
         $packages = array(array('id' => $doctrine->getRepository('PackagistWebBundle:Package')->findOneByName($package)->getId()));
         $flags = Updater::UPDATE_TAGS;
     } elseif ($force) {
         $packages = $doctrine->getEntityManager()->getConnection()->fetchAll('SELECT id FROM package ORDER BY id ASC');
         $flags = Updater::UPDATE_TAGS;
     } else {
         $packages = $doctrine->getRepository('PackagistWebBundle:Package')->getStalePackages();
     }
     $ids = array();
     foreach ($packages as $package) {
         $ids[] = $package['id'];
     }
     if ($input->getOption('delete-before')) {
         $flags = Updater::DELETE_BEFORE;
     }
     $updater = $this->getContainer()->get('packagist.package_updater');
     $start = new \DateTime();
     $input->setInteractive(false);
     $io = $verbose ? new ConsoleIO($input, $output, $this->getApplication()->getHelperSet()) : new NullIO();
     $config = Factory::createConfig();
     $loader = new ValidatingArrayLoader(new ArrayLoader());
     while ($ids) {
         $packages = $doctrine->getRepository('PackagistWebBundle:Package')->getPackagesWithVersions(array_splice($ids, 0, 50));
         foreach ($packages as $package) {
             if ($verbose) {
                 $output->writeln('Importing ' . $package->getRepository());
             }
             try {
                 $repository = new VcsRepository(array('url' => $package->getRepository()), $io, $config);
                 $repository->setLoader($loader);
                 $updater->update($package, $repository, $flags, $start);
             } catch (\Exception $e) {
                 $output->writeln('<error>Exception: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . ', skipping package ' . $router->generate('view_package', array('name' => $package->getName()), true) . '</error>');
             }
         }
         $doctrine->getEntityManager()->clear();
         unset($packages);
     }
 }
Example #7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $from = $input->getArgument('from');
     $targetList = $input->getArgument('to');
     $input->setInteractive(!$input->getOption('force'));
     $labelSynchronizer = new LabelSynchronizer($this->github, $input, $output);
     $milestoneSynchronizer = new MilestoneSynchronizer($this->github, $input, $output);
     foreach ($targetList as $to) {
         $output->writeln(sprintf('<comment>Synchronizing labels from %s to %s</comment>', $from, $to));
         $labelSynchronizer->synchronize($from, $to);
         $output->writeln('');
         $output->writeln(sprintf('<comment>Synchronizing milestones from %s to %s</comment>', $from, $to));
         $milestoneSynchronizer->synchronize($from, $to);
         $output->writeln('');
     }
     $output->writeln('<comment>Finished</comment>');
 }
 /**
  * Configures the input and output instances based on the user arguments and options.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  */
 protected function configureIO(InputInterface $input, OutputInterface $output)
 {
     if (true === $input->hasParameterOption(array('--ansi'))) {
         $output->setDecorated(true);
     } elseif (true === $input->hasParameterOption(array('--no-ansi'))) {
         $output->setDecorated(false);
     }
     if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
         $input->setInteractive(false);
     } elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) {
         $inputStream = $this->getHelperSet()->get('dialog')->getInputStream();
         if (!@posix_isatty($inputStream)) {
             $input->setInteractive(false);
         }
     }
     if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
         $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
     } else {
         if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) {
             $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
         } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) {
             $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
         } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) {
             $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $verbose = $input->getOption('verbose');
     $force = $input->getOption('force');
     $package = $input->getArgument('package');
     $doctrine = $this->getContainer()->get('doctrine');
     $router = $this->getContainer()->get('router');
     $flags = 0;
     if ($package) {
         $packages = array(array('id' => $doctrine->getRepository('PackagistWebBundle:Package')->findOneByName($package)->getId()));
         $flags = $force ? Updater::UPDATE_EQUAL_REFS : 0;
     } elseif ($force) {
         $packages = $doctrine->getManager()->getConnection()->fetchAll('SELECT id FROM package ORDER BY id ASC');
         $flags = Updater::UPDATE_EQUAL_REFS;
     } else {
         $packages = $doctrine->getRepository('PackagistWebBundle:Package')->getStalePackages();
     }
     $ids = array();
     foreach ($packages as $package) {
         $ids[] = $package['id'];
     }
     if ($input->getOption('delete-before')) {
         $flags = Updater::DELETE_BEFORE;
     } elseif ($input->getOption('update-equal-refs')) {
         $flags = Updater::UPDATE_EQUAL_REFS;
     }
     $updater = $this->getContainer()->get('packagist.package_updater');
     $start = new \DateTime();
     if ($verbose && $input->getOption('notify-failures')) {
         throw new \LogicException('Failures can not be notified in verbose mode since the output is piped to the CLI');
     }
     $input->setInteractive(false);
     $config = Factory::createConfig();
     $io = $verbose ? new ConsoleIO($input, $output, $this->getApplication()->getHelperSet()) : new BufferIO('');
     $io->loadConfiguration($config);
     $loader = new ValidatingArrayLoader(new ArrayLoader());
     while ($ids) {
         $packages = $doctrine->getRepository('PackagistWebBundle:Package')->getPackagesWithVersions(array_splice($ids, 0, 50));
         foreach ($packages as $package) {
             if ($verbose) {
                 $output->writeln('Importing ' . $package->getRepository());
             }
             try {
                 if (null === $io || $io instanceof BufferIO) {
                     $io = new BufferIO('');
                     $io->loadConfiguration($config);
                 }
                 $repository = new VcsRepository(array('url' => $package->getRepository()), $io, $config);
                 $repository->setLoader($loader);
                 $updater->update($io, $config, $package, $repository, $flags, $start);
             } catch (InvalidRepositoryException $e) {
                 $output->writeln('<error>Broken repository in ' . $router->generate('view_package', array('name' => $package->getName()), true) . ': ' . $e->getMessage() . '</error>');
                 if ($input->getOption('notify-failures')) {
                     if (!$this->getContainer()->get('packagist.package_manager')->notifyUpdateFailure($package, $e, $io->getOutput())) {
                         $output->writeln('<error>Failed to notify maintainers</error>');
                     }
                 }
             } catch (\Exception $e) {
                 $output->writeln('<error>Error updating ' . $router->generate('view_package', array('name' => $package->getName()), true) . ' [' . get_class($e) . ']: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . '</error>');
             }
         }
         $doctrine->getManager()->clear();
         unset($packages);
     }
 }
 protected function finalStep(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Preparing application.</info>');
     $input->setInteractive(false);
     $this->runCommand('oro:search:create-index', $input, $output)->runCommand('oro:navigation:init', $input, $output)->runCommand('fos:js-routing:dump', $input, $output, array('--target' => 'web/js/routes.js'))->runCommand('oro:localization:dump', $input, $output)->runCommand('assets:install', $input, $output)->runCommand('assetic:dump', $input, $output)->runCommand('oro:assetic:dump', $input, $output)->runCommand('oro:translation:dump', $input, $output)->runCommand('oro:requirejs:build', $input, $output);
     // update installed flag in parameters.yml
     $dumper = $this->getContainer()->get('oro_installer.yaml_persister');
     $params = $dumper->parse();
     $params['system']['installed'] = date('c');
     $dumper->dump($params);
     // clear the cache set installed flag in DI container
     $this->runCommand('cache:clear', $input, $output);
     $output->writeln('');
     return $this;
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     // Work around a bug in Console which means the default command's input
     // is always considered to be interactive.
     if ($this->getName() === 'welcome' && isset($GLOBALS['argv']) && array_intersect($GLOBALS['argv'], ['-n', '--no', '-y', '---yes'])) {
         $input->setInteractive(false);
         self::$interactive = false;
         return;
     }
     $this->checkUpdates();
 }
Example #12
0
 /**
  * Configures the input and output instances based on the user arguments and options.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  */
 protected function configureIO(InputInterface $input, OutputInterface $output)
 {
     if (true === $input->hasParameterOption(array('--ansi'), true)) {
         $output->setDecorated(true);
     } elseif (true === $input->hasParameterOption(array('--no-ansi'), true)) {
         $output->setDecorated(false);
     }
     if (true === $input->hasParameterOption(array('--no-interaction', '-n'), true)) {
         $input->setInteractive(false);
     } elseif (function_exists('posix_isatty')) {
         $inputStream = null;
         if ($input instanceof StreamableInputInterface) {
             $inputStream = $input->getStream();
         }
         // This check ensures that calling QuestionHelper::setInputStream() works
         // To be removed in 4.0 (in the same time as QuestionHelper::setInputStream)
         if (!$inputStream && $this->getHelperSet()->has('question')) {
             $inputStream = $this->getHelperSet()->get('question')->getInputStream(false);
         }
         if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) {
             $input->setInteractive(false);
         }
     }
     if (true === $input->hasParameterOption(array('--quiet', '-q'), true)) {
         $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
         $input->setInteractive(false);
     } else {
         if ($input->hasParameterOption('-vvv', true) || $input->hasParameterOption('--verbose=3', true) || $input->getParameterOption('--verbose', false, true) === 3) {
             $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
         } elseif ($input->hasParameterOption('-vv', true) || $input->hasParameterOption('--verbose=2', true) || $input->getParameterOption('--verbose', false, true) === 2) {
             $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
         } elseif ($input->hasParameterOption('-v', true) || $input->hasParameterOption('--verbose=1', true) || $input->hasParameterOption('--verbose', true) || $input->getParameterOption('--verbose', false, true)) {
             $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
         }
     }
 }
Example #13
0
 /**
  * Runs the current application.
  *
  * @param InputInterface  $input  An Input instance
  * @param OutputInterface $output An Output instance
  *
  * @return int 0 if everything went fine, or an error code
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     if (50302 > PHP_VERSION_ID) {
         $output->writeln('<caution>Slicer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP ' . PHP_VERSION . ', upgrading is strongly recommended.</caution>');
     }
     if (defined('SLICER_DEV_WARNING_TIME')) {
         //$commandName = 'self-update';
     }
     if (getenv('SLICER_NO_INTERACTION')) {
         $input->setInteractive(FALSE);
     }
     // switch to working dir
     if ($newWorkingDir = $this->getNewWorkingDir($input)) {
         $oldWorkingDir = getcwd();
         chdir($newWorkingDir);
         //            if ( $this->getIO()->isDebug() >= 4 )
         //            {
         //                $this->getIO()->writeError( 'Changed CWD to ' . getcwd() );
         //            }
     }
     if ($input->hasParameterOption('--profile')) {
         $startTime = microtime(TRUE);
         //$this->io->enableDebugging( $startTime );
     }
     $result = parent::doRun($input, $output);
     if (isset($oldWorkingDir)) {
         chdir($oldWorkingDir);
     }
     if (isset($startTime)) {
         $output->writeln('<info>Memory usage: ' . round(memory_get_usage() / 1024 / 1024, 2) . 'MB (peak: ' . round(memory_get_peak_usage() / 1024 / 1024, 2) . 'MB), time: ' . round(microtime(TRUE) - $startTime, 2) . 's</info>');
     }
     return $result;
 }
Example #14
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     $items = array('progress', 'table', 'formatter', 'dialog');
     $sel = $this->getHelper('dialog')->select($output, 'Select by key number: ', $items, '0');
     $formatter = $this->getHelper('formatter');
     switch ($items[$sel]) {
         case 'progress':
             $formatted = $formatter->formatBlock('Progress', 'info', true);
             $output->writeln($formatted);
             $progress = $this->getHelper('progress');
             $progress->start($output, 25);
             $i = 0;
             while ($i++ < 25) {
                 usleep(50000);
                 $progress->advance();
             }
             $progress->finish();
             break;
         case 'table':
             $formatted = $formatter->formatBlock('Table', 'info', true);
             $output->writeln($formatted);
             $table = $this->getHelper('table');
             $table->setHeaders(array('1', '2', '3'))->setRows(array(array('a', 'a', 'a'), array('b', 'b', 'b'), array('c', 'c', 'c')))->setLayout($table::LAYOUT_DEFAULT);
             $table->render($output);
             break;
         case 'formatter':
             //$formatter = $this->getHelper('formatter');
             $formatted = $formatter->formatBlock('Formatter', 'info', true);
             $output->writeln($formatted);
             $formatted = $formatter->formatSection('Info', 'Format section info text.');
             $output->writeln($formatted);
             $output->writeln('');
             $array = array('Format block error', 'Foo bar baz qux');
             array_walk($array, function (&$v, $k) {
                 $v = '* ' . $v;
             });
             $formatted = $formatter->formatBlock($array, 'error');
             $output->writeln($formatted);
             $output->writeln('');
             $formatted = $formatter->formatBlock('Format block error with space', 'error', true);
             $output->writeln($formatted);
             $output->writeln('');
             $formatted = $formatter->formatBlock('Format block info with space', 'info', true);
             $output->writeln($formatted);
             break;
         case 'dialog':
             $dialog = $this->getHelper('dialog');
             $formatted = $formatter->formatBlock('Dialog', 'info', true);
             $output->writeln($formatted);
             $opts = array('ask', 'autocomplete', 'hidden', 'confirm', 'validator', 'shy');
             $sel = $dialog->select($output, 'Which dialog would you like to demo?', $opts, '0');
             $formatted = $formatter->formatBlock(ucfirst($opts[$sel]), 'info', true);
             $output->writeln($formatted);
             switch ($opts[$sel]) {
                 case 'ask':
                     $time = $dialog->ask($output, 'What time is it? ', '2PM');
                     $output->writeln("The time now is {$time}.");
                     break;
                 case 'autocomplete':
                     $bundles = array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle');
                     $selection = $dialog->ask($output, 'Please select a bundle: ', 'FrameworkBundle', $bundles);
                     $output->writeln("You selected {$selection}");
                     break;
                 case 'hidden':
                     $response = $dialog->askHiddenResponse($output, 'What time is it? ');
                     $output->writeln("The time now is {$response}");
                     break;
                 case 'confirm':
                     $confirm = $dialog->askConfirmation($output, 'Do you like French fries? ', true);
                     if ($confirm) {
                         $output->writeln('You like French fries.');
                     } else {
                         $output->writeln('You do not like French fries.');
                     }
                     break;
                 case 'validator':
                     $question = 'What color was the white horse of Henry IV? ';
                     $error = 'This is not a color!';
                     $validator = function ($color) use($error) {
                         if (!in_array($color, array('white', 'black'))) {
                             throw new \InvalidArgumentException($error);
                         }
                         return $color;
                     };
                     try {
                         $answer = $dialog->askAndValidate($output, $question, $validator, 3, 'white');
                         $output->writeln("You answered {$answer}");
                     } catch (\InvalidArgumentException $e) {
                         $output->writeln(sprintf('<error>fail</error> %s', 'Only 3 chances to answer correctly.'));
                         $output->writeln(sprintf('<info>message</info> %s', $e->getMessage()));
                     }
                     break;
                 case 'shy':
                     $input->setInteractive(false);
                     $dialog->setInput($input);
                     $dialog->ask($output, 'Do you have a job? ', 'not yet');
                     break;
             }
             break;
     }
 }
 /**
  * @param CommandExecutor $commandExecutor
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return InstallCommand
  */
 protected function finalStep(CommandExecutor $commandExecutor, InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Preparing application.</info>');
     $input->setInteractive(false);
     $commandExecutor->runCommand('assets:install', array('target' => './', '--symlink' => true, '--relative' => true))->runCommand('assetic:dump', array('--process-isolation' => true));
     // run installer scripts
     $this->processInstallerScripts($output, $commandExecutor);
     $this->updateInstalledFlag(date('c'));
     // clear the cache set installed flag in DI container
     $commandExecutor->runCommand('cache:clear', array('--process-isolation' => true));
     $output->writeln('');
     return $this;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     // Set the input to non-interactive if the yes or no options are used.
     if ($input->hasParameterOption(['--yes', '-y', '--no', '-n'])) {
         $input->setInteractive(false);
     }
     return parent::doRun($input, $output);
 }