* cli command support added

* nightly cache update cli command implemented
This commit is contained in:
Dávid Danyi 2017-03-30 12:37:51 +02:00
parent 6e823bc0ea
commit 68e66ddedf
7 changed files with 87 additions and 4 deletions

17
bin/cli Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/php
<?php
require __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\Console\Application;
/** @var \Interop\Container\ContainerInterface $container */
$container = require __DIR__ . '/../config/container.php';
$application = new Application('Application console');
$commands = $container->get('config')['console']['commands'];
foreach ($commands as $command) {
$application->add($container->get($command));
}
$application->run();

View File

@ -19,7 +19,8 @@
"los/basepath": "^1.0",
"zendframework/zend-http": "^2.6",
"symfony/css-selector": "^3.2",
"zendframework/zend-cache": "^2.7"
"zendframework/zend-cache": "^2.7",
"symfony/console": "^3.2"
},
"require-dev": {
"phpunit/phpunit": "^4.8",

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "1823e15d3da7740350f42c474e6e640e",
"content-hash": "b68abdbc94f3cc9c9ca4ed861cb59a9f",
"packages": [
{
"name": "container-interop/container-interop",

View File

@ -0,0 +1,15 @@
<?php
return [
'dependencies' => [
'invokables' => [],
'factories' => [
App\Command\UpdateNightlyCacheCommand::class => App\Command\UpdateNightlyCacheCommandFactory::class,
],
],
'console' => [
'commands' => [
App\Command\UpdateNightlyCacheCommand::class,
],
],
];

View File

@ -0,0 +1,33 @@
<?php
namespace App\Command;
use App\Service\CiExecutorService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UpdateNightlyCacheCommand extends Command
{
/**
* @var CiExecutorService
*/
private $ciExecutorService;
public function __construct(CiExecutorService $ciExecutorService)
{
$this->ciExecutorService = $ciExecutorService;
parent::__construct();
}
protected function configure()
{
$this->setName('nightly:update')
->setDescription('Updates nightly configuration cache');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->ciExecutorService->getActiveNightlyConfiguration(true);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Command;
use App\Service\CiExecutorService;
use Interop\Container\ContainerInterface;
class UpdateNightlyCacheCommandFactory
{
public function __invoke(ContainerInterface $container)
{
/** @var CiExecutorService $ciExecutorService */
$ciExecutorService = $container->get(CiExecutorService::class);
return new UpdateNightlyCacheCommand($ciExecutorService);
}
}

View File

@ -90,7 +90,6 @@ class CiExecutorService
$config2Html = $this->getConfig2Html();
$staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE");
return $this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']);
// return $this->getJcatVersions($config2Html);
}
$cache = $this->getCache(self::JCAT_CACHE_KEY);
@ -99,7 +98,6 @@ class CiExecutorService
$config2Html = $this->getConfig2Html();
$staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE");
$packages =$this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']);
// $packages =$this->getJcatVersions($config2Html);
$cache->setItem(self::PACKAGE_CACHE_KEY, serialize($packages));
} else {
$packages = unserialize($result);
@ -759,8 +757,11 @@ class CiExecutorService
$cssToXpathConverter = new CssSelectorConverter();
$xpathQuery = $cssToXpathConverter->toXPath(sprintf('input[value=%s]', $fieldName));
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
$domDocument = new \DOMDocument();
$domDocument->loadHTML($html);
libxml_clear_errors();
libxml_use_internal_errors($xmlErrorHandling);
$xpath = new \DOMXPath($domDocument);
$element = $xpath->query($xpathQuery);