1 | <?php |
||
17 | class ImportBuilder |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @var ImporterRepository |
||
22 | */ |
||
23 | private $importerRepository; |
||
24 | |||
25 | /** |
||
26 | * @var StorageLocator |
||
27 | */ |
||
28 | private $storageLocator; |
||
29 | |||
30 | /** |
||
31 | * @var EventDispatcherInterface |
||
32 | */ |
||
33 | private $eventDispatcher; |
||
34 | |||
35 | 1 | public function __construct( |
|
36 | ImporterRepository $importerRepository, |
||
37 | StorageLocator $storageLocator, |
||
38 | EventDispatcherInterface $eventDispatcher = null) |
||
39 | { |
||
40 | 1 | $this->importerRepository = $importerRepository; |
|
41 | 1 | $this->storageLocator = $storageLocator; |
|
42 | 1 | $this->eventDispatcher = $eventDispatcher; |
|
43 | 1 | } |
|
44 | |||
45 | /** |
||
46 | * @return null|string |
||
47 | */ |
||
48 | public function findImporterForStorage(StorageInterface $storage) |
||
52 | |||
53 | /** |
||
54 | * @return Import |
||
55 | */ |
||
56 | 1 | public function rebuild(ImportRun $importRun) |
|
57 | { |
||
58 | $importerId = $importRun->getConfiguration()->getImporterId(); |
||
59 | |||
60 | $importer = $this->importerRepository->get($importerId); |
||
61 | if ($importer->getSourceStorage()) { |
||
62 | $sourceStorage = $importer->getSourceStorage(); |
||
63 | 1 | } else { |
|
64 | $sourceStorage = $this->storageLocator->getStorage($importRun->getConfiguration()->getSourceStorageSelection()); |
||
65 | } |
||
66 | |||
67 | return $this->factorImport($importer, $sourceStorage, $importRun); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return Import |
||
72 | * @throws InvalidConfigurationException |
||
73 | */ |
||
74 | 1 | public function buildFromRequest(ImportRequest $importRequest) |
|
105 | |||
106 | /** |
||
107 | * @return Import |
||
108 | * @throws InvalidConfigurationException |
||
109 | */ |
||
110 | 1 | public function build(ImportConfiguration $importConfiguration, StorageInterface $sourceStorage = null, $createdBy = null, $requestContext = null) |
|
111 | { |
||
112 | 1 | $importer = $this->importerRepository->get($importConfiguration->getImporterId()); |
|
113 | 1 | if ($importer->getSourceStorage()) { |
|
114 | $sourceStorage = $importer->getSourceStorage(); |
||
115 | 1 | } elseif (!$sourceStorage) { |
|
116 | throw new InvalidConfigurationException("Either the importRequest or the importer '" . $importConfiguration->getImporterId() . "' must have a source storage set."); |
||
117 | } |
||
118 | |||
119 | 1 | $importRun = $importConfiguration->toRun($createdBy); |
|
120 | |||
121 | //apply static context from importer & request |
||
122 | 1 | $context = $requestContext; |
|
123 | 1 | if (!is_null($importer->getContext()) && !empty($importer->getContext())) { |
|
124 | $importerContext = $importer->getContext(); |
||
125 | if ($importerContext && $requestContext) { |
||
126 | $context = array_merge($importerContext, $requestContext); |
||
127 | } else { |
||
128 | $context = $importerContext; |
||
129 | } |
||
130 | } |
||
131 | 1 | $importRun->setContext($context); |
|
132 | |||
133 | 1 | $import = $this->factorImport($importer, $sourceStorage, $importRun); |
|
134 | |||
135 | //after everthing was build, apply softdata from sourcestorage to importrun |
||
136 | //dont do this any earlier, as there might be AFTER_BUILD hooks, that may change |
||
137 | //the sourcestorage configuration |
||
138 | 1 | $importRun->setInfo((array) $sourceStorage->info()); |
|
139 | |||
140 | 1 | return $import; |
|
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return Import |
||
145 | */ |
||
146 | 1 | private function factorImport(Importer $importer, StorageInterface $sourceStorage, ImportRun $importRun) |
|
163 | |||
164 | } |
||
165 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: