Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.27% covered (warning)
77.27%
17 / 22
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SyncSolvMergePeopleCommand
77.27% covered (warning)
77.27%
17 / 22
66.67% covered (warning)
66.67%
2 / 3
9.95
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%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 mergeSolvPeople
73.68% covered (warning)
73.68%
14 / 19
0.00% covered (danger)
0.00%
0 / 1
7.89
1<?php
2
3namespace Olz\Command;
4
5use Olz\Command\Common\OlzCommand;
6use Olz\Entity\SolvPerson;
7use Olz\Entity\SolvResult;
8use Symfony\Component\Console\Attribute\AsCommand;
9use Symfony\Component\Console\Command\Command;
10use Symfony\Component\Console\Input\InputInterface;
11use Symfony\Component\Console\Output\OutputInterface;
12
13#[AsCommand(name: 'olz:sync-solv-merge-people')]
14class SyncSolvMergePeopleCommand extends OlzCommand {
15    /** @return array<string> */
16    protected function getAllowedAppEnvs(): array {
17        return ['dev', 'test', 'staging', 'prod'];
18    }
19
20    protected function handle(InputInterface $input, OutputInterface $output): int {
21        $this->mergeSolvPeople();
22        return Command::SUCCESS;
23    }
24
25    public function mergeSolvPeople(): void {
26        $solv_person_repo = $this->entityManager()->getRepository(SolvPerson::class);
27        $solv_result_repo = $this->entityManager()->getRepository(SolvResult::class);
28
29        $solv_persons = $solv_person_repo->getSolvPersonsMarkedForMerge();
30        foreach ($solv_persons as $row) {
31            $id = $row['id'];
32            $same_as = $row['same_as'];
33            $this->logAndOutput("Merge person {$id} into {$same_as}.");
34            if (intval($same_as) <= 0) {
35                $this->logAndOutput("Invalid same_as for person {$id}{$same_as}.", level: 'warning');
36            } elseif (!$solv_result_repo->solvPersonHasResults($id)) {
37                $this->logAndOutput("Duplicate person {$id} without any results assigned to merge into person {$same_as}.", level: 'warning');
38            } else {
39                $merge_result = $solv_result_repo->mergePerson($id, $same_as);
40                if (!$merge_result) {
41                    $this->logAndOutput("Merge failed!", level: 'error');
42                }
43            }
44            if (!$solv_result_repo->solvPersonHasResults($id)) {
45                $solv_person_repo->deleteById($id);
46            } elseif ($id == $same_as) {
47                $solv_person_repo->resetSolvPersonSameAs($id);
48            } else {
49                $this->logAndOutput("There are still results assigned to person {$id}.", level: 'warning');
50            }
51        }
52    }
53}