2015-11-03 21:42:47 +01:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Command;
|
2015-11-03 21:42:47 +01:00
|
|
|
|
2018-03-04 08:30:34 +01:00
|
|
|
use PHPCensor\Store\Factory;
|
2015-11-03 21:42:47 +01:00
|
|
|
use Monolog\Logger;
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor\BuildFactory;
|
|
|
|
use PHPCensor\Logging\OutputLogHandler;
|
|
|
|
use PHPCensor\Service\BuildService;
|
2015-11-03 21:42:47 +01:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
2017-02-05 05:18:33 +01:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
2017-01-20 15:55:48 +01:00
|
|
|
*/
|
2015-11-03 21:42:47 +01:00
|
|
|
class RebuildQueueCommand extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var OutputInterface
|
|
|
|
*/
|
|
|
|
protected $output;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Logger
|
|
|
|
*/
|
|
|
|
protected $logger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \Monolog\Logger $logger
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public function __construct(Logger $logger, $name = null)
|
|
|
|
{
|
|
|
|
parent::__construct($name);
|
|
|
|
$this->logger = $logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
2016-07-21 19:02:11 +02:00
|
|
|
->setName('php-censor:rebuild-queue')
|
2016-07-19 13:05:02 +02:00
|
|
|
->setDescription('Rebuilds the PHP Censor worker queue.');
|
2015-11-03 21:42:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$this->output = $output;
|
|
|
|
|
|
|
|
// For verbose mode we want to output all informational and above
|
|
|
|
// messages to the symphony output interface.
|
|
|
|
if ($input->hasOption('verbose') && $input->getOption('verbose')) {
|
|
|
|
$this->logger->pushHandler(
|
|
|
|
new OutputLogHandler($this->output, Logger::INFO)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$store = Factory::getStore('Build');
|
|
|
|
$result = $store->getByStatus(0);
|
|
|
|
|
2017-02-05 05:18:33 +01:00
|
|
|
$this->logger->addInfo(sprintf('Found %d builds', count($result['items'])));
|
2015-11-03 21:42:47 +01:00
|
|
|
|
|
|
|
$buildService = new BuildService($store);
|
|
|
|
|
|
|
|
while (count($result['items'])) {
|
|
|
|
$build = array_shift($result['items']);
|
|
|
|
$build = BuildFactory::getBuild($build);
|
|
|
|
|
|
|
|
$this->logger->addInfo('Added build #' . $build->getId() . ' to queue.');
|
|
|
|
$buildService->addBuildToQueue($build);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|