/** * Execute Symfony2 command * * @param string $command Command name (for example, "cache:clear") * @param array $params [optional] Additional command parameters, like "--force" etc * @return int an executed command exit code * @throws \Exception * @throws \RuntimeException */ protected function runCommand($command, $params = array()) { $application = $this->getApplication(); $output = $this->getOutput(); $commandExecutor = new CommandExecutor($application->getKernel()->getEnvironment(), $output, $application); $output->writeln(''); $output->writeln(sprintf('[%s] Launching "%s" command', date('Y-m-d H:i:s'), $command)); $mem = (int) memory_get_usage() / (1024 * 1024); $time = time(); $result = null; try { $commandExecutor->runCommand($command, $params); $result = $commandExecutor->getLastCommandExitCode(); } catch (\RuntimeException $ex) { $result = $ex; } $output->writeln(''); $output->writeln(sprintf('Command "%s" executed in %u second(s), memory usage: %.2fMb', $command, time() - $time, (int) memory_get_usage() / (1024 * 1024) - $mem)); $output->writeln(''); // check for any error if ($result instanceof \RuntimeException) { throw $result; } return $result; }
/** * @param ConsoleTerminateEvent $event */ public function onConsoleTerminate(ConsoleTerminateEvent $event) { $command = $event->getCommand(); $environment = $this->kernel->getEnvironment(); if ($environment == 'test' && $command instanceof LoadMigrationsCommand && $event->getInput()->getOption('force')) { $executor = new CommandExecutor($environment, $event->getOutput(), $command->getApplication()); $executor->runCommand('oro:test:schema:update', ['--process-isolation' => true]); } }
/** * @param InputInterface $input * @param OutputInterface $output * * @return CommandExecutor */ protected function getCommandExecutor(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); $commandExecutor = new CommandExecutor($input->hasOption('env') ? $input->getOption('env') : null, $output, $this->getApplication(), $container->get('oro_cache.oro_data_cache_manager')); $timeout = $input->getOption('timeout'); if ($timeout > 0) { $commandExecutor->setDefaultOption('process-timeout', $timeout); } if (!$input->getOption('force-debug') && (true === $input->getOption('no-debug') || $container->get('kernel')->isDebug())) { $commandExecutor->setDefaultOption('no-debug'); } return $commandExecutor; }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $force = $input->getOption('force'); if ($force) { $assetsOptions = array('--exclude' => array('OroInstallerBundle')); if ($input->hasOption('symlink') && $input->getOption('symlink')) { $assetsOptions['--symlink'] = true; } $commandExecutor = new CommandExecutor($input->hasOption('env') ? $input->getOption('env') : null, $output, $this->getApplication(), $this->getContainer()->get('oro_cache.oro_data_cache_manager')); $commandExecutor->setDefaultTimeout($input->getOption('timeout')); $commandExecutor->runCommand('oro:migration:load', array('--process-isolation' => true, '--force' => true))->runCommand('oro:workflow:definitions:load', array('--process-isolation' => true))->runCommand('oro:process:configuration:load', array('--process-isolation' => true))->runCommand('oro:migration:data:load', array('--process-isolation' => true))->runCommand('oro:navigation:init', array('--process-isolation' => true))->runCommand('oro:assets:install', $assetsOptions)->runCommand('assetic:dump')->runCommand('fos:js-routing:dump', array('--target' => 'web/js/routes.js'))->runCommand('oro:localization:dump')->runCommand('oro:translation:dump')->runCommand('oro:requirejs:build', array('--ignore-errors' => true)); } else { $output->writeln('<comment>ATTENTION</comment>: Database backup is highly recommended before executing this command.'); $output->writeln(' Please make sure that application cache is up-to-date before run this command.'); $output->writeln(' Use <info>cache:clear</info> if needed.'); $output->writeln(''); $output->writeln('To force execution run command with <info>--force</info> option:'); $output->writeln(sprintf(' <info>%s --force</info>', $this->getName())); } }
/** * @param CommandExecutor $commandExecutor * @param OutputInterface $output * @param InputInterface $input * @return InstallCommand */ protected function finalStep(CommandExecutor $commandExecutor, OutputInterface $output, InputInterface $input) { $output->writeln('<info>Preparing application.</info>'); $assetsOptions = array('--exclude' => array('OroInstallerBundle')); if ($input->hasOption('symlink') && $input->getOption('symlink')) { $assetsOptions['--symlink'] = true; } $commandExecutor->runCommand('oro:navigation:init', array('--process-isolation' => true))->runCommand('fos:js-routing:dump', array('--target' => 'web/js/routes.js', '--process-isolation' => true))->runCommand('oro:localization:dump')->runCommand('oro:assets:install', $assetsOptions)->runCommand('assetic:dump', array('--process-isolation' => true))->runCommand('oro:translation:dump', array('--process-isolation' => true))->runCommand('oro:requirejs:build', array('--ignore-errors' => true, '--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; }
/** * Update the organization * * @param CommandExecutor $commandExecutor */ protected function updateOrganization(CommandExecutor $commandExecutor) { /** @var ConfigManager $configManager */ $configManager = $this->getContainer()->get('oro_config.global'); $defaultOrganizationName = $configManager->get('diamante_distribution.organization_name'); $organizationNameValidator = function ($value) use(&$defaultOrganizationName) { $len = strlen(trim($value)); if ($len === 0 && empty($defaultOrganizationName)) { throw new \Exception('The organization name must not be empty'); } if ($len > 15) { throw new \Exception('The organization name must be not more than 15 characters long'); } return $value; }; $options = ['organization-name' => ['label' => 'Organization name', 'askMethod' => 'askAndValidate', 'additionalAskArguments' => [$organizationNameValidator], 'defaultValue' => $defaultOrganizationName]]; $commandParameters = []; foreach ($options as $optionName => $optionData) { $commandParameters['--' . $optionName] = $this->inputOptionProvider->get($optionName, $optionData['label'], $optionData['defaultValue'], $optionData['askMethod'], $optionData['additionalAskArguments']); } $commandExecutor->runCommand('oro:organization:update', array_merge(['organization-name' => 'default', '--process-isolation' => true], $commandParameters)); }
private function ensureAliasesSet() { if (!CommandExecutor::isCurrentCommand('oro:entity-extend:update-config')) { ExtendClassLoadingUtils::setAliases($this->cacheDir); } }
/** * Finds the PHP executable. * * @return string */ private function getPhpExecutable() { if (null === $this->phpExecutable) { $this->phpExecutable = CommandExecutor::getPhpExecutable(); } return $this->phpExecutable; }