コード例 #1
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);
     }
 }
コード例 #2
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);
     }
 }
コード例 #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 $e
  */
 public function onTerminate(ConsoleTerminateEvent $e)
 {
     // For non-0 exit command, fire an ERROR event
     if ($e->getExitCode() != 0) {
         $this->dispatch(ConsoleEvent::ERROR, $e);
     }
     $this->dispatch(ConsoleEvent::TERMINATE, $e);
 }
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     $command = $event->getCommand();
     $input = $event->getInput();
     if ('rabbitmq:consumer' === $command->getName() && $this->consumerName === $input->getArgument('name')) {
         $this->om->flush();
     }
 }
コード例 #6
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));
     }
 }
コード例 #7
0
 public function testOnTerminate()
 {
     $track_clear_cache = true;
     $this->keeper->expects($this->once())->method('set')->with(Keeper::LAST_UPDATE_KEY, $this->isInstanceOf(\DateTime::class));
     $this->event->expects($this->once())->method('getCommand')->will($this->returnValue($this->command));
     $this->command->expects($this->once())->method('getName')->will($this->returnValue('cache:clear'));
     $listener = new ConsoleListener($this->keeper, $track_clear_cache);
     $listener->onTerminate($this->event);
 }
コード例 #8
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]);
     }
 }
コード例 #9
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());
 }
コード例 #10
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);
     }
 }
コード例 #11
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();
 }
コード例 #12
0
 /**
  * Log Abnormal exists for AcmPhp commands.
  *
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if (0 === ($exitCode = $event->getExitCode())) {
         return;
     }
     if (!$this->isAcmePhpCommand($event->getCommand())) {
         return;
     }
     $this->logger->error('Command "{command}" exited with code "{exitCode}".', ['command' => $event->getCommand()->getName(), 'exitCode' => $exitCode]);
 }
コード例 #13
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());
         }
     }
 }
コード例 #14
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function afterExecute(ConsoleTerminateEvent $event)
 {
     switch ($event->getCommand()->getName()) {
         case DriverLockCommandListener::LEXIK_MAINTENANCE_LOCK:
             $this->dispatcher->dispatch(Events::MAINTENANCE_ON);
             break;
         case DriverLockCommandListener::LEXIK_MAINTENANCE_UNLOCK:
             $this->dispatcher->dispatch(Events::MAINTENANCE_OFF);
             break;
     }
 }
コード例 #15
0
 public function applyCodingStyle(ConsoleTerminateEvent $event)
 {
     $command = $event->getCommand();
     if (!$this->isAllowedCommand($command->getName())) {
         return;
     }
     $filename = $this->getCurrentMigrationFileName();
     if (file_exists($filename)) {
         $this->codeStyle->applyForFile($filename);
     }
 }
コード例 #16
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     $statusCode = $event->getExitCode();
     $command = $event->getCommand();
     if ($statusCode === 0) {
         return;
     }
     if ($statusCode > 255) {
         $statusCode = 255;
         $event->setExitCode($statusCode);
     }
     $this->logger->warning(sprintf('Command `%s` exited with status code %d', $command->getName(), $statusCode));
 }
コード例 #17
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;
     }
 }
コード例 #18
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;
     }
 }
コード例 #19
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.');
             }
         }
     }
 }
コード例 #20
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);
     }
 }
コード例 #21
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onTerminate(ConsoleTerminateEvent $event)
 {
     if ($event->getCommand()->getName() == 'cache:clear') {
         $env = ltrim($event->getInput()->getOption('env'), '=');
         $cmd = 'animedb:update-titles -e=' . $env;
         $phpFinder = new PhpExecutableFinder();
         if (!($phpPath = $phpFinder->find())) {
             throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
         }
         $php = escapeshellarg($phpPath);
         $process = new Process($php . ' app/console ' . $cmd, $this->root_dir . '/../', null, null, 1500);
         $process->run(function ($type, $buffer) {
             echo $buffer;
         });
         if (!$process->isSuccessful()) {
             throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command.', $cmd));
         }
     }
 }
コード例 #22
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);
         }
     }
 }
コード例 #23
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);
     }
 }
コード例 #24
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);
         }
     }
 }
コード例 #25
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);
         }
     }
 }
コード例 #26
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);
         }
     }
 }
コード例 #27
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);
     }
 }
コード例 #28
0
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onTerminate(ConsoleTerminateEvent $event)
 {
     if ($this->track_clear_cache && $event->getCommand()->getName() == 'cache:clear') {
         $this->keeper->set(Keeper::LAST_UPDATE_KEY, new \DateTime());
     }
 }
コード例 #29
0
 /**
  * @param \Symfony\Component\Console\Event\ConsoleTerminateEvent $event
  *
  * @return array
  */
 protected function addOptionsAsCustomParameter(ConsoleTerminateEvent $event)
 {
     $this->addCustomParameter($event->getInput()->getOptions());
 }
コード例 #30
0
 /**
  * Cleanup after run command
  *
  * @param ConsoleTerminateEvent $event
  */
 public function onTerminate(ConsoleTerminateEvent $event)
 {
     if (!$this->isPIDRequired($event->getCommand())) {
         return;
     }
     $pidFile = $event->getInput()->getOption(static::PID_OPTION);
     if (null !== $pidFile) {
         unlink($pidFile);
     }
 }