コード例 #1
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showCompletedMessage(ConsoleTerminateEvent $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');
     $messageHelper->showMessages($output);
     if ($event->getExitCode() != 0) {
         return;
     }
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     $completedMessageKey = 'application.console.messages.completed';
     if ($command instanceof GeneratorCommand) {
         $completedMessageKey = 'application.console.messages.generated.completed';
     }
     $completedMessage = $translatorHelper->trans($completedMessageKey);
     if ($completedMessage != $completedMessageKey) {
         $messageHelper->showMessage($output, $completedMessage);
     }
 }
コード例 #2
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function callCommands(ConsoleTerminateEvent $event)
 {
     /**
      * @var \Drupal\Console\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     if (!$command instanceof Command) {
         return;
     }
     $application = $command->getApplication();
     $commands = $application->getChain()->getCommands();
     if (!$commands) {
         return;
     }
     foreach ($commands as $chainedCommand) {
         if ($chainedCommand['name'] == 'module:install') {
             $messageHelper = $application->getMessageHelper();
             $translatorHelper = $application->getTranslator();
             $messageHelper->addErrorMessage($translatorHelper->trans('commands.chain.messages.module_install'));
             continue;
         }
         $callCommand = $application->find($chainedCommand['name']);
         $input = new ArrayInput($chainedCommand['inputs']);
         if (!is_null($chainedCommand['interactive'])) {
             $input->setInteractive($chainedCommand['interactive']);
         }
         $callCommand->run($input, $output);
     }
 }
コード例 #3
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if ($event->getCommand() instanceof UpdateSchemaDoctrineCommand) {
         $output = $event->getOutput();
         $input = $event->getInput();
         if ($input->getOption('force')) {
             $result = $this->fulltextIndexManager->createIndexes();
             $output->writeln('Schema update and create index completed.');
             if ($result) {
                 $output->writeln('Indexes were created.');
             }
         }
     }
     if ($event->getCommand() instanceof UpdateSchemaCommand) {
         $entities = $this->registry->getRepository('OroSearchBundle:UpdateEntity')->findAll();
         if (count($entities)) {
             $em = $this->registry->getManager();
             foreach ($entities as $entity) {
                 $job = new Job(ReindexCommand::COMMAND_NAME, ['class' => $entity->getEntity()]);
                 $em->persist($job);
                 $em->remove($entity);
             }
             $em->flush($job);
         }
     }
 }
コード例 #4
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if ('check' == $event->getCommand()->getName()) {
         $stopEvent = $this->stopwatch->stop('check_command');
         $output = $event->getOutput();
         $output->writeln(sprintf('Checked source files in %s seconds, %s MB memory used', $stopEvent->getDuration() / 1000, $stopEvent->getMemory() / 1024 / 1024));
     }
 }
コード例 #5
0
 /**
  * @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]);
     }
 }
コード例 #6
0
 public function onCommandEnd(ConsoleTerminateEvent $event)
 {
     $command = $event->getCommand();
     if (!in_array($command->getName(), $this->listenedCommands)) {
         return;
     }
     $commandSlug = preg_replace('/[^a-zA-Z0-9_.]/', '', $command->getName());
     $this->watcher->end($commandSlug, $event->getOutput(), $event->getInput()->getArguments());
 }
コード例 #7
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showGenerateInline(ConsoleTerminateEvent $event)
 {
     /**
      * @var \Drupal\AppConsole\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     $command_name = $command->getName();
     $this->skipArguments[] = $command_name;
     $application = $command->getApplication();
     $messageHelper = $application->getHelperSet()->get('message');
     /**
      * @var TranslatorHelper
      */
     $translatorHelper = $application->getHelperSet()->get('translator');
     if ($event->getExitCode() != 0) {
         return;
     }
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     // get the input instance
     $input = $event->getInput();
     //Get options list
     $options = array_filter($input->getOptions());
     if (isset($options['generate-inline']) && $options['generate-inline'] == 1) {
         // Remove unnecessary options
         foreach ($this->skipOptions as $remove_option) {
             unset($options[$remove_option]);
         }
         // Get argument list
         $arguments = array_filter($input->getArguments());
         // Remove unnecessary arguments
         foreach ($this->skipArguments as $remove_argument) {
             unset($arguments[$remove_argument]);
         }
         $inline = '';
         foreach ($arguments as $argument_id => $argument) {
             if (is_array($argument)) {
                 $argument = implode(" ", $argument);
             } elseif (strstr($argument, ' ')) {
                 $argument = '"' . $argument . '"';
             }
             $inline .= " {$argument}";
         }
         foreach ($options as $option_id => $option) {
             if (strstr($option, ' ')) {
                 $option = '"' . $option . '"';
             }
             $inline .= ' --' . $option_id . '=' . $option;
         }
         // Print yaml output and message
         $messageHelper->showMessage($output, $translatorHelper->trans('application.console.messages.inline.generated'));
         $output->writeln('$ drupal' . $inline);
     }
 }
コード例 #8
0
 public function handleTerminate(ConsoleTerminateEvent $event)
 {
     $command = $event->getCommand();
     $output = $event->getOutput();
     $session = $command->get('phpcr.session');
     if ($session->hasPendingChanges()) {
         $output->writeln('<info>Auto-saving session</info>');
     }
     $session->save();
 }
コード例 #9
0
ファイル: ChainCommandListener.php プロジェクト: sergeyz/cc
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     $command = $event->getCommand();
     $application = $command->getApplication();
     if ($this->registry->isChainCommand($command)) {
         $dependencies = $this->registry->getDependencies($command);
         foreach ($dependencies as $dep) {
             $application->find($dep)->run($event->getInput(), $event->getOutput());
         }
     }
 }
コード例 #10
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showTerminateMessages(ConsoleTerminateEvent $event)
 {
     /**
      * @var \Drupal\Console\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     $application = $command->getApplication();
     $messageHelper = $application->getMessageHelper();
     $messageHelper->showMessages($output);
     if ($event->getExitCode() != 0) {
         return;
     }
 }
コード例 #11
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if ($event->getCommand() instanceof UpdateSchemaDoctrineCommand) {
         $output = $event->getOutput();
         $input = $event->getInput();
         if ($input->getOption('force')) {
             $result = $this->fulltextIndexManager->createIndexes();
             $output->writeln('Schema update and create index completed.');
             if ($result) {
                 $output->writeln('Indexes were created.');
             }
         }
     }
 }
コード例 #12
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showTerminateMessages(ConsoleTerminateEvent $event)
 {
     /* @var Command $command */
     $command = $event->getCommand();
     /* @var DrupalStyle $io */
     $io = $event->getOutput();
     $application = $command->getApplication();
     if ($errorMessage = $application->getErrorMessage()) {
         $io->warning($errorMessage);
     }
     if ($event->getExitCode() != 0) {
         return;
     }
 }
コード例 #13
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showGenerateChain(ConsoleTerminateEvent $event)
 {
     /**
      * @var \Drupal\Console\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     $command_name = $command->getName();
     $this->skipArguments[] = $command_name;
     $application = $command->getApplication();
     $messageHelper = $application->getHelperSet()->get('message');
     /* @var TranslatorHelper */
     $translatorHelper = $application->getHelperSet()->get('translator');
     if ($event->getExitCode() != 0) {
         return;
     }
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     // get the input instance
     $input = $event->getInput();
     //Get options list
     $options = array_filter($input->getOptions());
     if (isset($options['generate-chain']) && $options['generate-chain'] == 1) {
         // Remove unnecessary options
         foreach ($this->skipOptions as $remove_option) {
             unset($options[$remove_option]);
         }
         // Get argument list
         $arguments = array_filter($input->getArguments());
         // Remove unnecessary arguments
         foreach ($this->skipArguments as $remove_argument) {
             unset($arguments[$remove_argument]);
         }
         $yaml = array();
         $yaml[$command_name]['options'] = $options;
         $yaml[$command_name]['arguments'] = $arguments;
         $dumper = new Dumper();
         $yaml = $dumper->dump($yaml, 10);
         // Print yaml output and message
         $messageHelper->showMessage($output, $translatorHelper->trans('application.console.messages.chain.generated'));
         $output->writeln($yaml);
     }
 }
コード例 #14
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showGeneratedFiles(ConsoleTerminateEvent $event)
 {
     /** @var \Drupal\AppConsole\Command\Command $command */
     $command = $event->getCommand();
     $output = $event->getOutput();
     $application = $command->getApplication();
     $messageHelper = $application->getHelperSet()->get('message');
     if ($event->getExitCode() != 0) {
         return;
     }
     if ('self-update' == $command->getName()) {
         return;
     }
     if ($command instanceof GeneratorCommand) {
         $files = $command->getGenerator()->getFiles();
         if ($files) {
             $messageHelper->showGeneratedFiles($output, $files);
         }
     }
 }
コード例 #15
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function callCommands(ConsoleTerminateEvent $event)
 {
     //        /* @var Command $command */
     $command = $event->getCommand();
     /* @var DrupalStyle $io */
     $io = $event->getOutput();
     if (!$command instanceof Command && !$command instanceof BaseCommand) {
         return;
     }
     $application = $command->getApplication();
     $commands = $application->getContainer()->get('chain')->getCommands();
     if (!$commands) {
         return;
     }
     foreach ($commands as $chainedCommand) {
         $callCommand = $application->find($chainedCommand['name']);
         $input = new ArrayInput($chainedCommand['inputs']);
         if (!is_null($chainedCommand['interactive'])) {
             $input->setInteractive($chainedCommand['interactive']);
         }
         $io->text($chainedCommand['name']);
         $callCommand->run($input, $io);
         $drupal = $application->getContainer()->get('site');
         if ($chainedCommand['name'] === 'site:new') {
             if ($chainedCommand['inputs']['directory']) {
                 $siteRoot = sprintf('%s/%s', getcwd(), $chainedCommand['inputs']['directory']);
                 chdir($siteRoot);
             }
             $drupal->isValidRoot(getcwd());
             $drupal->getAutoLoadClass();
             $application->prepare($drupal);
         }
         if ($chainedCommand['name'] === 'site:install') {
             $drupal->isValidRoot(getcwd());
             $application->prepare($drupal);
         }
         if ($chainedCommand['name'] === 'settings:set') {
             $application->prepare($drupal);
         }
     }
 }
コード例 #16
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showGenerateChain(ConsoleTerminateEvent $event)
 {
     if ($event->getExitCode() != 0) {
         return;
     }
     /* @var Command $command */
     $command = $event->getCommand();
     /* @var DrupalStyle $io */
     $io = $event->getOutput();
     $command_name = $command->getName();
     $this->skipArguments[] = $command_name;
     $application = $command->getApplication();
     $translatorHelper = $application->getTranslator();
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     $input = $event->getInput();
     if ($input->getOption('generate-chain')) {
         $commands = [];
         $options = array_filter($input->getOptions());
         foreach ($this->skipOptions as $remove_option) {
             unset($options[$remove_option]);
         }
         $arguments = array_filter($input->getArguments());
         foreach ($this->skipArguments as $remove_argument) {
             unset($arguments[$remove_argument]);
         }
         $commands['commands'][0]['command'] = $command_name;
         if ($options) {
             $commands['commands'][0]['options'] = $options;
         }
         if ($arguments) {
             $commands['commands'][0]['arguments'] = $arguments;
         }
         $dumper = new Dumper();
         $yml = $dumper->dump($commands, 10);
         $yml = str_replace(sprintf('\'%s\':', $command_name), sprintf('  - command: %s', $command_name), $yml);
         $io->commentBlock($translatorHelper->trans('application.messages.chain.generated'));
         $io->writeln($yml);
     }
 }
コード例 #17
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showGeneratedFiles(ConsoleTerminateEvent $event)
 {
     /* @var Command $command */
     $command = $event->getCommand();
     /* @var DrupalStyle $io */
     $io = $event->getOutput();
     $application = $command->getApplication();
     $showFileHelper = $application->getShowFileHelper();
     if ($event->getExitCode() != 0) {
         return;
     }
     if ('self-update' == $command->getName()) {
         return;
     }
     if ($command instanceof GeneratorCommand) {
         $files = $command->getGenerator()->getFiles();
         if ($files) {
             $showFileHelper->generatedFiles($io, $files);
         }
     }
 }
コード例 #18
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function callCommands(ConsoleTerminateEvent $event)
 {
     /**
      * @var \Drupal\Console\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     if (!$command instanceof Command) {
         return;
     }
     $application = $command->getApplication();
     $commands = $application->getChain()->getCommands();
     if (!$commands) {
         return;
     }
     foreach ($commands as $chainedCommand) {
         $callCommand = $application->find($chainedCommand['name']);
         $input = new ArrayInput($chainedCommand['inputs']);
         if (!is_null($chainedCommand['interactive'])) {
             $input->setInteractive($chainedCommand['interactive']);
         }
         $callCommand->run($input, $output);
         $drupal = $application->getDrupalHelper();
         if ($chainedCommand['name'] === 'site:new') {
             if ($chainedCommand['inputs']['site-name']) {
                 $siteRoot = sprintf('%s/%s', getcwd(), $chainedCommand['inputs']['site-name']);
                 chdir($siteRoot);
             }
             $drupal->isValidRoot(getcwd());
             $drupal->getAutoLoadClass();
             $application->prepare($drupal);
         }
         if ($chainedCommand['name'] === 'site:install') {
             $drupal->isValidRoot(getcwd());
             $application->prepare($drupal);
         }
     }
 }
コード例 #19
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function callCommands(ConsoleTerminateEvent $event)
 {
     /**
      * @var \Drupal\Console\Command\Command $command
      */
     $command = $event->getCommand();
     $output = $event->getOutput();
     if (!$command instanceof Command) {
         return;
     }
     $application = $command->getApplication();
     $commands = $application->getChain()->getCommands();
     if (!$commands) {
         return;
     }
     foreach ($commands as $chainedCommand) {
         $callCommand = $application->find($chainedCommand['name']);
         $input = new ArrayInput($chainedCommand['inputs']);
         if (!is_null($chainedCommand['interactive'])) {
             $input->setInteractive($chainedCommand['interactive']);
         }
         $callCommand->run($input, $output);
     }
 }
コード例 #20
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function showGenerateInline(ConsoleTerminateEvent $event)
 {
     /* @var Command $command */
     $command = $event->getCommand();
     /* @var DrupalStyle $io */
     $io = $event->getOutput();
     $command_name = $command->getName();
     $this->skipArguments[] = $command_name;
     $application = $command->getApplication();
     $translatorHelper = $application->getTranslator();
     if ($event->getExitCode() != 0) {
         return;
     }
     if (in_array($command->getName(), $this->skipCommands)) {
         return;
     }
     $input = $event->getInput();
     if ($input->getOption('generate-inline')) {
         $options = array_filter($input->getOptions());
         foreach ($this->skipOptions as $remove_option) {
             unset($options[$remove_option]);
         }
         $arguments = array_filter($input->getArguments());
         foreach ($this->skipArguments as $remove_argument) {
             unset($arguments[$remove_argument]);
         }
         $inline = '';
         foreach ($arguments as $argument_id => $argument) {
             if (is_array($argument)) {
                 $argument = implode(" ", $argument);
             } elseif (strstr($argument, ' ')) {
                 $argument = '"' . $argument . '"';
             }
             $inline .= " {$argument}";
         }
         // Refactor and remove nested levels. Then apply to arguments.
         foreach ($options as $optionName => $optionValue) {
             if (is_array($optionValue)) {
                 foreach ($optionValue as $optionItem) {
                     if (is_array($optionItem)) {
                         $inlineValue = implode(' ', array_map(function ($v, $k) {
                             return $k . ':' . $v;
                         }, $optionItem, array_keys($optionItem)));
                     } else {
                         $inlineValue = $optionItem;
                     }
                     $inline .= ' --' . $optionName . '="' . $inlineValue . '"';
                 }
             } else {
                 if (is_bool($optionValue)) {
                     $inline .= ' --' . $optionName;
                 } else {
                     $inline .= ' --' . $optionName . '="' . $optionValue . '"';
                 }
             }
         }
         // Print yaml output and message
         $io->commentBlock($translatorHelper->trans('application.messages.inline.generated'));
         $io->writeln(sprintf('$ drupal %s %s', $command_name, $inline));
     }
 }
コード例 #21
0
 /**
  * Trigger the collector to end the request and output the xhprof link if
  * we where collecting.
  *
  * @param ConsoleTerminateEvent $event
  */
 public function onTerminate(ConsoleTerminateEvent $event)
 {
     $command = $event->getCommand();
     $link = $this->collector->stopProfiling('cli', $command->getName());
     if (false === $link) {
         return;
     }
     $event->getOutput()->writeln(sprintf("\n---\nXHProf run link <info>%s</info>", $this->collector->getXhprofUrl()));
 }