|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package: chapi |
|
4
|
|
|
* |
|
5
|
|
|
* @author: msiebeneicher |
|
6
|
|
|
* @since: 2015-07-31 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Chapi\Commands; |
|
11
|
|
|
|
|
12
|
|
|
use Chapi\BusinessCase\Comparison\JobComparisonInterface; |
|
13
|
|
|
use Chapi\Component\Command\JobUtils; |
|
14
|
|
|
use Chapi\Service\JobIndex\JobIndexServiceInterface; |
|
15
|
|
|
|
|
16
|
|
|
class AddCommand extends AbstractCommand |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Configures the current command. |
|
20
|
|
|
*/ |
|
21
|
2 |
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
2 |
|
$this->setName('add') |
|
24
|
2 |
|
->setDescription('Add job contents to the index') |
|
25
|
|
|
; |
|
26
|
|
|
|
|
27
|
2 |
|
JobUtils::configureJobNamesArgument($this, 'Jobs to add to the index'); |
|
28
|
2 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return int |
|
32
|
|
|
*/ |
|
33
|
2 |
|
protected function process() |
|
34
|
|
|
{ |
|
35
|
2 |
|
$jobNames = JobUtils::getJobNames($this->input, $this); |
|
36
|
2 |
|
$jobsToAdd = (JobUtils::isWildcard($jobNames)) |
|
37
|
1 |
|
? $this->getChangedJobs() |
|
38
|
2 |
|
: $jobNames |
|
39
|
|
|
; |
|
40
|
|
|
|
|
41
|
2 |
|
$this->addJobs($jobsToAdd); |
|
42
|
|
|
|
|
43
|
2 |
|
return 0; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
1 |
|
private function getChangedJobs() |
|
50
|
|
|
{ |
|
51
|
|
|
// job data |
|
52
|
|
|
/** @var JobComparisonInterface $jobComparisonBusinessCase */ |
|
53
|
1 |
|
$jobComparisonBusinessCase = $this->getContainer()->get(JobComparisonInterface::DIC_NAME); |
|
54
|
|
|
|
|
55
|
1 |
|
$newJobs = $jobComparisonBusinessCase->getRemoteMissingJobs(); |
|
56
|
1 |
|
$missingJobs = $jobComparisonBusinessCase->getLocalMissingJobs(); |
|
57
|
1 |
|
$localJobUpdates = $jobComparisonBusinessCase->getLocalJobUpdates(); |
|
58
|
|
|
|
|
59
|
1 |
|
return array_merge($newJobs, $missingJobs, $localJobUpdates); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string[] $jobsToAdd |
|
64
|
|
|
*/ |
|
65
|
2 |
|
private function addJobs($jobsToAdd) |
|
66
|
|
|
{ |
|
67
|
|
|
/** @var JobIndexServiceInterface $jobIndexService */ |
|
68
|
2 |
|
$jobIndexService = $this->getContainer()->get(JobIndexServiceInterface::DIC_NAME); |
|
69
|
2 |
|
$jobIndexService->addJobs($jobsToAdd); |
|
70
|
2 |
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|