1 | <?php |
||
17 | abstract class AbstractStoreJobBusinessCase implements StoreJobBusinessCaseInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var JobIndexServiceInterface |
||
21 | */ |
||
22 | protected $jobIndexService; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * @var JobComparisonInterface |
||
27 | */ |
||
28 | protected $jobComparisonBusinessCase; |
||
29 | |||
30 | /** |
||
31 | * @var LoggerInterface |
||
32 | */ |
||
33 | protected $logger; |
||
34 | |||
35 | /** |
||
36 | * @var JobRepositoryInterface |
||
37 | */ |
||
38 | protected $jobRepositoryRemote; |
||
39 | |||
40 | /** |
||
41 | * @var JobRepositoryInterface |
||
42 | */ |
||
43 | protected $jobRepositoryLocal; |
||
44 | |||
45 | /** |
||
46 | * @inheritdoc |
||
47 | */ |
||
48 | 7 | public function storeJobsToLocalRepository(array $entityNames = [], $forceOverwrite = false) |
|
71 | |||
72 | 3 | protected function addJobInLocalRepository(JobEntityInterface $appRemote) |
|
86 | |||
87 | |||
88 | 7 | protected function updateJobInLocalRepository(JobEntityInterface $appRemote, $forceOverwrite) |
|
89 | { |
||
90 | 7 | $diff = $this->jobComparisonBusinessCase->getJobDiff($appRemote->getKey()); |
|
91 | 7 | if (!empty($diff)) { |
|
92 | 5 | if (!$forceOverwrite) { |
|
93 | 2 | throw new \InvalidArgumentException( |
|
94 | 2 | sprintf( |
|
95 | 2 | 'The entity "%s" already exist in your local repository. Use the "force" option to overwrite the job', |
|
96 | 2 | $appRemote->getKey() |
|
97 | ) |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | 3 | if ($this->jobRepositoryLocal->updateJob($appRemote)) { |
|
102 | 2 | $this->logger->notice(sprintf( |
|
103 | 2 | 'Entity %s is updated in local repository', |
|
104 | 2 | $appRemote->getKey() |
|
105 | )); |
||
106 | } else { |
||
107 | 1 | $this->logger->error(sprintf( |
|
108 | 1 | 'Failed to update app %s in local repository', |
|
109 | 1 | $appRemote->getKey() |
|
110 | )); |
||
111 | } |
||
112 | |||
113 | // remove job from index in case off added in the past |
||
114 | 3 | $this->jobIndexService->removeJob($appRemote->getKey()); |
|
115 | } |
||
116 | 6 | } |
|
117 | |||
118 | /** |
||
119 | * @inheritdoc |
||
120 | */ |
||
121 | public function isJobAvailable($jobName) |
||
127 | |||
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | abstract public function storeIndexedJobs(); |
||
133 | } |
||
134 |