Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var InputExtendedInterface $input */
     $this->outputStartMessage($output);
     // If we enable the "setup-database-tables" setting, we will check if the necessary tables
     // are already there. If not we will try to setup / create them.
     // Try, because this process can fail due to missing access rights of the database user.
     // If the user got the needed rights, everything will work fine ;)
     if ($input->getOption('setup-database-tables') === true) {
         $databaseService = new DatabaseService($this->database, $output);
         $databaseService->setupDatabaseTables();
     }
     // Start the importer for each configured project
     $gerritSystems = $this->configuration->getConfigurationValue('Gerrit');
     $defaultSSHKeyFile = $this->configuration->getConfigurationValue('SSH.KeyFile');
     foreach ($gerritSystems as $name => $gerrieProject) {
         $gerritSystem = ['Name' => $name];
         foreach ($gerrieProject as $gerritInstance) {
             // TODO Extract this Instance Key part here. This is the same as in "ListProjectsCommand".
             // Get instance url
             // If the instance is a string, we only got a url path like scheme://user@url:port/
             if (is_string($gerritInstance)) {
                 $instanceConfig = ['Instance' => $gerritInstance, 'KeyFile' => $defaultSSHKeyFile];
                 // If the instance is an array, we get a key => value structure with an Instance key
             } elseif (is_array($gerritInstance) && isset($gerritInstance['Instance'])) {
                 $instanceConfig = ['Instance' => $gerritInstance['Instance'], 'KeyFile' => $defaultSSHKeyFile];
                 if (array_key_exists('KeyFile', $gerritInstance) === true) {
                     $instanceConfig['KeyFile'] = $gerritInstance['KeyFile'];
                 }
             } else {
                 throw new \RuntimeException('No Gerrit instance config given', 1415451921);
             }
             $dataService = DataServiceFactory::getDataService($instanceConfig);
             // Bootstrap the importer
             $gerrie = new Gerrie($this->database, $dataService, $gerritSystem);
             $gerrie->setOutput($output);
             if ($input->getOption('debug') === true) {
                 $gerrie->enableDebugFunctionality();
             } else {
                 $gerrie->disableDebugFunctionality();
             }
             // Start the crawling action
             $gerrie->crawl();
         }
     }
     $this->outputEndMessage($output);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var InputExtendedInterface $input */
     // Start the importer for each configured project
     $gerritSystems = $this->configuration->getConfigurationValue('Gerrit');
     $defaultSSHKeyFile = $this->configuration->getConfigurationValue('SSH.KeyFile');
     $i = 0;
     foreach ($gerritSystems as $name => $gerrieProject) {
         foreach ($gerrieProject as $gerritInstance) {
             $path = parse_url($gerritInstance);
             // TODO Extract this Instance Key part here. This is the same as in "CrawlCommand".
             // Get instance url
             // If the instance is a string, we only got a url path like scheme://user@url:port/
             if (is_string($gerritInstance)) {
                 $instanceConfig = ['Instance' => $gerritInstance, 'KeyFile' => $defaultSSHKeyFile];
                 // If the instance is an array, we get a key => value structure with an Instance key
             } elseif (is_array($gerritInstance) && isset($gerritInstance['Instance'])) {
                 $instanceConfig = ['Instance' => $gerritInstance['Instance'], 'KeyFile' => $defaultSSHKeyFile];
                 if (array_key_exists('KeyFile', $gerritInstance) === true) {
                     $instanceConfig['KeyFile'] = $gerritInstance['KeyFile'];
                 }
             } else {
                 throw new \RuntimeException('No Gerrit instance config given', 1415451921);
             }
             $dataService = DataServiceFactory::getDataService($instanceConfig);
             $projects = $dataService->getProjects();
             if (is_array($projects) === false) {
                 throw new \Exception('No projects found on "' . $path['host'] . '"!', 1363894633);
             }
             if ($i >= 1) {
                 $output->writeln('');
             }
             $headline = '<comment>Instance: %s (via %s)</comment>';
             $headline = sprintf($headline, $path['host'], $dataService->getName());
             $output->writeln($headline);
             $output->writeln('<comment>' . str_repeat('=', 40) . '</comment>');
             foreach ($projects as $name => $project) {
                 $message = '<info>%s</info>';
                 $message = sprintf($message, $name);
                 $output->writeln($message);
             }
             $i++;
         }
     }
 }
 /**
  * Merges the command line options into a existing configuration.
  *
  * E.g.
  *  * Database credentials
  *  * SSH settings
  *
  * @param Configuration $config
  * @param InputExtendedInterface $input
  * @return Configuration
  */
 protected static function mergeCommandOptionsIntoConfiguration(Configuration $config, InputExtendedInterface $input)
 {
     $configurationMapping = ['database-host' => 'Database.Host', 'database-user' => 'Database.Username', 'database-pass' => 'Database.Password', 'database-port' => 'Database.Port', 'database-name' => 'Database.Name', 'ssh-key' => 'SSH.KeyFile'];
     foreach ($configurationMapping as $optionName => $configName) {
         if ($input->isOptionSet($optionName) === true) {
             $config->setConfigurationValue($configName, $input->getOption($optionName));
             // If the value is not set / available, set this to nothing
         } elseif (!$config->getConfigurationValue($configName)) {
             $config->setConfigurationValue($configName, null);
         }
     }
     return $config;
 }
Example #4
0
 public function testSetConfigurationValueWithEmptyConfiguration()
 {
     $this->assertEquals('', $this->configuration->getConfigurationValue('Foo'));
     $this->assertEquals('', $this->configuration->getConfigurationValue('Foo.Bar.Baz'));
     $this->assertEquals('', $this->configuration->getConfigurationValue('Foo.Gerrie'));
     $this->assertEquals('', $this->configuration->getConfigurationValue('Awesome.Application.YOLO'));
     $this->configuration->setConfigurationValue('Foo', 'Bar');
     $this->assertEquals('Bar', $this->configuration->getConfigurationValue('Foo'));
     $this->configuration->setConfigurationValue('Foo', 'Weekend');
     $this->assertEquals('Weekend', $this->configuration->getConfigurationValue('Foo'));
     $this->configuration->setConfigurationValue('Foo.Bar', 'Baz');
     $this->configuration->setConfigurationValue('Foo.Bar.Baz', 'Hello');
     $this->configuration->setConfigurationValue('Foo.Gerrie', 'World');
     $this->configuration->setConfigurationValue('Awesome.Application.YOLO', 'Google Google Google');
     $this->assertEquals(['Baz' => 'Hello'], $this->configuration->getConfigurationValue('Foo.Bar'));
     $this->assertEquals('Hello', $this->configuration->getConfigurationValue('Foo.Bar.Baz'));
     $this->assertEquals('World', $this->configuration->getConfigurationValue('Foo.Gerrie'));
     $this->assertEquals('Google Google Google', $this->configuration->getConfigurationValue('Awesome.Application.YOLO'));
 }