|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oliverde8\PhpEtlBundle\Etl\OperationFactory\Cleanup; |
|
4
|
|
|
|
|
5
|
|
|
use Oliverde8\Component\PhpEtl\Builder\Factories\AbstractFactory; |
|
6
|
|
|
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface; |
|
7
|
|
|
use Oliverde8\PhpEtlBundle\Etl\Operation\Cleanup\FindOldExecutionsOperation; |
|
8
|
|
|
use Oliverde8\PhpEtlBundle\Repository\EtlExecutionRepository; |
|
9
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
10
|
|
|
|
|
11
|
|
|
class FindOldExecutionsFactory extends AbstractFactory |
|
12
|
|
|
{ |
|
13
|
|
|
protected EtlExecutionRepository $etlExecutionRepository; |
|
14
|
|
|
|
|
15
|
|
|
protected string $minKeep; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* FindOldExecutionsFactory constructor. |
|
19
|
|
|
* @param EtlExecutionRepository $etlExecutionRepository |
|
20
|
|
|
* @param string $minKeep |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct(EtlExecutionRepository $etlExecutionRepository, string $minKeep) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->etlExecutionRepository = $etlExecutionRepository; |
|
25
|
|
|
$this->minKeep = $minKeep; |
|
26
|
|
|
|
|
27
|
|
|
$this->operation = 'Etl/Cleanup/FindOldExecutions'; |
|
28
|
|
|
$this->class = FindOldExecutionsOperation::class; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Build an operation of a certain type with the options. |
|
34
|
|
|
* |
|
35
|
|
|
* @param String $operation |
|
36
|
|
|
* @param array $options |
|
37
|
|
|
* |
|
38
|
|
|
* @return ChainOperationInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function build($operation, $options) |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->create($this->etlExecutionRepository, $this->getKeepDate($options)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Configure validation. |
|
48
|
|
|
* |
|
49
|
|
|
* @return Constraint |
|
|
|
|
|
|
50
|
|
|
*/ |
|
51
|
|
|
protected function configureValidator() |
|
52
|
|
|
{ |
|
53
|
|
|
return new Assert\Collection([ |
|
|
|
|
|
|
54
|
|
|
'keep' => new Assert\Type(["type" => "string"]) |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function getKeepDate(array $options): \DateTime |
|
59
|
|
|
{ |
|
60
|
|
|
$keepDate = $options['keep'] ?? $this->minKeep; |
|
61
|
|
|
|
|
62
|
|
|
$wantedKeepDate = strtotime("- " . $keepDate); |
|
63
|
|
|
$minKeepDate = strtotime("- " . $this->minKeep); |
|
64
|
|
|
|
|
65
|
|
|
if ($wantedKeepDate > $minKeepDate) { |
|
66
|
|
|
throw new \Exception("You can't delete orders from $keepDate ago, the minimum keep is " . $this->minKeep); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return (new \DateTime())->setTimestamp($wantedKeepDate); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths