Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
82.98% covered (warning)
82.98%
39 / 47
42.86% covered (danger)
42.86%
3 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
SyncSolvCommand
82.98% covered (warning)
82.98%
39 / 47
42.86% covered (danger)
42.86%
3 / 7
12.71
0.00% covered (danger)
0.00%
0 / 1
 getAllowedAppEnvs
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 syncSolvEvents
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
 syncSolvEventForYear
75.00% covered (warning)
75.00%
6 / 8
0.00% covered (danger)
0.00%
0 / 1
2.06
 syncSolvResults
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
2.04
 assignSolvPeople
75.00% covered (warning)
75.00%
6 / 8
0.00% covered (danger)
0.00%
0 / 1
2.06
 mergeSolvPeople
75.00% covered (warning)
75.00%
6 / 8
0.00% covered (danger)
0.00%
0 / 1
2.06
1<?php
2
3namespace Olz\Command;
4
5use Olz\Command\Common\OlzCommand;
6use Symfony\Component\Console\Attribute\AsCommand;
7use Symfony\Component\Console\Command\Command;
8use Symfony\Component\Console\Input\ArrayInput;
9use Symfony\Component\Console\Input\InputInterface;
10use Symfony\Component\Console\Output\OutputInterface;
11
12#[AsCommand(name: 'olz:sync-solv')]
13class 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}