|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HDNET\Importr\Processor; |
|
4
|
|
|
|
|
5
|
|
|
use HDNET\Importr\Domain\Model\Strategy; |
|
6
|
|
|
use HDNET\Importr\Domain\Repository\StrategyRepository; |
|
7
|
|
|
use HDNET\Importr\Exception\ReinitializeException; |
|
8
|
|
|
use HDNET\Importr\Service\ImportServiceInterface; |
|
9
|
|
|
use HDNET\Importr\Service\ManagerInterface; |
|
10
|
|
|
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Configuration |
|
14
|
|
|
*/ |
|
15
|
|
|
class Configuration |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Dispatcher |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $signalSlotDispatcher; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var StrategyRepository |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $strategyRepository; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var ImportServiceInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $importService; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Configuration constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param Dispatcher $signalSlotDispatcher |
|
36
|
|
|
* @param StrategyRepository $strategyRepository |
|
37
|
|
|
* @param ImportServiceInterface $importService |
|
38
|
|
|
*/ |
|
39
|
6 |
|
public function __construct(Dispatcher $signalSlotDispatcher, StrategyRepository $strategyRepository, ImportServiceInterface $importService) |
|
40
|
|
|
{ |
|
41
|
6 |
|
$this->signalSlotDispatcher = $signalSlotDispatcher; |
|
42
|
6 |
|
$this->strategyRepository = $strategyRepository; |
|
43
|
6 |
|
$this->importService = $importService; |
|
44
|
6 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param array $configuration |
|
48
|
|
|
* @param ManagerInterface $manager |
|
49
|
|
|
* @param mixed $filter |
|
50
|
|
|
* |
|
51
|
|
|
* @throws ReinitializeException |
|
52
|
|
|
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException |
|
53
|
|
|
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException |
|
54
|
|
|
*/ |
|
55
|
5 |
|
public function process(array $configuration, ManagerInterface $manager, $filter = null) |
|
56
|
|
|
{ |
|
57
|
5 |
|
if ($filter === null) { |
|
58
|
3 |
|
$this->processInner($configuration, $manager); |
|
59
|
2 |
|
} elseif ($this->canProcess($configuration, $filter)) { |
|
60
|
1 |
|
$this->processInner($configuration[$filter], $manager); |
|
61
|
|
|
} |
|
62
|
4 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param array $configuration |
|
66
|
|
|
* @param string $name |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
3 |
|
public function canProcess(array $configuration, $name) |
|
71
|
|
|
{ |
|
72
|
3 |
|
return isset($configuration[$name]) && is_array($configuration[$name]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param array $configuration |
|
77
|
|
|
* @param ManagerInterface $manager |
|
78
|
|
|
* |
|
79
|
|
|
* @throws ReinitializeException |
|
80
|
|
|
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException |
|
81
|
|
|
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException |
|
82
|
|
|
*/ |
|
83
|
4 |
|
protected function processInner(array $configuration, ManagerInterface $manager) |
|
84
|
|
|
{ |
|
85
|
4 |
|
$this->emitSignal('preParseConfiguration', $configuration); |
|
86
|
|
|
try { |
|
87
|
4 |
|
$this->updateInterval($configuration, $manager) |
|
88
|
4 |
|
->createImport($configuration) |
|
89
|
4 |
|
->reinitializeScheduler($configuration); |
|
90
|
|
|
|
|
91
|
3 |
|
$this->emitSignal('postParseConfiguration', $configuration); |
|
92
|
1 |
|
} catch (ReinitializeException $exception) { |
|
93
|
1 |
|
$this->emitSignal('postParseConfiguration', $configuration); |
|
94
|
1 |
|
throw $exception; |
|
95
|
|
|
} |
|
96
|
3 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param string $name |
|
100
|
|
|
* @param array $configuration |
|
101
|
|
|
* |
|
102
|
|
|
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException |
|
103
|
|
|
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException |
|
104
|
|
|
*/ |
|
105
|
4 |
|
protected function emitSignal($name, array &$configuration) |
|
106
|
|
|
{ |
|
107
|
4 |
|
$this->signalSlotDispatcher->dispatch( |
|
108
|
4 |
|
__CLASS__, |
|
109
|
4 |
|
$name, |
|
110
|
4 |
|
[$this, $configuration] |
|
111
|
|
|
); |
|
112
|
4 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param array $configuration |
|
116
|
|
|
* @param ManagerInterface $manager |
|
117
|
|
|
* @return $this |
|
118
|
|
|
*/ |
|
119
|
4 |
|
protected function updateInterval(array $configuration, ManagerInterface $manager) |
|
120
|
|
|
{ |
|
121
|
4 |
|
if (isset($configuration['updateInterval'])) { |
|
122
|
2 |
|
$manager->setUpdateInterval((int)$configuration['updateInterval']); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
4 |
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param array $configuration |
|
130
|
|
|
* @return $this |
|
131
|
|
|
* @throws ReinitializeException |
|
132
|
|
|
*/ |
|
133
|
4 |
|
protected function reinitializeScheduler(array $configuration) |
|
134
|
|
|
{ |
|
135
|
4 |
|
if (isset($configuration['reinitializeScheduler'])) { |
|
136
|
1 |
|
throw new ReinitializeException(); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
3 |
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param array $configuration |
|
144
|
|
|
* @return $this |
|
145
|
|
|
*/ |
|
146
|
4 |
|
protected function createImport(array $configuration) |
|
147
|
|
|
{ |
|
148
|
4 |
|
if (!isset($configuration['createImport']) && !is_array($configuration['createImport'])) { |
|
149
|
3 |
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
1 |
|
foreach ($configuration['createImport'] as $create) { |
|
153
|
1 |
|
$strategy = $this->strategyRepository->findByUid((int)$create['importId']); |
|
154
|
|
|
|
|
155
|
1 |
|
if ($strategy instanceof Strategy) { |
|
156
|
1 |
|
$filepath = isset($create['filepath']) ? $create['filepath'] : ''; |
|
157
|
1 |
|
$this->importService->addToQueue($filepath, $strategy, $create); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
1 |
|
return $this; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|