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++;
         }
     }
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var InputExtendedInterface $input */
     /**
      * Welcome message
      */
     // Run gerrie:create-database-Command
     $output->writeln('<info>Gerrie will check if the current setup will work as expected.</info>');
     $output->writeln('<info>Lets start!</info>');
     /**
      * Start checking
      */
     $output->writeln('');
     $output->writeln('<comment>System:</comment>');
     // Check if curl is installed
     $curlCheck = new CurlExtensionCheck();
     $this->checkProperty($output, $curlCheck);
     // Check if PDO and MySQL are installed
     $pdoCheck = new PDOMySqlExtensionCheck();
     $this->checkProperty($output, $pdoCheck);
     // Check if SSH is installed
     $sshCheck = new SSHCheck();
     $this->checkProperty($output, $sshCheck);
     $output->writeln('');
     $output->writeln('<comment>Configuration:</comment>');
     // Check if the config file exists
     $configFileCheck = new ConfigFileCheck($input->getOption('config-file'));
     $this->checkProperty($output, $configFileCheck);
     // Check if the config file is valid
     $configFile = $input->getOption('config-file');
     $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $input);
     $configurationValidationCheck = new ConfigurationValidationCheck($configuration);
     $this->checkProperty($output, $configurationValidationCheck);
     $output->writeln('');
     $output->writeln('<comment>Connection:</comment>');
     // Check database connection
     $databaseConfig = $configuration->getConfigurationValue('Database');
     $database = new Database($databaseConfig, false);
     $databaseConnectionCheck = new DatabaseConnectionCheck($database);
     $this->checkProperty($output, $databaseConnectionCheck);
     // TODO Refactor this. This is copy / paste from CrawlCommand
     $gerritSystems = $configuration->getConfigurationValue('Gerrit');
     $defaultSSHKeyFile = $configuration->getConfigurationValue('SSH.KeyFile');
     foreach ($gerritSystems as $name => $gerrieProject) {
         foreach ($gerrieProject as $gerritInstance) {
             // 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);
             // Check the API (SSH / HTTP) connection
             // TODO Authentification
             $apiConnectionCheck = new APIConnectionCheck($dataService);
             $this->checkProperty($output, $apiConnectionCheck);
         }
     }
     /**
      * Message end result
      */
     if ($this->overallResult === false) {
         $this->outputFixMessage($output);
     } else {
         $this->outputEverythingIsFineAndIWantABeerMessage($output);
     }
 }
 public function testGetHTTPSDataService()
 {
     $instanceConfig = ['Instance' => 'https://andy.grunwald:pass@review.typo3.org:80/'];
     $httpDataService = DataServiceFactory::getDataService($instanceConfig);
     $this->assertInstanceOf('Gerrie\\API\\DataService\\HTTPDataService', $httpDataService);
 }
Example #4
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);
 }