1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HDNET\Importr\Processor; |
4
|
|
|
|
5
|
|
|
use HDNET\Importr\Domain\Model\Import; |
6
|
|
|
use HDNET\Importr\Service\ImportServiceInterface; |
7
|
|
|
use HDNET\Importr\Service\Targets\TargetInterface; |
8
|
|
|
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Target |
12
|
|
|
*/ |
13
|
|
|
class Target |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var ImportServiceInterface |
17
|
|
|
*/ |
18
|
|
|
protected $importService; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Dispatcher |
22
|
|
|
*/ |
23
|
|
|
protected $signalSlotDispatcher; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Target constructor. |
27
|
|
|
* |
28
|
|
|
* @param ImportServiceInterface $importService |
29
|
|
|
* @param Dispatcher $signalSlotDispatcher |
30
|
|
|
*/ |
31
|
2 |
|
public function __construct(ImportServiceInterface $importService, Dispatcher $signalSlotDispatcher) |
32
|
|
|
{ |
33
|
2 |
|
$this->importService = $importService; |
34
|
2 |
|
$this->signalSlotDispatcher = $signalSlotDispatcher; |
35
|
2 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param TargetInterface $target |
39
|
|
|
* @param mixed $entry |
40
|
|
|
* @param Import $import |
41
|
|
|
* @param int $pointer |
42
|
|
|
* |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
2 |
|
public function process(TargetInterface $target, $entry, Import $import, $pointer) |
46
|
|
|
{ |
47
|
|
|
try { |
48
|
2 |
|
$entry = $this->emitEntrySignal('preProcess', $target->getConfiguration(), $entry); |
49
|
2 |
|
$result = $target->processEntry($entry); |
50
|
1 |
|
$import->increaseCount($result); |
51
|
1 |
|
} catch (\Exception $e) { |
52
|
1 |
|
$import->increaseCount(TargetInterface::RESULT_ERROR); |
53
|
1 |
|
$this->importService->updateImport($import, $pointer + 1); |
54
|
1 |
|
throw $e; |
55
|
|
|
} |
56
|
1 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $name |
60
|
|
|
* @param array $configuration |
61
|
|
|
* @param mixed $entry |
62
|
|
|
* |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
2 |
|
protected function emitEntrySignal($name, array $configuration, $entry) |
66
|
|
|
{ |
67
|
2 |
|
$result = $this->signalSlotDispatcher->dispatch( |
68
|
2 |
|
__CLASS__, |
69
|
|
|
$name, |
70
|
2 |
|
[$configuration, $entry] |
71
|
|
|
); |
72
|
|
|
|
73
|
2 |
|
return $result[1]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|