|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Maba\DatabaseInconsistencyFinder; |
|
5
|
|
|
|
|
6
|
|
|
use Maba\DatabaseInconsistencyFinder\Database\QueryExecutor; |
|
7
|
|
|
use Maba\DatabaseInconsistencyFinder\Entity\InconsistenciesResult; |
|
8
|
|
|
use Maba\DatabaseInconsistencyFinder\Entity\ReferencesConfiguration; |
|
9
|
|
|
use Maba\DatabaseInconsistencyFinder\JobDistribution\JobDistributorFactoryInterface; |
|
10
|
|
|
use Maba\DatabaseInconsistencyFinder\Service\IntervalManager; |
|
11
|
|
|
|
|
12
|
|
|
class InconsistencyFinder |
|
13
|
|
|
{ |
|
14
|
|
|
private $referencesConfiguration; |
|
15
|
|
|
private $queryExecutor; |
|
16
|
|
|
private $intervalManager; |
|
17
|
|
|
private $jobDistributorFactory; |
|
18
|
|
|
|
|
19
|
4 |
|
public function __construct( |
|
20
|
|
|
ReferencesConfiguration $referencesConfiguration, |
|
21
|
|
|
QueryExecutor $queryExecutor, |
|
22
|
|
|
IntervalManager $intervalManager, |
|
23
|
|
|
JobDistributorFactoryInterface $jobDistributorFactory |
|
24
|
|
|
) { |
|
25
|
4 |
|
$this->referencesConfiguration = $referencesConfiguration; |
|
26
|
4 |
|
$this->queryExecutor = $queryExecutor; |
|
27
|
4 |
|
$this->intervalManager = $intervalManager; |
|
28
|
4 |
|
$this->jobDistributorFactory = $jobDistributorFactory; |
|
29
|
4 |
|
} |
|
30
|
|
|
|
|
31
|
4 |
|
public function find(): InconsistenciesResult |
|
32
|
|
|
{ |
|
33
|
4 |
|
$jobDistributor = $this->jobDistributorFactory->createJobDistributorForIteration(); |
|
34
|
4 |
|
$idRange = $this->queryExecutor->getIdRange($this->referencesConfiguration->getReferencedColumn()); |
|
35
|
|
|
|
|
36
|
4 |
|
foreach ($this->intervalManager->divideForJobDistribution($idRange) as $interval) { |
|
37
|
4 |
|
$jobDistributor->perform($interval); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
4 |
|
return $jobDistributor->collectResults(); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|