Total Complexity | 42 |
Total Lines | 640 |
Duplicated Lines | 0 % |
Changes | 8 | ||
Bugs | 0 | Features | 0 |
Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class Standard |
||
21 | extends \Aimeos\Controller\Jobs\Common\Product\Import\Csv\Base |
||
22 | implements \Aimeos\Controller\Jobs\Iface |
||
23 | { |
||
24 | /** controller/jobs/product/import/csv/name |
||
25 | * Class name of the used product suggestions scheduler controller implementation |
||
26 | * |
||
27 | * Each default job controller can be replace by an alternative imlementation. |
||
28 | * To use this implementation, you have to set the last part of the class |
||
29 | * name as configuration value so the controller factory knows which class it |
||
30 | * has to instantiate. |
||
31 | * |
||
32 | * For example, if the name of the default class is |
||
33 | * |
||
34 | * \Aimeos\Controller\Jobs\Product\Import\Csv\Standard |
||
35 | * |
||
36 | * and you want to replace it with your own version named |
||
37 | * |
||
38 | * \Aimeos\Controller\Jobs\Product\Import\Csv\Mycsv |
||
39 | * |
||
40 | * then you have to set the this configuration option: |
||
41 | * |
||
42 | * controller/jobs/product/import/csv/name = Mycsv |
||
43 | * |
||
44 | * The value is the last part of your own class name and it's case sensitive, |
||
45 | * so take care that the configuration value is exactly named like the last |
||
46 | * part of the class name. |
||
47 | * |
||
48 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
49 | * characters are possible! You should always start the last part of the class |
||
50 | * name with an upper case character and continue only with lower case characters |
||
51 | * or numbers. Avoid chamel case names like "MyCsv"! |
||
52 | * |
||
53 | * @param string Last part of the class name |
||
54 | * @since 2015.01 |
||
55 | */ |
||
56 | |||
57 | /** controller/jobs/product/import/csv/decorators/excludes |
||
58 | * Excludes decorators added by the "common" option from the product import CSV job controller |
||
59 | * |
||
60 | * Decorators extend the functionality of a class by adding new aspects |
||
61 | * (e.g. log what is currently done), executing the methods of the underlying |
||
62 | * class only in certain conditions (e.g. only for logged in users) or |
||
63 | * modify what is returned to the caller. |
||
64 | * |
||
65 | * This option allows you to remove a decorator added via |
||
66 | * "controller/jobs/common/decorators/default" before they are wrapped |
||
67 | * around the job controller. |
||
68 | * |
||
69 | * controller/jobs/product/import/csv/decorators/excludes = array( 'decorator1' ) |
||
70 | * |
||
71 | * This would remove the decorator named "decorator1" from the list of |
||
72 | * common decorators ("\Aimeos\Controller\Jobs\Common\Decorator\*") added via |
||
73 | * "controller/jobs/common/decorators/default" to the job controller. |
||
74 | * |
||
75 | * @param array List of decorator names |
||
76 | * @since 2015.01 |
||
77 | * @see controller/jobs/common/decorators/default |
||
78 | * @see controller/jobs/product/import/csv/decorators/global |
||
79 | * @see controller/jobs/product/import/csv/decorators/local |
||
80 | */ |
||
81 | |||
82 | /** controller/jobs/product/import/csv/decorators/global |
||
83 | * Adds a list of globally available decorators only to the product import CSV job controller |
||
84 | * |
||
85 | * Decorators extend the functionality of a class by adding new aspects |
||
86 | * (e.g. log what is currently done), executing the methods of the underlying |
||
87 | * class only in certain conditions (e.g. only for logged in users) or |
||
88 | * modify what is returned to the caller. |
||
89 | * |
||
90 | * This option allows you to wrap global decorators |
||
91 | * ("\Aimeos\Controller\Jobs\Common\Decorator\*") around the job controller. |
||
92 | * |
||
93 | * controller/jobs/product/import/csv/decorators/global = array( 'decorator1' ) |
||
94 | * |
||
95 | * This would add the decorator named "decorator1" defined by |
||
96 | * "\Aimeos\Controller\Jobs\Common\Decorator\Decorator1" only to the job controller. |
||
97 | * |
||
98 | * @param array List of decorator names |
||
99 | * @since 2015.01 |
||
100 | * @see controller/jobs/common/decorators/default |
||
101 | * @see controller/jobs/product/import/csv/decorators/excludes |
||
102 | * @see controller/jobs/product/import/csv/decorators/local |
||
103 | */ |
||
104 | |||
105 | /** controller/jobs/product/import/csv/decorators/local |
||
106 | * Adds a list of local decorators only to the product import CSV job controller |
||
107 | * |
||
108 | * Decorators extend the functionality of a class by adding new aspects |
||
109 | * (e.g. log what is currently done), executing the methods of the underlying |
||
110 | * class only in certain conditions (e.g. only for logged in users) or |
||
111 | * modify what is returned to the caller. |
||
112 | * |
||
113 | * This option allows you to wrap local decorators |
||
114 | * ("\Aimeos\Controller\Jobs\Product\Import\Csv\Decorator\*") around the job |
||
115 | * controller. |
||
116 | * |
||
117 | * controller/jobs/product/import/csv/decorators/local = array( 'decorator2' ) |
||
118 | * |
||
119 | * This would add the decorator named "decorator2" defined by |
||
120 | * "\Aimeos\Controller\Jobs\Product\Import\Csv\Decorator\Decorator2" |
||
121 | * only to the job controller. |
||
122 | * |
||
123 | * @param array List of decorator names |
||
124 | * @since 2015.01 |
||
125 | * @see controller/jobs/common/decorators/default |
||
126 | * @see controller/jobs/product/import/csv/decorators/excludes |
||
127 | * @see controller/jobs/product/import/csv/decorators/global |
||
128 | */ |
||
129 | |||
130 | |||
131 | private ?array $types = null; |
||
132 | |||
133 | |||
134 | /** |
||
135 | * Returns the localized name of the job. |
||
136 | * |
||
137 | * @return string Name of the job |
||
138 | */ |
||
139 | public function getName() : string |
||
142 | } |
||
143 | |||
144 | |||
145 | /** |
||
146 | * Returns the localized description of the job. |
||
147 | * |
||
148 | * @return string Description of the job |
||
149 | */ |
||
150 | public function getDescription() : string |
||
153 | } |
||
154 | |||
155 | |||
156 | /** |
||
157 | * Executes the job. |
||
158 | * |
||
159 | * @throws \Aimeos\Controller\Jobs\Exception If an error occurs |
||
160 | */ |
||
161 | public function run() |
||
162 | { |
||
163 | $context = $this->context(); |
||
164 | $logger = $context->logger(); |
||
165 | $date = date( 'Y-m-d H:i:s' ); |
||
166 | |||
167 | try |
||
168 | { |
||
169 | $files = $errors = 0; |
||
170 | $fs = $context->fs( 'fs-import' ); |
||
171 | $site = $context->locale()->getSiteItem()->getCode(); |
||
172 | $location = $this->location() . '/' . $site; |
||
173 | |||
174 | if( $fs->isDir( $location ) === false ) { |
||
175 | return; |
||
176 | } |
||
177 | |||
178 | $logger->info( sprintf( 'Started product import from "%1$s"', $location ), 'import/csv/product' ); |
||
179 | |||
180 | foreach( map( $fs->scan( $location ) )->sort() as $filename ) |
||
181 | { |
||
182 | $path = $location . '/' . $filename; |
||
183 | |||
184 | if( $filename[0] === '.' || $fs instanceof \Aimeos\Base\Filesystem\DirIface && $fs->isDir( $path ) ) { |
||
185 | continue; |
||
186 | } |
||
187 | |||
188 | $errors = $this->import( $path ); |
||
189 | $files++; |
||
190 | } |
||
191 | |||
192 | /** controller/jobs/product/import/csv/cleanup |
||
193 | * Deletes all products with categories which havn't been updated |
||
194 | * |
||
195 | * By default, the product importer only adds new and updates existing |
||
196 | * products but doesn't delete any products. If you want to remove all |
||
197 | * products which haven't been updated during the import, then set this |
||
198 | * configuration option to "true". This will remove all products which |
||
199 | * are not assigned to any category but keep the ones without categories, |
||
200 | * e.g. rebate products. |
||
201 | * |
||
202 | * @param bool TRUE to delete all untouched products, FALSE to keep them |
||
203 | * @since 2023.10 |
||
204 | * @see controller/jobs/product/import/csv/backup |
||
205 | * @see controller/jobs/product/import/csv/domains |
||
206 | * @see controller/jobs/product/import/csv/location |
||
207 | * @see controller/jobs/product/import/csv/mapping |
||
208 | * @see controller/jobs/product/import/csv/max-size |
||
209 | * @see controller/jobs/product/import/csv/skip-lines |
||
210 | */ |
||
211 | if( $files && $context->config()->get( 'controller/jobs/product/import/csv/cleanup', false ) ) |
||
212 | { |
||
213 | $count = $this->cleanup( $date ); |
||
214 | $logger->info( sprintf( 'Cleaned %1$s old products', $count ), 'import/csv/product' ); |
||
215 | } |
||
216 | |||
217 | if( $errors > 0 ) { |
||
218 | $this->mail( 'Product CSV import', sprintf( 'Invalid product lines during import: %1$d', $errors ) ); |
||
219 | } |
||
220 | |||
221 | $logger->info( sprintf( 'Finished product import from "%1$s"', $location ), 'import/csv/product' ); |
||
222 | } |
||
223 | catch( \Exception $e ) |
||
224 | { |
||
225 | $logger->error( 'Product import error: ' . $e->getMessage() . "\n" . $e->getTraceAsString(), 'import/csv/product' ); |
||
226 | $this->mail( 'Product CSV import error', $e->getMessage() . "\n" . $e->getTraceAsString() ); |
||
227 | throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
||
228 | } |
||
229 | } |
||
230 | |||
231 | |||
232 | /** |
||
233 | * Returns the directory for storing imported files |
||
234 | * |
||
235 | * @return string Directory for storing imported files |
||
236 | */ |
||
237 | protected function backup() : string |
||
238 | { |
||
239 | /** controller/jobs/product/import/csv/backup |
||
240 | * Name of the backup for sucessfully imported files |
||
241 | * |
||
242 | * After a CSV file was imported successfully, you can move it to another |
||
243 | * location, so it won't be imported again and isn't overwritten by the |
||
244 | * next file that is stored at the same location in the file system. |
||
245 | * |
||
246 | * You should use an absolute path to be sure but can be relative path |
||
247 | * if you absolutely know from where the job will be executed from. The |
||
248 | * name of the new backup location can contain placeholders understood |
||
249 | * by the PHP DateTime::format() method (with percent signs prefix) to |
||
250 | * create dynamic paths, e.g. "backup/%Y-%m-%d" which would create |
||
251 | * "backup/2000-01-01". For more information about the date() placeholders, |
||
252 | * please have a look into the PHP documentation of the |
||
253 | * {@link https://www.php.net/manual/en/datetime.format.php format() method}. |
||
254 | * |
||
255 | * **Note:** If no backup name is configured, the file will be removed! |
||
256 | * |
||
257 | * @param integer Name of the backup file, optionally with date/time placeholders |
||
258 | * @since 2018.04 |
||
259 | * @see controller/jobs/product/import/csv/cleanup |
||
260 | * @see controller/jobs/product/import/csv/domains |
||
261 | * @see controller/jobs/product/import/csv/location |
||
262 | * @see controller/jobs/product/import/csv/mapping |
||
263 | * @see controller/jobs/product/import/csv/max-size |
||
264 | * @see controller/jobs/product/import/csv/skip-lines |
||
265 | */ |
||
266 | $backup = $this->context()->config()->get( 'controller/jobs/product/import/csv/backup' ); |
||
267 | return \Aimeos\Base\Str::strtime( (string) $backup ); |
||
268 | } |
||
269 | |||
270 | |||
271 | /** |
||
272 | * Checks the given product type for validity |
||
273 | * |
||
274 | * @param string|null $type Product type or null for no type |
||
275 | * @return string New product type |
||
276 | */ |
||
277 | protected function checkType( ?string $type = null ) : string |
||
278 | { |
||
279 | if( !isset( $this->types ) ) |
||
280 | { |
||
281 | $this->types = []; |
||
282 | |||
283 | $manager = \Aimeos\MShop::create( $this->context(), 'product/type' ); |
||
284 | $search = $manager->filter()->slice( 0, 10000 ); |
||
285 | |||
286 | foreach( $manager->search( $search ) as $item ) { |
||
287 | $this->types[$item->getCode()] = $item->getCode(); |
||
288 | } |
||
289 | } |
||
290 | |||
291 | return ( isset( $this->types[$type] ) ? $this->types[$type] : 'default' ); |
||
292 | } |
||
293 | |||
294 | |||
295 | /** |
||
296 | * Cleans up the given list of product items |
||
297 | * |
||
298 | * @param \Aimeos\Map $products List of product items implementing \Aimeos\MShop\Product\Item\Iface |
||
299 | */ |
||
300 | protected function clean( \Aimeos\Map $products ) |
||
301 | { |
||
302 | $articles = $products->filter( fn( $item ) => $item->getType() === 'select' ) |
||
303 | ->getRefItems( 'product', null, 'default' )->flat( 1 ); |
||
304 | |||
305 | $manager = \Aimeos\MShop::create( $this->context(), 'index' ); |
||
306 | |||
307 | $manager->begin(); |
||
308 | $manager->save( $products->merge( $articles )->setStatus( -2 ) ); |
||
309 | $manager->commit(); |
||
310 | } |
||
311 | |||
312 | |||
313 | /** |
||
314 | * Adds conditions to the filter for fetching products that should be removed |
||
315 | * |
||
316 | * @param \Aimeos\Base\Criteria\Iface $filter Criteria object |
||
317 | * @return \Aimeos\Base\Criteria\Iface Modified criteria object |
||
318 | */ |
||
319 | protected function cleaner( \Aimeos\Base\Criteria\Iface $filter ) : \Aimeos\Base\Criteria\Iface |
||
320 | { |
||
321 | return $filter->add( $filter->make( 'product:has', ['catalog'] ), '!=', null ); |
||
322 | } |
||
323 | |||
324 | |||
325 | /** |
||
326 | * Removes all products which have been updated before the given date/time |
||
327 | * |
||
328 | * @param string $datetime Date and time in ISO format |
||
329 | * @return int Number of removed products |
||
330 | */ |
||
331 | protected function cleanup( string $datetime ) : int |
||
332 | { |
||
333 | $count = 0; |
||
334 | $manager = \Aimeos\MShop::create( $this->context(), 'index' ); |
||
335 | |||
336 | $filter = $manager->filter(); |
||
337 | $filter->add( 'product.mtime', '<', $datetime ); |
||
338 | $cursor = $manager->cursor( $this->call( 'cleaner', $filter ) ); |
||
339 | |||
340 | while( $items = $manager->iterate( $cursor, ['product' => ['default']] ) ) |
||
341 | { |
||
342 | $this->call( 'clean', $items ); |
||
343 | $count += count( $items ); |
||
344 | } |
||
345 | |||
346 | return $count; |
||
347 | } |
||
348 | |||
349 | |||
350 | /** |
||
351 | * Returns the list of domain names that should be retrieved along with the attribute items |
||
352 | * |
||
353 | * @return array List of domain names |
||
354 | */ |
||
355 | protected function domains() : array |
||
356 | { |
||
357 | /** controller/jobs/product/import/csv/domains |
||
358 | * List of item domain names that should be retrieved along with the product items |
||
359 | * |
||
360 | * For efficient processing, the items associated to the products can be |
||
361 | * fetched to, minimizing the number of database queries required. To be |
||
362 | * most effective, the list of item domain names should be used in the |
||
363 | * mapping configuration too, so the retrieved items will be used during |
||
364 | * the import. |
||
365 | * |
||
366 | * @param array Associative list of MShop item domain names |
||
367 | * @since 2018.04 |
||
368 | * @see controller/jobs/product/import/csv/backup |
||
369 | * @see controller/jobs/product/import/csv/cleanup |
||
370 | * @see controller/jobs/product/import/csv/location |
||
371 | * @see controller/jobs/product/import/csv/mapping |
||
372 | * @see controller/jobs/product/import/csv/max-size |
||
373 | * @see controller/jobs/product/import/csv/skip-lines |
||
374 | */ |
||
375 | return $this->context()->config()->get( 'controller/jobs/product/import/csv/domains', [] ); |
||
376 | } |
||
377 | |||
378 | |||
379 | /** |
||
380 | * Returns the position of the "product.code" column from the product item mapping |
||
381 | * |
||
382 | * @param array $mapping Mapping of the "item" columns with position as key and code as value |
||
383 | * @return int Position of the "product.code" column |
||
384 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "product.code" is found |
||
385 | */ |
||
386 | protected function getCodePosition( array $mapping ) : int |
||
387 | { |
||
388 | foreach( $mapping as $pos => $key ) |
||
389 | { |
||
390 | if( $key === 'product.code' ) { |
||
391 | return $pos; |
||
392 | } |
||
393 | } |
||
394 | |||
395 | throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) ); |
||
396 | } |
||
397 | |||
398 | |||
399 | /** |
||
400 | * Returns the product items for the given codes |
||
401 | * |
||
402 | * @param array $codes List of product codes |
||
403 | * @param array $domains List of domains whose items should be fetched too |
||
404 | * @return \Aimeos\Map Associative list of product codes as key and product items as value |
||
405 | */ |
||
406 | protected function getProducts( array $codes, array $domains ) : \Aimeos\Map |
||
407 | { |
||
408 | $manager = \Aimeos\MShop::create( $this->context(), 'index' ); |
||
409 | $search = $manager->filter()->add( ['product.code' => $codes] )->slice( 0, count( $codes ) ); |
||
410 | |||
411 | return $manager->search( $search, $domains )->col( null, 'product.code' ); |
||
412 | } |
||
413 | |||
414 | |||
415 | /** |
||
416 | * Imports the CSV file from the given path |
||
417 | * |
||
418 | * @param string $path Relative path to the CSV file |
||
419 | * @return int Number of lines which couldn't be imported |
||
420 | */ |
||
421 | protected function import( string $path ) : int |
||
422 | { |
||
423 | $context = $this->context(); |
||
424 | $logger = $context->logger(); |
||
425 | |||
426 | $logger->info( sprintf( 'Started product import from "%1$s"', $path ), 'import/csv/product' ); |
||
427 | |||
428 | $maxcnt = $this->max(); |
||
429 | $skiplines = $this->skip(); |
||
430 | $domains = $this->domains(); |
||
431 | |||
432 | $mappings = $this->mapping(); |
||
433 | $processor = $this->getProcessors( $mappings ); |
||
434 | $codePos = $this->getCodePosition( $mappings['item'] ); |
||
435 | |||
436 | $fs = $context->fs( 'fs-import' ); |
||
437 | $fh = $fs->reads( $path ); |
||
438 | $total = $errors = 0; |
||
439 | |||
440 | for( $i = 0; $i < $skiplines; $i++ ) { |
||
441 | fgetcsv( $fh, null, ',', '"', '' ); |
||
442 | } |
||
443 | |||
444 | while( ( $data = $this->getData( $fh, $maxcnt, $codePos ) ) !== [] ) |
||
445 | { |
||
446 | $products = $this->getProducts( array_keys( $data ), $domains ); |
||
447 | $errors += $this->importProducts( $products, $data, $mappings['item'], [], $processor ); |
||
448 | |||
449 | $total += count( $data ); |
||
450 | unset( $products, $data ); |
||
451 | } |
||
452 | |||
453 | $processor->finish(); |
||
454 | fclose( $fh ); |
||
455 | |||
456 | if( !empty( $backup = $this->backup() ) ) { |
||
457 | $fs->move( $path, $backup ); |
||
458 | } else { |
||
459 | $fs->rm( $path ); |
||
460 | } |
||
461 | |||
462 | $str = sprintf( 'Finished product import from "%1$s" (%2$d/%3$d)', $path, $errors, $total ); |
||
463 | $logger->info( $str, 'import/csv/product' ); |
||
464 | |||
465 | return $errors; |
||
466 | } |
||
467 | |||
468 | |||
469 | /** |
||
470 | * Imports the CSV data and creates new products or updates existing ones |
||
471 | * |
||
472 | * @param \Aimeos\Map $products List of products items implementing \Aimeos\MShop\Product\Item\Iface |
||
473 | * @param array $data Associative list of import data as index/value pairs |
||
474 | * @param array $mapping Associative list of positions and domain item keys |
||
475 | * @param array $types List of allowed product type codes |
||
476 | * @param \Aimeos\Controller\Jobs\Common\Product\Import\Csv\Processor\Iface $processor Processor object |
||
477 | * @return int Number of products that couldn't be imported |
||
478 | * @throws \Aimeos\Controller\Jobs\Exception |
||
479 | */ |
||
480 | protected function importProducts( \Aimeos\Map $products, array $data, array $mapping, array $types, |
||
481 | \Aimeos\Controller\Jobs\Common\Product\Import\Csv\Processor\Iface $processor ) : int |
||
482 | { |
||
483 | $items = []; |
||
484 | $errors = 0; |
||
485 | $context = $this->context(); |
||
486 | $manager = \Aimeos\MShop::create( $context, 'index' ); |
||
487 | |||
488 | foreach( $data as $code => $list ) |
||
489 | { |
||
490 | $manager->begin(); |
||
491 | |||
492 | try |
||
493 | { |
||
494 | $code = trim( $code ); |
||
495 | $product = $products[$code] ?? $manager->create(); |
||
496 | $map = current( $this->getMappedChunk( $list, $mapping ) ); // there can only be one chunk for the base product data |
||
497 | |||
498 | if( $map ) |
||
499 | { |
||
500 | $type = $this->checkType( $this->val( $map, 'product.type', $product->getType() ) ); |
||
501 | |||
502 | if( $config = $this->val( $map, 'product.config' ) ) { |
||
503 | $map['product.config'] = json_decode( $config ) ?: []; |
||
504 | } |
||
505 | |||
506 | $product = $manager->save( $product->fromArray( $map, true )->setType( $type ) ); |
||
507 | |||
508 | $processor->process( $product, $list ); |
||
|
|||
509 | |||
510 | $product = $manager->save( $product->setModified() ); |
||
511 | $items[$product->getId()] = $product; |
||
512 | } |
||
513 | |||
514 | $manager->commit(); |
||
515 | } |
||
516 | catch( \Throwable $t ) |
||
517 | { |
||
518 | $manager->rollback(); |
||
519 | |||
520 | $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $t->getMessage() ); |
||
521 | $context->logger()->error( $msg, 'import/csv/product' ); |
||
522 | |||
523 | $errors++; |
||
524 | } |
||
525 | } |
||
526 | |||
527 | return $errors; |
||
528 | } |
||
529 | |||
530 | |||
531 | /** |
||
532 | * Returns the path to the directory with the CSV file |
||
533 | * |
||
534 | * @return string Path to the directory with the CSV file |
||
535 | */ |
||
536 | protected function location() : string |
||
558 | } |
||
559 | |||
560 | |||
561 | /** |
||
562 | * Returns the CSV column mapping |
||
563 | * |
||
564 | * @return array CSV column mapping |
||
565 | */ |
||
566 | protected function mapping() : array |
||
567 | { |
||
568 | /** controller/jobs/product/import/csv/mapping |
||
569 | * List of mappings between the position in the CSV file and item keys |
||
570 | * |
||
571 | * The importer have to know which data is at which position in the CSV |
||
572 | * file. Therefore, you need to specify a mapping between each position |
||
573 | * and the MShop domain item key (e.g. "product.code") it represents. |
||
574 | * |
||
575 | * You can use all domain item keys which are used in the fromArray() |
||
576 | * methods of the item classes. |
||
577 | * |
||
578 | * These mappings are grouped together by their processor names, which |
||
579 | * are responsible for importing the data, e.g. all mappings in "item" |
||
580 | * will be processed by the base product importer while the mappings in |
||
581 | * "text" will be imported by the text processor. |
||
582 | * |
||
583 | * @param array Associative list of processor names and lists of key/position pairs |
||
584 | * @since 2018.04 |
||
585 | * @see controller/jobs/product/import/csv/backup |
||
586 | * @see controller/jobs/product/import/csv/cleanup |
||
587 | * @see controller/jobs/product/import/csv/domains |
||
588 | * @see controller/jobs/product/import/csv/location |
||
589 | * @see controller/jobs/product/import/csv/max-size |
||
590 | * @see controller/jobs/product/import/csv/skip-lines |
||
591 | */ |
||
592 | $map = (array) $this->context()->config()->get( 'controller/jobs/product/import/csv/mapping', $this->getDefaultMapping() ); |
||
593 | |||
594 | if( !isset( $map['item'] ) || !is_array( $map['item'] ) ) |
||
595 | { |
||
596 | $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
||
597 | throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
||
598 | } |
||
599 | |||
600 | return $map; |
||
601 | } |
||
602 | |||
603 | |||
604 | /** |
||
605 | * Returns the maximum number of CSV rows to import at once |
||
606 | * |
||
607 | * @return int Maximum number of CSV rows to import at once |
||
608 | */ |
||
609 | protected function max() : int |
||
610 | { |
||
611 | /** controller/jobs/product/import/csv/max-size |
||
612 | * Maximum number of CSV rows to import at once |
||
613 | * |
||
614 | * It's more efficient to read and import more than one row at a time |
||
615 | * to speed up the import. Usually, the bigger the chunk that is imported |
||
616 | * at once, the less time the importer will need. The downside is that |
||
617 | * the amount of memory required by the import process will increase as |
||
618 | * well. Therefore, it's a trade-off between memory consumption and |
||
619 | * import speed. |
||
620 | * |
||
621 | * @param integer Number of rows |
||
622 | * @since 2018.04 |
||
623 | * @see controller/jobs/product/import/csv/backup |
||
624 | * @see controller/jobs/product/import/csv/cleanup |
||
625 | * @see controller/jobs/product/import/csv/domains |
||
626 | * @see controller/jobs/product/import/csv/location |
||
627 | * @see controller/jobs/product/import/csv/mapping |
||
628 | * @see controller/jobs/product/import/csv/skip-lines |
||
629 | */ |
||
630 | return (int) $this->context()->config()->get( 'controller/jobs/product/import/csv/max-size', 1000 ); |
||
631 | } |
||
632 | |||
633 | |||
634 | /** |
||
635 | * Returns the number of rows skipped in front of each CSV files |
||
636 | * |
||
637 | * @return int Number of rows skipped in front of each CSV files |
||
638 | */ |
||
639 | protected function skip() : int |
||
660 | } |
||
661 | } |
||
662 |