1 | <?php |
||
15 | class Import |
||
16 | { |
||
17 | /** |
||
18 | * @var EntityManagerInterface |
||
19 | */ |
||
20 | private $entityManager; |
||
21 | |||
22 | /** |
||
23 | * @var TransformerFactory |
||
24 | */ |
||
25 | private $transformerFactory; |
||
26 | |||
27 | /** |
||
28 | * @var SchemaDefinitionGroupByEntity |
||
29 | */ |
||
30 | private $schemaDefintionToSchemaGroupByEntityConverter; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $schemaDefinition; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $schemaDefintiontGroupByEntity; |
||
41 | |||
42 | /** |
||
43 | * @var GetDataFromCsvFile |
||
44 | */ |
||
45 | private $dataGetterFromCsv; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $data; |
||
51 | |||
52 | /** |
||
53 | * @var int |
||
54 | */ |
||
55 | private $dataSize; |
||
56 | |||
57 | /** |
||
58 | * @var ProgressBar |
||
59 | */ |
||
60 | private $progressBar; |
||
61 | |||
62 | /** |
||
63 | * @var PropertyAccessorInterface |
||
64 | */ |
||
65 | private $propertyAccessor; |
||
66 | |||
67 | /** |
||
68 | * @param EntityManagerInterface $entityManager |
||
69 | * @param SchemaDefinitionGroupByEntity $schemaDefintionToSchemaGroupByEntity |
||
70 | * @param GetDataFromCsvFile $dataGetterFromCsv |
||
71 | * @param TransformerFactory $transformerFactory |
||
72 | */ |
||
73 | public function __construct(EntityManagerInterface $entityManager, SchemaDefinitionGroupByEntity $schemaDefintionToSchemaGroupByEntity, GetDataFromCsvFile $dataGetterFromCsv, TransformerFactory $transformerFactory) |
||
81 | |||
82 | /** |
||
83 | * @param string $fileName |
||
84 | * @param string $delimiter |
||
85 | * |
||
86 | * @return Import |
||
87 | */ |
||
88 | protected function setData(string $fileName, string $delimiter) |
||
95 | |||
96 | /** |
||
97 | * @param array $schemaDefinition |
||
98 | * |
||
99 | * @return Import |
||
100 | */ |
||
101 | protected function setSchemaDefinition(array $schemaDefinition) |
||
108 | |||
109 | /** |
||
110 | * @param array $schemaDefinition |
||
111 | * @param string $fileName |
||
112 | * @param OutputInterface $output |
||
113 | */ |
||
114 | public function import(array $schemaDefinition, string $fileName, OutputInterface $output) |
||
133 | |||
134 | /** |
||
135 | * @param array $entities |
||
136 | * |
||
137 | * @return mixed |
||
138 | */ |
||
139 | protected function linkEntities(array $entities) |
||
150 | |||
151 | /** |
||
152 | * @param mixed $entity |
||
153 | * @param int $advance |
||
154 | * |
||
155 | * @return Import |
||
156 | */ |
||
157 | protected function persistEntities($entity, int $advance) |
||
167 | |||
168 | /** |
||
169 | * @param array $fields |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | protected function buildEntities(array $fields) |
||
183 | |||
184 | /** |
||
185 | * @param array $values |
||
186 | * @param mixed $entity |
||
187 | * |
||
188 | * @return mixed |
||
189 | */ |
||
190 | protected function setEntityFields(array $values, $entity) |
||
198 | |||
199 | /** |
||
200 | * @param array $line |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | protected function groupFieldsByEntity(array $line) |
||
219 | |||
220 | /** |
||
221 | * @param array $config |
||
222 | * @param string $value |
||
223 | * |
||
224 | * @return mixed |
||
225 | */ |
||
226 | protected function getCellValue(array $config, string $value) |
||
239 | |||
240 | /** |
||
241 | * @param string $transformerName |
||
242 | * |
||
243 | * @return TransformerInterface |
||
244 | */ |
||
245 | protected function getTransformer(string $transformerName) |
||
253 | |||
254 | /** |
||
255 | * @return array |
||
256 | */ |
||
257 | protected function initFieldsGroupByEntity() |
||
268 | |||
269 | /** |
||
270 | * @param OutputInterface $output |
||
271 | * |
||
272 | * @return \QualityCode\TransformAndLoadBundle\Services\Import |
||
273 | */ |
||
274 | protected function initProgressBar(OutputInterface $output) |
||
281 | |||
282 | /** |
||
283 | * @return Import |
||
284 | */ |
||
285 | protected function finishProgressBar() |
||
291 | |||
292 | /** |
||
293 | * @param int $advance |
||
294 | * |
||
295 | * @return Import |
||
296 | */ |
||
297 | protected function advanceProgressBar(int $advance) |
||
305 | } |
||
306 |