Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
SyncSolvCommand | |
0.00% |
0 / 47 |
|
0.00% |
0 / 7 |
156 | |
0.00% |
0 / 1 |
getAllowedAppEnvs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handle | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
syncSolvEvents | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
syncSolvEventForYear | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
syncSolvResults | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
assignSolvPeople | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
mergeSolvPeople | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Olz\Command; |
4 | |
5 | use Olz\Command\Common\OlzCommand; |
6 | use Symfony\Component\Console\Attribute\AsCommand; |
7 | use Symfony\Component\Console\Command\Command; |
8 | use Symfony\Component\Console\Input\ArrayInput; |
9 | use Symfony\Component\Console\Input\InputInterface; |
10 | use Symfony\Component\Console\Output\OutputInterface; |
11 | |
12 | #[AsCommand(name: 'olz:sync-solv')] |
13 | class SyncSolvCommand extends OlzCommand { |
14 | /** @return array<string> */ |
15 | protected function getAllowedAppEnvs(): array { |
16 | return ['dev', 'test', 'staging', 'prod']; |
17 | } |
18 | |
19 | protected function handle(InputInterface $input, OutputInterface $output): int { |
20 | $this->syncSolvEvents(); |
21 | $this->syncSolvResults(); |
22 | $this->assignSolvPeople(); |
23 | $this->mergeSolvPeople(); |
24 | return Command::SUCCESS; |
25 | } |
26 | |
27 | private function syncSolvEvents(): void { |
28 | $current_year = intval($this->dateUtils()->getCurrentDateInFormat('Y')); |
29 | $current_day = intval($this->dateUtils()->getCurrentDateInFormat('d')); |
30 | $this->syncSolvEventForYear($current_year); |
31 | if ($current_day !== 1) { // Only do the following once a month. |
32 | return; |
33 | } |
34 | $this->syncSolvEventForYear($current_year - 1); |
35 | $this->syncSolvEventForYear($current_year + 1); |
36 | $this->syncSolvEventForYear($current_year - 2); |
37 | } |
38 | |
39 | private function syncSolvEventForYear(int $year): void { |
40 | try { |
41 | $this->generalUtils()->checkNotNull($this->output, "No output"); |
42 | $this->symfonyUtils()->callCommand( |
43 | 'olz:sync-solv-events', |
44 | new ArrayInput(['year' => strval($year)]), |
45 | $this->output, |
46 | ); |
47 | } catch (\Throwable $th) { |
48 | $this->logAndOutput("olz:sync-solv-events({$year}) failed.", [$th], level: 'warning'); |
49 | } |
50 | } |
51 | |
52 | private function syncSolvResults(): void { |
53 | $current_year = intval($this->dateUtils()->getCurrentDateInFormat('Y')); |
54 | try { |
55 | $this->generalUtils()->checkNotNull($this->output, "No output"); |
56 | $this->symfonyUtils()->callCommand( |
57 | 'olz:sync-solv-results', |
58 | new ArrayInput(['year' => strval($current_year)]), |
59 | $this->output, |
60 | ); |
61 | } catch (\Throwable $th) { |
62 | $this->logAndOutput("olz:sync-solv-results({$current_year}) failed. {$th}", [$th], level: 'warning'); |
63 | } |
64 | } |
65 | |
66 | private function assignSolvPeople(): void { |
67 | try { |
68 | $this->generalUtils()->checkNotNull($this->output, "No output"); |
69 | $this->symfonyUtils()->callCommand( |
70 | 'olz:sync-solv-assign-people', |
71 | new ArrayInput([]), |
72 | $this->output, |
73 | ); |
74 | } catch (\Throwable $th) { |
75 | $this->logAndOutput("olz:sync-solv-assign-people() failed.", [$th], level: 'warning'); |
76 | } |
77 | } |
78 | |
79 | private function mergeSolvPeople(): void { |
80 | try { |
81 | $this->generalUtils()->checkNotNull($this->output, "No output"); |
82 | $this->symfonyUtils()->callCommand( |
83 | 'olz:sync-solv-merge-people', |
84 | new ArrayInput([]), |
85 | $this->output, |
86 | ); |
87 | } catch (\Throwable $th) { |
88 | $this->logAndOutput("olz:sync-solv-merge-people() failed.", [$th], level: 'warning'); |
89 | } |
90 | } |
91 | } |