|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCI - Continuous Integration for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright 2015, Block 8 Limited. |
|
6
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://www.phptesting.org/ |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace PHPCI\Command; |
|
12
|
|
|
|
|
13
|
|
|
use b8\Store\Factory; |
|
14
|
|
|
use Monolog\Logger; |
|
15
|
|
|
use PHPCI\BuildFactory; |
|
16
|
|
|
use PHPCI\Helper\Lang; |
|
17
|
|
|
use PHPCI\Logging\OutputLogHandler; |
|
18
|
|
|
use PHPCI\Service\BuildService; |
|
19
|
|
|
use Symfony\Component\Console\Command\Command; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Dan Cryer <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class RebuildQueueCommand extends Command |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var OutputInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $output; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var Logger |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $logger; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param \Monolog\Logger $logger |
|
40
|
|
|
* @param string $name |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(Logger $logger, $name = null) |
|
43
|
|
|
{ |
|
44
|
|
|
parent::__construct($name); |
|
45
|
|
|
$this->logger = $logger; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function configure() |
|
49
|
|
|
{ |
|
50
|
|
|
$this |
|
51
|
|
|
->setName('phpci:rebuild-queue') |
|
52
|
|
|
->setDescription('Rebuilds the PHPCI worker queue.'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->output = $output; |
|
58
|
|
|
|
|
59
|
|
|
// For verbose mode we want to output all informational and above |
|
60
|
|
|
// messages to the symphony output interface. |
|
61
|
|
|
if ($input->hasOption('verbose') && $input->getOption('verbose')) { |
|
62
|
|
|
$this->logger->pushHandler( |
|
63
|
|
|
new OutputLogHandler($this->output, Logger::INFO) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$store = Factory::getStore('Build'); |
|
68
|
|
|
$result = $store->getByStatus(0); |
|
69
|
|
|
|
|
70
|
|
|
$this->logger->addInfo(Lang::get('found_n_builds', count($result['items']))); |
|
71
|
|
|
|
|
72
|
|
|
$buildService = new BuildService($store); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
while (count($result['items'])) { |
|
75
|
|
|
$build = array_shift($result['items']); |
|
76
|
|
|
$build = BuildFactory::getBuild($build); |
|
77
|
|
|
|
|
78
|
|
|
$this->logger->addInfo('Added build #'.$build->getId().' to queue.'); |
|
79
|
|
|
$buildService->addBuildToQueue($build); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.