コード例 #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * DrupalConsole extends the SymfonyStyle class to provide
      * an standardized Output Formatting Style.
      *
      * Drupal Console provides the DrupalStyle helper class:
      */
     $io = new DrupalStyle($input, $output);
     $io->simple('This text could be translatable by');
     $io->simple('adding a YAML file at "config/translations/LANGUAGE/command.name.yml"');
     /**
      *  By using ContainerAwareCommand as the base class for the command
      *  (instead of the more basic Command), you have access to
      *  the service container.
      *
      *  In other words, you can access to any configured Drupal service
      *  using the provided getService method.
      *
      *  $this->getService('entity_type.manager');
      *
      *  Reading user input argument
      *  $input->getArgument('ARGUMENT_NAME');
      *
      *  Reading user input option
      *  $input->getOption('OPTION_NAME');
      */
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* Register your command as a service
      *
      * Make sure you register your command class at
      * config/services/namespace.yml file and add the `console.command` tag.
      *
      * develop_example:
      *   class: Drupal\Console\Command\Develop\ExampleCommand
      *   tags:
      *     - { name: console.command }
      *
      * NOTE: Make the proper changes on the namespace and class
      *       according your new command.
      *
      * DrupalConsole extends the SymfonyStyle class to provide
      * an standardized Output Formatting Style.
      *
      * Drupal Console provides the DrupalStyle helper class:
      */
     $io = new DrupalStyle($input, $output);
     $io->simple('This text could be translatable by');
     $io->simple('adding a YAML file at "config/translations/LANGUAGE/command.name.yml"');
     /**
      *  Reading user input argument
      *  $input->getArgument('ARGUMENT_NAME');
      *
      *  Reading user input option
      *  $input->getOption('OPTION_NAME');
      */
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $configFile = $input->getOption('file');
     $removeFiles = $input->getOption('remove-files');
     $configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
     if ($configFile) {
         $archiveTar = new ArchiveTar($configFile, 'gz');
         $io->simple($this->trans('commands.config.import.messages.config_files_imported'));
         foreach ($archiveTar->listContent() as $file) {
             $io->info('[-] ' . $file['filename']);
         }
         try {
             $archiveTar->extract($configSyncDir . '/');
         } catch (\Exception $e) {
             $io->error($e->getMessage());
             return;
         }
     }
     $finder = new Finder();
     $finder->in($configSyncDir);
     $finder->name("*.yml");
     foreach ($finder as $configFile) {
         $configName = $configFile->getBasename('.yml');
         $configFilePath = sprintf('%s/%s', $configSyncDir, $configFile->getBasename());
         $config = $this->getConfigFactory()->getEditable($configName);
         $parser = new Parser();
         $configData = $parser->parse(file_get_contents($configFilePath));
         $config->setData($configData);
         if ($removeFiles) {
             file_unmanaged_delete($configFilePath);
         }
         try {
             $config->save();
         } catch (\Exception $e) {
             $io->error($e->getMessage());
             return;
         }
     }
     $io->simple(sprintf($this->trans('commands.config.import.messages.imported'), CONFIG_SYNC_DIRECTORY));
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* Register your command as a service
      *
      * Make sure you register your command class at
      * config/services/namespace.yml file and add the `console.command` tag.
      *
      * develop_example_container_aware:
      *   class: Drupal\Console\Command\Develop\ExampleContainerAwareCommand
      *   tags:
      *     - { name: console.command }
      *
      * NOTE: Make the proper changes on the namespace and class
      *       according your new command.
      *
      * DrupalConsole extends the SymfonyStyle class to provide
      * an standardized Output Formatting Style.
      *
      * Drupal Console provides the DrupalStyle helper class:
      */
     $io = new DrupalStyle($input, $output);
     $io->simple('This text could be translatable by');
     $io->simple('adding a YAML file at "config/translations/LANGUAGE/command.name.yml"');
     /**
      *  By using ContainerAwareCommandTrait on your class for the command
      *  (instead of the more basic CommandTrait), you have access to
      *  the service container.
      *
      *  In other words, you can access to any configured Drupal service
      *  using the provided get method.
      *
      *  $this->get('entity_type.manager');
      *
      *  Reading user input argument
      *  $input->getArgument('ARGUMENT_NAME');
      *
      *  Reading user input option
      *  $input->getOption('OPTION_NAME');
      */
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $settingKeys = array_keys($this->settings->getAll());
     $io->newLine();
     $io->info($this->trans('commands.config.settings.debug.messages.current'));
     $io->newLine();
     foreach ($settingKeys as $settingKey) {
         $io->comment($settingKey, false);
         $io->simple(Yaml::encode($this->settings->get($settingKey)));
     }
     $io->newLine();
 }
コード例 #6
0
 /**
  * Extracts the contents of the archive file into the config directory.
  *
  * @param DrupalStyle $io
  *   IO object to print messages.
  * @param string $archiveFile
  *   The archive file to extract
  * @param string $configDir
  *   The directory to extract the files into.
  *
  * @return \Drupal\Core\Archiver\ArchiveTar
  *   The initialised object.
  *
  * @throws \Exception
  *   If something went wrong during extraction.
  */
 private function extractArchive(DrupalStyle $io, $archiveFile, $configDir)
 {
     $archiveTar = new ArchiveTar($archiveFile, 'gz');
     $io->simple($this->trans('commands.config.import.messages.config_files_imported'));
     foreach ($archiveTar->listContent() as $file) {
         $io->info('[-] ' . $file['filename']);
     }
     try {
         $archiveTar->extract($configDir . '/');
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return;
     }
 }
コード例 #7
0
ファイル: DebugCommand.php プロジェクト: ki3104/DrupalConsole
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $settings = $this->getSettings();
     $settingKeys = array_keys($settings->getAll());
     $dumper = new Dumper();
     $io->newLine();
     $io->info($this->trans('commands.settings.debug.messages.current'));
     $io->newLine();
     foreach ($settingKeys as $settingKey) {
         $io->comment($settingKey, false);
         $io->simple($dumper->dump($settings->get($settingKey), 10));
     }
     $io->newLine();
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $directory = $input->getOption('directory');
     $tar = $input->getOption('tar');
     $archiveTar = new ArchiveTar();
     if (!$directory) {
         $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
     }
     if ($tar) {
         if (!is_dir($directory)) {
             mkdir($directory, 0777, true);
         }
         $dateTime = new \DateTime();
         $archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s'));
         $archiveTar = new ArchiveTar($archiveFile, 'gz');
     }
     try {
         $configManager = $this->getDrupalService('config.manager');
         // Get raw configuration data without overrides.
         foreach ($configManager->getConfigFactory()->listAll() as $name) {
             $configData = $configManager->getConfigFactory()->get($name)->getRawData();
             $configName = sprintf('%s.yml', $name);
             $ymlData = Yaml::encode($configData);
             if ($tar) {
                 $archiveTar->addString($configName, $ymlData);
                 continue;
             }
             $configFileName = sprintf('%s/%s', $directory, $configName);
             $fs = $this->get('filesystem');
             try {
                 $fs->mkdir($directory);
             } catch (IOExceptionInterface $e) {
                 $io->error(sprintf($this->trans('commands.config.export.messages.error'), $e->getPath()));
             }
             file_put_contents($configFileName, $ymlData);
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
     }
     $io->success($this->trans('commands.config.export.messages.directory'));
     $io->simple($directory);
 }
コード例 #9
0
 private function testDetail(DrupalStyle $io, $test_class)
 {
     $testingGroups = $this->getTestDiscovery()->getTestClasses(null);
     $testDetails = null;
     foreach ($testingGroups as $testing_group => $tests) {
         foreach ($tests as $key => $test) {
             if ($test['name'] == $test_class) {
                 $testDetails = $test;
                 break;
             }
         }
         if ($testDetails !== null) {
             break;
         }
     }
     $class = null;
     if ($testDetails) {
         $class = new \ReflectionClass($test['name']);
         if (is_subclass_of($testDetails['name'], 'PHPUnit_Framework_TestCase')) {
             $testDetails['type'] = 'phpunit';
         } else {
             $testDetails = $this->getTestDiscovery()->getTestInfo($testDetails['name']);
             $testDetails['type'] = 'simpletest';
         }
         $io->comment($testDetails['name']);
         $testInfo = [];
         foreach ($testDetails as $key => $value) {
             $testInfo[] = [$key, $value];
         }
         $io->table([], $testInfo);
         if ($class) {
             $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
             $io->info($this->trans('commands.test.debug.messages.methods'));
             foreach ($methods as $method) {
                 if ($method->class == $testDetails['name'] && strpos($method->name, 'test') === 0) {
                     $io->simple($method->name);
                 }
             }
         }
     } else {
         $io->error($this->trans('commands.test.debug.messages.not-found'));
     }
 }
コード例 #10
0
ファイル: RunCommand.php プロジェクト: eleaga/DrupalConsole
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     //Registers namespaces for disabled modules.
     $this->getTestDiscovery()->registerTestNamespaces();
     $testClass = $input->getArgument('test-class');
     $url = $input->getOption('url');
     if (!$url) {
         $io->error($this->trans('commands.test.run.messages.url-required'));
         return;
     }
     $this->setEnvironment($url);
     // Create simpletest test id
     $testId = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute();
     if (is_subclass_of($testClass, 'PHPUnit_Framework_TestCase')) {
         $io->info($this->trans('commands.test.run.messages.phpunit-pending'));
         return;
     } else {
         $test = new $testClass($testId);
         $io->info($this->trans('commands.test.run.messages.starting-test'));
         Timer::start('run-tests');
         $test->run();
         $end = Timer::stop('run-tests');
         $io->simple($this->trans('commands.test.run.messages.test-duration') . ': ' . \Drupal::service('date.formatter')->formatInterval($end['time'] / 1000));
         $io->simple($this->trans('commands.test.run.messages.test-pass') . ': ' . $test->results['#pass']);
         $io->commentBlock($this->trans('commands.test.run.messages.test-fail') . ': ' . $test->results['#fail']);
         $io->commentBlock($this->trans('commands.test.run.messages.test-exception') . ': ' . $test->results['#exception']);
         $io->simple($this->trans('commands.test.run.messages.test-debug') . ': ' . $test->results['#debug']);
         $this->getModuleHandler()->invokeAll('test_finished', array($test->results));
         $io->newLine();
         $io->info($this->trans('commands.test.run.messages.test-summary'));
         $io->newLine();
         $currentClass = null;
         $currentGroup = null;
         $currentStatus = null;
         $messages = $this->simpletestScriptLoadMessagesByTestIds(array($testId));
         foreach ($messages as $message) {
             if ($currentClass === null || $currentClass != $message->test_class) {
                 $currentClass = $message->test_class;
                 $io->comment($message->test_class);
             }
             if ($currentGroup === null || $currentGroup != $message->message_group) {
                 $currentGroup = $message->message_group;
             }
             if ($currentStatus === null || $currentStatus != $message->status) {
                 $currentStatus = $message->status;
                 if ($message->status == 'fail') {
                     $io->error($this->trans('commands.test.run.messages.group') . ':' . $message->message_group . ' ' . $this->trans('commands.test.run.messages.status') . ':' . $message->status);
                     $io->newLine();
                 } else {
                     $io->info($this->trans('commands.test.run.messages.group') . ':' . $message->message_group . ' ' . $this->trans('commands.test.run.messages.status') . ':' . $message->status);
                     $io->newLine();
                 }
             }
             $io->simple($this->trans('commands.test.run.messages.file') . ': ' . str_replace($this->getDrupalHelper()->getRoot(), '', $message->file));
             $io->simple($this->trans('commands.test.run.messages.method') . ': ' . $message->function);
             $io->simple($this->trans('commands.test.run.messages.line') . ': ' . $message->line);
             $io->simple($this->trans('commands.test.run.messages.message') . ': ' . $message->message);
             $io->newLine();
         }
         return;
     }
 }