Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
31.82% |
7 / 22 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SyncSolvMergePeopleCommand | |
31.82% |
7 / 22 |
|
66.67% |
2 / 3 |
34.67 | |
0.00% |
0 / 1 |
| getAllowedAppEnvs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| mergeSolvPeople | |
21.05% |
4 / 19 |
|
0.00% |
0 / 1 |
31.11 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Command; |
| 4 | |
| 5 | use Olz\Command\Common\OlzCommand; |
| 6 | use Olz\Entity\SolvPerson; |
| 7 | use Olz\Entity\SolvResult; |
| 8 | use Symfony\Component\Console\Attribute\AsCommand; |
| 9 | use Symfony\Component\Console\Command\Command; |
| 10 | use Symfony\Component\Console\Input\InputInterface; |
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
| 12 | |
| 13 | #[AsCommand(name: 'olz:sync-solv-merge-people')] |
| 14 | class 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 | } |