public function listenForServerRunCommand(ConsoleCommandEvent $event)
 {
     if (!$event->getCommand() instanceof ServerRunCommand) {
         return;
     }
     $argv = $_SERVER['argv'];
     if (count($argv) < 3) {
         return;
     }
     // strip the application name
     array_shift($argv);
     // strip the command name
     array_shift($argv);
     $address = $argv[0];
     if (0 !== strpos($address, '0.0.0.0')) {
         return;
     }
     $address = str_replace('0.0.0.0', $this->getLocalIp(), $address);
     $output = $event->getOutput();
     $output->writeln(sprintf('If you are in a container you would probably prefer to use: <info>http://%s</info>', $address));
     if (function_exists('uprofiler_enable')) {
         $output->writeln(sprintf('XHProf UI: <info>http://%s/xhprof</info>', $address));
     }
     $output->writeln('');
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function setDefaultValues(ConsoleCommandEvent $event)
 {
     /* @var Command $command */
     $command = $event->getCommand();
     $application = $command->getApplication();
     $config = $application->getConfig();
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     $input = $command->getDefinition();
     $options = $input->getOptions();
     foreach ($options as $key => $option) {
         $defaultOption = sprintf('application.default.commands.%s.options.%s', str_replace(':', '.', $command->getName()), $key);
         $defaultValue = $config->get($defaultOption);
         if ($defaultValue) {
             $option->setDefault($defaultValue);
         }
     }
     $arguments = $input->getArguments();
     foreach ($arguments as $key => $argument) {
         $defaultArgument = sprintf('application.default.commands.%s.arguments.%s', str_replace(':', '.', $command->getName()), $key);
         $defaultValue = $config->get($defaultArgument);
         if ($defaultValue) {
             $argument->setDefault($defaultValue);
         }
     }
 }
 /**
  * @param ConsoleCommandEvent $event
  *
  * @return void
  * @throws CommandAlreadyRunningException
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     // generate pid file name
     $commandName = $event->getCommand()->getName();
     // check for exceptions
     if (in_array($commandName, $this->exceptionsList)) {
         return;
     }
     $clearedCommandName = $this->cleanString($commandName);
     $pidFile = $this->pidFile = $this->pidDirectory . "/{$clearedCommandName}.pid";
     // check if command is already executing
     if (file_exists($pidFile)) {
         $pidOfRunningCommand = file_get_contents($pidFile);
         $elements = explode(":", $pidOfRunningCommand);
         if ($elements[0] == gethostname()) {
             if (posix_getpgid($elements[1]) !== false) {
                 throw (new CommandAlreadyRunningException())->setCommandName($commandName)->setPidNumber($pidOfRunningCommand);
             } else {
                 // pid file exist but the process is not running anymore
                 unlink($pidFile);
             }
         } else {
             throw (new CommandAlreadyRunningException())->setCommandName($commandName)->setPidNumber($pidOfRunningCommand);
         }
     }
     // if is not already executing create pid file
     //file_put_contents($pidFile, getmypid());
     // Añadimos hostname para verificar desde que frontal se estan ejecutando
     $string = gethostname() . ":" . getmypid();
     file_put_contents($pidFile, $string);
     // register shutdown function to remove pid file in case of unexpected exit
     register_shutdown_function(array($this, 'shutDown'), null, $pidFile);
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function validateDependencies(ConsoleCommandEvent $event)
 {
     /**
      * @var \Drupal\AppConsole\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     $application = $command->getApplication();
     $messageHelper = $application->getHelperSet()->get('message');
     /**
      * @var TranslatorHelper
      */
     $translatorHelper = $application->getHelperSet()->get('translator');
     if (!$command instanceof Command) {
         return;
     }
     $dependencies = $command->getDependencies();
     if ($dependencies) {
         foreach ($dependencies as $dependency) {
             if (\Drupal::moduleHandler()->moduleExists($dependency) === false) {
                 $errorMessage = sprintf($translatorHelper->trans('commands.common.errors.module-dependency'), $dependency);
                 $messageHelper->showMessage($output, $errorMessage, 'error');
                 $event->disableCommand();
             }
         }
     }
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function setDefaultValues(ConsoleCommandEvent $event)
 {
     /** @var \Drupal\AppConsole\Command\Command $command */
     $command = $event->getCommand();
     /** @var \Drupal\AppConsole\Console\Application $command */
     $application = $command->getApplication();
     /** @var \Drupal\AppConsole\Config $config */
     $config = $application->getConfig();
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     $input = $command->getDefinition();
     $options = $input->getOptions();
     foreach ($options as $key => $option) {
         $defaultOption = 'commands.' . str_replace(':', '.', $command->getName()) . '.options.' . $key;
         $defaultValue = $config->get($defaultOption);
         if ($defaultValue) {
             $option->setDefault($defaultValue);
         }
     }
     $arguments = $input->getArguments();
     foreach ($arguments as $key => $argument) {
         $defaultArgument = 'commands.' . str_replace(':', '.', $command->getName()) . '.arguments.' . $key;
         $defaultValue = $config->get($defaultArgument);
         if ($defaultValue) {
             $argument->setDefault($defaultValue);
         }
     }
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     $input = $event->getInput();
     if (in_array($command->getName(), $this->ignoredCommands)) {
         $this->interactor->ignoreTransaction();
     }
     if ($this->newRelic->getName()) {
         $this->interactor->setApplicationName($this->newRelic->getName(), $this->newRelic->getLicenseKey(), $this->newRelic->getXmit());
     }
     $this->interactor->setTransactionName($command->getName());
     $this->interactor->enableBackgroundJob();
     // send parameters to New Relic
     foreach ($input->getOptions() as $key => $value) {
         $key = '--' . $key;
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 $this->interactor->addCustomParameter($key . '[' . $k . ']', $v);
             }
         } else {
             $this->interactor->addCustomParameter($key, $value);
         }
     }
     foreach ($input->getArguments() as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 $this->interactor->addCustomParameter($key . '[' . $k . ']', $v);
             }
         } else {
             $this->interactor->addCustomParameter($key, $value);
         }
     }
 }
 /**
  * @param ConsoleCommandEvent $event
  * @return void
  */
 public function showGenerateDoc(ConsoleCommandEvent $event)
 {
     /**
      * @var \Drupal\Console\Command\Command $command
      */
     $command = $event->getCommand();
     /**
      * @var \Drupal\Console\Console\Application $command
      */
     $application = $command->getApplication();
     /**
      * @var \Drupal\Console\Config $config
      */
     $config = $application->getConfig();
     $input = $command->getDefinition();
     $options = $input->getOptions();
     $arguments = $input->getArguments();
     if (isset($options['generate-doc']) && $options['generate-doc'] == 1) {
         foreach ($this->skipOptions as $remove_option) {
             unset($options[$remove_option]);
         }
         $parameters = ['options' => $options, 'arguments' => $arguments, 'command' => $command->getName(), 'description' => $command->getDescription(), 'aliases' => $command->getAliases()];
         $renderedDoc = $application->getHelperSet()->get('renderer')->render('gitbook/generate-doc.md.twig', $parameters);
         $output = $event->getOutput();
         $output->writeln($renderedDoc);
         $event->disableCommand();
     }
 }
 /**
  * Before a Console command runs, examine the global
  * commandline options from the event Input, and set
  * configuration values as appropriate.
  *
  * @param ConsoleCommandEvent $event
  */
 public function setGlobalOptions(ConsoleCommandEvent $event)
 {
     /* @var Input $input */
     $input = $event->getInput();
     // TODO: We need a good strategy for managing global options.
     // $simulate = $input->getOption('simulate');
 }
 public function setOutputWriter(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$this->isMigrationCommand($command)) {
         return;
     }
     $this->outputWriter->setConsoleOutput($event->getOutput());
 }
 public function registerMigrations(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$this->isMigrationCommand($command)) {
         return;
     }
     $this->configuration->registerMigrationsFromDirectory($this->configuration->getMigrationsDirectory());
 }
 private function mergeDefinitions(ConsoleCommandEvent $event)
 {
     $inputDefinition = $event->getCommand()->getApplication()->getDefinition();
     $inputDefinition->addOption(new InputOption('log-memory', null, InputOption::VALUE_NONE, 'Output information about memory usage', null));
     $inputDefinition->addOption(new InputOption('daemonize', null, InputOption::VALUE_NONE, 'Output information about memory usage', null));
     $event->getCommand()->mergeApplicationDefinition();
     return true;
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function onCronStart(ConsoleCommandEvent $event)
 {
     if (!$this->isCronCommand($event->getCommand()->getName(), $event->getInput())) {
         $this->skipped = true;
         return;
     }
     $this->start = microtime(true);
 }
Exemple #13
0
 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if ($this->registry->isChainedCommand($command)) {
         $event->disableCommand();
         $event->getOutput()->writeln('<error>Chained command should not be executed directly</error>');
     }
 }
 public function onCommandStart(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!in_array($command->getName(), $this->listenedCommands)) {
         return;
     }
     $commandSlug = preg_replace('/[^a-zA-Z0-9_.]/', '', $command->getName());
     $this->watcher->start($commandSlug);
 }
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $this->siteAccess->name = $event->getInput()->getParameterOption('--siteaccess', $this->defaultSiteAccessName);
     $this->siteAccess->matchingType = 'cli';
     if (!in_array($this->siteAccess->name, $this->siteAccessList)) {
         throw new InvalidSiteAccessException($this->siteAccess->name, $this->siteAccessList, $this->siteAccess->matchingType);
     }
     $this->eventDispatcher->dispatch(MVCEvents::CONFIG_SCOPE_CHANGE, new ScopeChangeEvent($this->siteAccess));
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     $input = $event->getInput();
     $this->addOptionsToCommand($command, $input);
     $listeners = $this->getListenersToDisable($input);
     if (!empty($listeners)) {
         $this->listenersManager->disableListeners($listeners);
     }
 }
Exemple #17
0
 /**
  * @see getSubscribedEvents
  *
  * @param ConsoleCommandEvent $event
  */
 public function initializeEventIo(ConsoleCommandEvent $event)
 {
     $set = $event->getCommand()->getHelperSet();
     if (!$set->has(self::HELPER_NAME)) {
         return;
     }
     /** @var  $helper IoHelper */
     $helper = $set->get(self::HELPER_NAME);
     $helper->initializeIo($event->getInput(), $event->getOutput());
 }
Exemple #18
0
 public function decorateDefinition(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$command instanceof InitCommand) {
         return;
     }
     $adapterName = $this->application->getConfig()->get('repo_adapter', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ADAPTER);
     $issueTracker = $this->application->getConfig()->get('issue_tracker', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ADAPTER);
     $command->addOption('repo-adapter', null, InputOption::VALUE_OPTIONAL, sprintf('Adapter-name of the repository-manager (%s)', $this->getSupportedAdapters(AdapterFactory::SUPPORT_REPOSITORY_MANAGER)), $adapterName)->addOption('issue-adapter', null, InputOption::VALUE_OPTIONAL, sprintf('Adapter-name of the issue-tracker (%s)', $this->getSupportedAdapters(AdapterFactory::SUPPORT_ISSUE_TRACKER)), $issueTracker)->addOption('org', 'o', InputOption::VALUE_REQUIRED, 'Name of the Git organization', $this->application->getConfig()->get('repo_org', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ORG))->addOption('repo', 'r', InputOption::VALUE_REQUIRED, 'Name of the Git repository', $this->application->getConfig()->get('repo_name', Config::CONFIG_LOCAL, GitHelper::UNDEFINED_REPO))->addOption('issue-org', 'io', InputOption::VALUE_REQUIRED, 'Name of the issue-tracker organization', $this->application->getConfig()->getFirstNotNull(['issue_project_org', 'repo_org'], Config::CONFIG_LOCAL, GitHelper::UNDEFINED_ORG))->addOption('issue-project', 'ip', InputOption::VALUE_REQUIRED, 'Repository/Project name of the issue-tracker', $this->application->getConfig()->getFirstNotNull(['issue_project', 'repo_name'], Config::CONFIG_LOCAL, GitHelper::UNDEFINED_REPO));
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     if ('doctrine:schema:update' === $event->getCommand()->getName()) {
         /**
          * to disable automatic rename of autogenerated indices
          * we have to use "class_alias" to replace "Doctrine\DBAL\Schema\SchemaDiff"
          * with "Oro\Bundle\MigrationBundle\Migration\Schema\SchemaDiff"
          */
         class_alias('Oro\\Bundle\\MigrationBundle\\Migration\\Schema\\SchemaDiff', 'Doctrine\\DBAL\\Schema\\SchemaDiff');
     }
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$command instanceof FormBasedCommand) {
         return;
     }
     $input = $event->getInput();
     $output = $event->getOutput();
     $formData = $this->formQuestionHelper->interactUsingForm($command->formType(), $input, $output);
     $command->setFormData($formData);
 }
 public function initialize(ConsoleCommandEvent $event)
 {
     /** @var GitDirectoryFeature|BaseCommand $command */
     $command = $event->getCommand();
     if (!$command instanceof GitDirectoryFeature) {
         return;
     }
     if (!$this->gitHelper->isGitDir()) {
         throw new UserException(sprintf('The "%s" command can only be executed from the root of a Git repository.', $command->getName()));
     }
 }
 /**
  * @DI\Observe("console.command")
  */
 public function onExecute(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if ($command->getName() === 'assetic:dump') {
         $command = new DumpCommand();
         $command->setContainer($this->container);
         $input = new ArrayInput(array());
         $output = new ConsoleOutput();
         $resultCode = $command->run($input, $output);
     }
 }
 /**
  * On Command Event Handler
  *
  * Check if the current command requires EE bootstrapping
  * and throw an exception if EE is not bootstrapped
  *
  * @param  ConsoleCommandEvent $event
  * @return void
  */
 public function onCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     $output = $event->getOutput();
     if (!$this->isCommandExemptFromBootstrap($command)) {
         if (!$this->canBeBootstrapped()) {
             throw new \Exception('Your craft path could not be found.');
         }
         $this->bootstrap();
     }
 }
Exemple #24
0
 /**
  * Analyzes and modifies command.
  *
  * @param ConsoleCommandEvent $event Command event
  */
 public function command(ConsoleCommandEvent $event)
 {
     /** @var ManifestCommand $command */
     $command = $event->getCommand();
     if (!in_array($command->getName(), $this->getSupportedCommands())) {
         return;
     }
     $command->setChain($this->chain);
     if ($command instanceof RunCommand) {
         $command->setEventDispatcher($this->dispatcher);
     }
 }
Exemple #25
0
 public function initialize(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$command instanceof TableFeature) {
         return;
     }
     $input = $event->getInput();
     $layout = $input->getOption('table-layout');
     if ($layout && !in_array($layout, $this->validLayouts, true)) {
         throw new \InvalidArgumentException(sprintf('The table-layout option must be passed one of "%s" but was given "%s"', implode(', ', $this->validLayouts), $layout));
     }
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function onConsoleCommand(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if ($command instanceof HelpCommand) {
         $command = $this->getCommandFromHelpCommand($command, $event->getInput());
     }
     if (!$command instanceof FormBasedCommand) {
         return;
     }
     $inputDefinition = $this->inputDefinitionFactory->createForFormType($command->formType());
     $this->setInputDefinition($command, $event->getInput(), $inputDefinition);
 }
 public function initialize(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if ($command instanceof TemplateFeature) {
         $input = $event->getInput();
         $template = $input->getOption('template');
         if ($template) {
             $validTemplates = $this->templateHelper->getNamesForDomain($command->getTemplateDomain());
             if (!in_array($template, $validTemplates, true)) {
                 throw new \InvalidArgumentException(sprintf('The specified template "%s" does not exist, try one of: ' . PHP_EOL . ' - %s', $template, implode(PHP_EOL . ' - ', $validTemplates)));
             }
         }
     }
 }
 /**
  * This function saves the bundle whose routes shall be translated in a global variable to be used in
  * Zikula\RoutesModule\Translation\DefaultRouteExclusionStrategy later on.
  *
  * @param ConsoleCommandEvent $event
  */
 public function checkBundleForTranslatingRoutes(ConsoleCommandEvent $event)
 {
     if ($event->getCommand()->getName() !== 'translation:extract') {
         return;
     }
     $GLOBALS['translation_extract_routes'] = true;
     if ($event->getInput()->hasParameterOption('--bundle')) {
         $bundle = $event->getInput()->getParameterOption('--bundle');
         if ('@' === $bundle[0]) {
             $bundle = substr($bundle, 1);
         }
         $GLOBALS['translation_extract_routes_bundle'] = $bundle;
     }
 }
 /**
  * @param ConsoleCommandEvent $event
  */
 public function showWelcomeMessage(ConsoleCommandEvent $event)
 {
     /* @var Command $command */
     $command = $event->getCommand();
     /* @var DrupalStyle $io */
     $io = $event->getOutput();
     $application = $command->getApplication();
     $translatorHelper = $application->getTranslator();
     $welcomeMessageKey = 'commands.' . str_replace(':', '.', $command->getName()) . '.welcome';
     $welcomeMessage = $translatorHelper->trans($welcomeMessageKey);
     if ($welcomeMessage != $welcomeMessageKey) {
         $io->text($welcomeMessage);
     }
 }
 /**
  * Before a Console command runs, examine the global
  * commandline options from the event Input, and set
  * configuration values as appropriate.
  *
  * @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event
  */
 public function setGlobalOptions(ConsoleCommandEvent $event)
 {
     $config = $this->getConfig();
     $input = $event->getInput();
     $globalOptions = $config->getGlobalOptionDefaultValues();
     foreach ($globalOptions as $option => $default) {
         $value = $input->hasOption($option) ? $input->getOption($option) : null;
         // Unfortunately, the `?:` operator does not differentate between `0` and `null`
         if (!isset($value)) {
             $value = $default;
         }
         $config->set($option, $value);
     }
 }