Passed
Push — master ( f4a43b...fd582e )
by Aimeos
03:37
created

Standard::run()   B

Complexity

Conditions 11
Paths 18

Size

Total Lines 69
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 11
eloc 27
c 3
b 0
f 0
nc 18
nop 0
dl 0
loc 69
rs 7.3166

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package Controller
7
 * @subpackage Jobs
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Product\Import\Csv;
12
13
14
/**
15
 * Job controller for CSV product imports.
16
 *
17
 * @package Controller
18
 * @subpackage Jobs
19
 */
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
140
	{
141
		return $this->context()->translate( 'controller/jobs', 'Product import CSV' );
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
151
	{
152
		return $this->context()->translate( 'controller/jobs', 'Imports new and updates existing products from CSV files' );
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
			$errors = 0;
170
			$location = $this->location();
171
			$fs = $context->fs( 'fs-import' );
172
			$site = $context->locale()->getSiteCode();
0 ignored issues
show
Bug introduced by
The method getSiteCode() does not exist on Aimeos\MShop\Locale\Item\Iface. Did you maybe mean getSiteId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
			$site = $context->locale()->/** @scrutinizer ignore-call */ getSiteCode();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
173
174
			foreach( [$location, $location . '/' . $site] as $location )
175
			{
176
				if( $fs instanceof \Aimeos\Base\Filesystem\DirIface && $fs->isDir( $location ) === false ) {
177
					continue;
178
				}
179
180
				foreach( map( $fs->scan( $location ) )->sort() as $filename )
181
				{
182
					if( $filename[0] === '.' ) {
183
						continue;
184
					}
185
186
					$path = $location . '/' . $filename;
187
188
					if( $fs instanceof \Aimeos\Base\Filesystem\DirIface && $fs->isDir( $path ) ) {
189
						continue;
190
					}
191
192
					$errors = $this->import( $path );
193
				}
194
			}
195
196
			/** controller/jobs/product/import/csv/destructive
197
			 * Deletes all products with categories which havn't been updated
198
			 *
199
			 * By default, the product importer only adds new and updates existing
200
			 * products but doesn't delete any products. If you want to remove all
201
			 * products which haven't been updated during the import, then set this
202
			 * configuration option to "true". This will remove all products which
203
			 * are not assigned to any category but keep the ones without categories,
204
			 * e.g. rebate products.
205
			 *
206
			 * @param bool TRUE to delete all untouched products, FALSE to keep them
207
			 * @since 2023.10
208
			 * @see controller/jobs/product/import/csv/backup
209
			 * @see controller/jobs/product/import/csv/domains
210
			 * @see controller/jobs/product/import/csv/location
211
			 * @see controller/jobs/product/import/csv/mapping
212
			 * @see controller/jobs/product/import/csv/max-size
213
			 * @see controller/jobs/product/import/csv/skip-lines
214
			 */
215
			if( $context->config()->get( 'controller/jobs/product/import/csv/destructive', false ) )
216
			{
217
				$count = $this->cleanup( $date );
218
				$logger->info( sprintf( 'Cleaned %1$s old products', $count ), 'import/csv/product' );
219
			}
220
221
			if( $errors > 0 ) {
222
				$this->mail( 'Product CSV import', sprintf( 'Invalid product lines during import: %1$d', $errors ) );
223
			}
224
		}
225
		catch( \Exception $e )
226
		{
227
			$logger->error( 'Product import error: ' . $e->getMessage() . "\n" . $e->getTraceAsString(), 'import/csv/product' );
228
			$this->mail( 'Product CSV import error', $e->getMessage() . "\n" . $e->getTraceAsString() );
229
			throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() );
230
		}
231
	}
232
233
234
	/**
235
	 * Returns the directory for storing imported files
236
	 *
237
	 * @return string Directory for storing imported files
238
	 */
239
	protected function backup() : string
240
	{
241
		/** controller/jobs/product/import/csv/backup
242
		 * Name of the backup for sucessfully imported files
243
		 *
244
		 * After a CSV file was imported successfully, you can move it to another
245
		 * location, so it won't be imported again and isn't overwritten by the
246
		 * next file that is stored at the same location in the file system.
247
		 *
248
		 * You should use an absolute path to be sure but can be relative path
249
		 * if you absolutely know from where the job will be executed from. The
250
		 * name of the new backup location can contain placeholders understood
251
		 * by the PHP DateTime::format() method (with percent signs prefix) to
252
		 * create dynamic paths, e.g. "backup/%Y-%m-%d" which would create
253
		 * "backup/2000-01-01". For more information about the date() placeholders,
254
		 * please have a look  into the PHP documentation of the
255
		 * {@link https://www.php.net/manual/en/datetime.format.php format() method}.
256
		 *
257
		 * **Note:** If no backup name is configured, the file will be removed!
258
		 *
259
		 * @param integer Name of the backup file, optionally with date/time placeholders
260
		 * @since 2018.04
261
		 * @see controller/jobs/product/import/csv/destructive
262
		 * @see controller/jobs/product/import/csv/domains
263
		 * @see controller/jobs/product/import/csv/location
264
		 * @see controller/jobs/product/import/csv/mapping
265
		 * @see controller/jobs/product/import/csv/max-size
266
		 * @see controller/jobs/product/import/csv/skip-lines
267
		 */
268
		$backup = $this->context()->config()->get( 'controller/jobs/product/import/csv/backup' );
269
		return \Aimeos\Base\Str::strtime( (string) $backup );
270
	}
271
272
273
	/**
274
	 * Checks the given product type for validity
275
	 *
276
	 * @param string|null $type Product type or null for no type
277
	 * @return string New product type
278
	 */
279
	protected function checkType( string $type = null ) : string
280
	{
281
		if( !isset( $this->types ) )
282
		{
283
			$this->types = [];
284
285
			$manager = \Aimeos\MShop::create( $this->context(), 'product/type' );
286
			$search = $manager->filter()->slice( 0, 10000 );
287
288
			foreach( $manager->search( $search ) as $item ) {
289
				$this->types[$item->getCode()] = $item->getCode();
290
			}
291
		}
292
293
		return ( isset( $this->types[$type] ) ? $this->types[$type] : 'default' );
294
	}
295
296
297
	/**
298
	 * Cleans up the given list of product items
299
	 *
300
	 * @param \Aimeos\Map $products List of product items implementing \Aimeos\MShop\Product\Item\Iface
301
	 */
302
	protected function clean( \Aimeos\Map $products )
303
	{
304
		$articles = $products->filter( fn( $item ) => $item->getType() === 'select' )
305
			->getRefItems( 'product', null, 'default' )->flat( 1 );
306
307
		\Aimeos\MShop::create( $this->context(), 'product' )->delete( $products->merge( $articles ) );
308
	}
309
310
311
	/**
312
	 * Adds conditions to the filter for fetching products that should be removed
313
	 *
314
	 * @param \Aimeos\Base\Criteria\Iface $filter Criteria object
315
	 * @return \Aimeos\Base\Criteria\Iface Modified criteria object
316
	 */
317
	protected function cleaner( \Aimeos\Base\Criteria\Iface $filter ) : \Aimeos\Base\Criteria\Iface
318
	{
319
		return $filter->add( $filter->make( 'product:has', ['catalog'] ), '!=', null );
320
	}
321
322
323
	/**
324
	 * Removes all products which have been updated before the given date/time
325
	 *
326
	 * @param string $datetime Date and time in ISO format
327
	 * @return int Number of removed products
328
	 */
329
	protected function cleanup( string $datetime ) : int
330
	{
331
		$count = 0;
332
		$manager = \Aimeos\MShop::create( $this->context(), 'product' );
333
334
		$filter = $manager->filter();
335
		$filter->add( 'product.mtime', '<', $datetime );
336
		$cursor = $manager->cursor( $this->call( 'cleaner', $filter ) );
337
338
		while( $items = $manager->iterate( $cursor, ['product' => ['default']] ) )
339
		{
340
			$this->call( 'clean', $items );
341
			$count += count( $items );
342
		}
343
344
		return $count;
345
	}
346
347
348
	/**
349
	 * Returns the list of domain names that should be retrieved along with the attribute items
350
	 *
351
	 * @return array List of domain names
352
	 */
353
	protected function domains() : array
354
	{
355
		/** controller/jobs/product/import/csv/domains
356
		 * List of item domain names that should be retrieved along with the product items
357
		 *
358
		 * For efficient processing, the items associated to the products can be
359
		 * fetched to, minimizing the number of database queries required. To be
360
		 * most effective, the list of item domain names should be used in the
361
		 * mapping configuration too, so the retrieved items will be used during
362
		 * the import.
363
		 *
364
		 * @param array Associative list of MShop item domain names
365
		 * @since 2018.04
366
		 * @see controller/jobs/product/import/csv/backup
367
		 * @see controller/jobs/product/import/csv/destructive
368
		 * @see controller/jobs/product/import/csv/location
369
		 * @see controller/jobs/product/import/csv/mapping
370
		 * @see controller/jobs/product/import/csv/max-size
371
		 * @see controller/jobs/product/import/csv/skip-lines
372
		 */
373
		return $this->context()->config()->get( 'controller/jobs/product/import/csv/domains', [] );
374
	}
375
376
377
	/**
378
	 * Returns the position of the "product.code" column from the product item mapping
379
	 *
380
	 * @param array $mapping Mapping of the "item" columns with position as key and code as value
381
	 * @return int Position of the "product.code" column
382
	 * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "product.code" is found
383
	 */
384
	protected function getCodePosition( array $mapping ) : int
385
	{
386
		foreach( $mapping as $pos => $key )
387
		{
388
			if( $key === 'product.code' ) {
389
				return $pos;
390
			}
391
		}
392
393
		throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) );
394
	}
395
396
397
	/**
398
	 * Returns the product items for the given codes
399
	 *
400
	 * @param array $codes List of product codes
401
	 * @param array $domains List of domains whose items should be fetched too
402
	 * @return \Aimeos\Map Associative list of product codes as key and product items as value
403
	 */
404
	protected function getProducts( array $codes, array $domains ) : \Aimeos\Map
405
	{
406
		$manager = \Aimeos\MShop::create( $this->context(), 'product' );
407
		$search = $manager->filter()->add( ['product.code' => $codes] )->slice( 0, count( $codes ) );
408
409
		return $manager->search( $search, $domains )->col( null, 'product.code' );
410
	}
411
412
413
	/**
414
	 * Imports the CSV file from the given path
415
	 *
416
	 * @param string $path Relative path to the CSV file
417
	 * @return int Number of lines which couldn't be imported
418
	 */
419
	protected function import( string $path ) : int
420
	{
421
		$context = $this->context();
422
		$logger = $context->logger();
423
424
		$logger->info( sprintf( 'Started product import from "%1$s"', $path ), 'import/csv/product' );
425
426
		$maxcnt = $this->max();
427
		$skiplines = $this->skip();
428
		$domains = $this->domains();
429
430
		$mappings = $this->mapping();
431
		$processor = $this->getProcessors( $mappings );
432
		$codePos = $this->getCodePosition( $mappings['item'] );
433
434
		$fs = $context->fs( 'fs-import' );
435
		$fh = $fs->reads( $path );
436
		$total = $errors = 0;
437
438
		for( $i = 0; $i < $skiplines; $i++ ) {
439
			fgetcsv( $fh );
440
		}
441
442
		while( ( $data = $this->getData( $fh, $maxcnt, $codePos ) ) !== [] )
443
		{
444
			$products = $this->getProducts( array_keys( $data ), $domains );
445
			$errors += $this->importProducts( $products, $data, $mappings['item'], [], $processor );
446
447
			$total += count( $data );
448
			unset( $products, $data );
449
		}
450
451
		$processor->finish();
452
		fclose( $fh );
453
454
		if( !empty( $backup = $this->backup() ) ) {
455
			$fs->move( $path, $backup );
456
		} else {
457
			$fs->rm( $path );
458
		}
459
460
		$str = sprintf( 'Finished product import from "%1$s" (%2$d/%3$d)', $path, $errors, $total );
461
		$logger->info( $str, 'import/csv/product' );
462
463
		return $errors;
464
	}
465
466
467
	/**
468
	 * Imports the CSV data and creates new products or updates existing ones
469
	 *
470
	 * @param \Aimeos\Map $products List of products items implementing \Aimeos\MShop\Product\Item\Iface
471
	 * @param array $data Associative list of import data as index/value pairs
472
	 * @param array $mapping Associative list of positions and domain item keys
473
	 * @param array $types List of allowed product type codes
474
	 * @param \Aimeos\Controller\Jobs\Common\Product\Import\Csv\Processor\Iface $processor Processor object
475
	 * @return int Number of products that couldn't be imported
476
	 * @throws \Aimeos\Controller\Jobs\Exception
477
	 */
478
	protected function importProducts( \Aimeos\Map $products, array $data, array $mapping, array $types,
479
		\Aimeos\Controller\Jobs\Common\Product\Import\Csv\Processor\Iface $processor ) : int
480
	{
481
		$items = [];
482
		$errors = 0;
483
		$context = $this->context();
484
		$manager = \Aimeos\MShop::create( $context, 'index' );
485
486
		foreach( $data as $code => $list )
487
		{
488
			$manager->begin();
489
490
			try
491
			{
492
				$code = trim( $code );
493
				$product = $products[$code] ?? $manager->create();
494
				$map = current( $this->getMappedChunk( $list, $mapping ) ); // there can only be one chunk for the base product data
495
496
				if( $map )
497
				{
498
					$type = $this->checkType( $this->val( $map, 'product.type', $product->getType() ) );
499
500
					if( $config = $this->val( $map, 'product.config' ) ) {
501
						$map['product.config'] = json_decode( $config ) ?: [];
502
					}
503
504
					$product = $product->fromArray( $map, true );
505
					$product = $manager->save( $product->setType( $type ) );
506
507
					$processor->process( $product, $list );
0 ignored issues
show
Bug introduced by
It seems like $product can also be of type Aimeos\Map; however, parameter $product of Aimeos\Controller\Jobs\C...cessor\Iface::process() does only seem to accept Aimeos\MShop\Product\Item\Iface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

507
					$processor->process( /** @scrutinizer ignore-type */ $product, $list );
Loading history...
508
509
					$product = $manager->save( $product->setModified() );
510
					$items[$product->getId()] = $product;
511
				}
512
513
				$manager->commit();
514
			}
515
			catch( \Throwable $t )
516
			{
517
				$manager->rollback();
518
519
				$msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $t->getMessage() );
520
				$context->logger()->error( $msg, 'import/csv/product' );
521
522
				$errors++;
523
			}
524
		}
525
526
		return $errors;
527
	}
528
529
530
	/**
531
	 * Returns the path to the directory with the CSV file
532
	 *
533
	 * @return string Path to the directory with the CSV file
534
	 */
535
	protected function location() : string
536
	{
537
		/** controller/jobs/product/import/csv/location
538
		 * Directory where the CSV files are stored which should be imported
539
		 *
540
		 * It's the relative path inside the "fs-import" virtual file system
541
		 * configuration. The default location of the "fs-import" file system is:
542
		 *
543
		 * * Laravel: ./storage/import/
544
		 * * TYPO3: /uploads/tx_aimeos/.secure/import/
545
		 *
546
		 * @param string Relative path to the CSV files
547
		 * @since 2015.08
548
		 * @see controller/jobs/product/import/csv/backup
549
		 * @see controller/jobs/product/import/csv/destructive
550
		 * @see controller/jobs/product/import/csv/domains
551
		 * @see controller/jobs/product/import/csv/location
552
		 * @see controller/jobs/product/import/csv/mapping
553
		 * @see controller/jobs/product/import/csv/max-size
554
		 * @see controller/jobs/product/import/csv/skip-lines
555
		 */
556
		return (string) $this->context()->config()->get( 'controller/jobs/product/import/csv/location', 'product' );
557
	}
558
559
560
	/**
561
	 * Returns the CSV column mapping
562
	 *
563
	 * @return array CSV column mapping
564
	 */
565
	protected function mapping() : array
566
	{
567
		/** controller/jobs/product/import/csv/mapping
568
		 * List of mappings between the position in the CSV file and item keys
569
		 *
570
		 * The importer have to know which data is at which position in the CSV
571
		 * file. Therefore, you need to specify a mapping between each position
572
		 * and the MShop domain item key (e.g. "product.code") it represents.
573
		 *
574
		 * You can use all domain item keys which are used in the fromArray()
575
		 * methods of the item classes.
576
		 *
577
		 * These mappings are grouped together by their processor names, which
578
		 * are responsible for importing the data, e.g. all mappings in "item"
579
		 * will be processed by the base product importer while the mappings in
580
		 * "text" will be imported by the text processor.
581
		 *
582
		 * @param array Associative list of processor names and lists of key/position pairs
583
		 * @since 2018.04
584
		 * @see controller/jobs/product/import/csv/backup
585
		 * @see controller/jobs/product/import/csv/destructive
586
		 * @see controller/jobs/product/import/csv/domains
587
		 * @see controller/jobs/product/import/csv/location
588
		 * @see controller/jobs/product/import/csv/max-size
589
		 * @see controller/jobs/product/import/csv/skip-lines
590
		 */
591
		$map = (array) $this->context()->config()->get( 'controller/jobs/product/import/csv/mapping', $this->getDefaultMapping() );
592
593
		if( !isset( $map['item'] ) || !is_array( $map['item'] ) )
594
		{
595
			$msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' );
596
			throw new \Aimeos\Controller\Jobs\Exception( $msg );
597
		}
598
599
		return $map;
600
	}
601
602
603
	/**
604
	 * Returns the maximum number of CSV rows to import at once
605
	 *
606
	 * @return int Maximum number of CSV rows to import at once
607
	 */
608
	protected function max() : int
609
	{
610
		/** controller/jobs/product/import/csv/max-size
611
		 * Maximum number of CSV rows to import at once
612
		 *
613
		 * It's more efficient to read and import more than one row at a time
614
		 * to speed up the import. Usually, the bigger the chunk that is imported
615
		 * at once, the less time the importer will need. The downside is that
616
		 * the amount of memory required by the import process will increase as
617
		 * well. Therefore, it's a trade-off between memory consumption and
618
		 * import speed.
619
		 *
620
		 * @param integer Number of rows
621
		 * @since 2018.04
622
		 * @see controller/jobs/product/import/csv/backup
623
		 * @see controller/jobs/product/import/csv/destructive
624
		 * @see controller/jobs/product/import/csv/domains
625
		 * @see controller/jobs/product/import/csv/location
626
		 * @see controller/jobs/product/import/csv/mapping
627
		 * @see controller/jobs/product/import/csv/skip-lines
628
		 */
629
		return (int) $this->context()->config()->get( 'controller/jobs/product/import/csv/max-size', 1000 );
630
	}
631
632
633
	/**
634
	 * Returns the number of rows skipped in front of each CSV files
635
	 *
636
	 * @return int Number of rows skipped in front of each CSV files
637
	 */
638
	protected function skip() : int
639
	{
640
		/** controller/jobs/product/import/csv/skip-lines
641
		 * Number of rows skipped in front of each CSV files
642
		 *
643
		 * Some CSV files contain header information describing the content of
644
		 * the column values. These data is for informational purpose only and
645
		 * can't be imported into the database. Using this option, you can
646
		 * define the number of lines that should be left out before the import
647
		 * begins.
648
		 *
649
		 * @param integer Number of rows
650
		 * @since 2015.08
651
		 * @see controller/jobs/product/import/csv/backup
652
		 * @see controller/jobs/product/import/csv/destructive
653
		 * @see controller/jobs/product/import/csv/domains
654
		 * @see controller/jobs/product/import/csv/location
655
		 * @see controller/jobs/product/import/csv/mapping
656
		 * @see controller/jobs/product/import/csv/max-size
657
		 */
658
		return (int) $this->context()->config()->get( 'controller/jobs/product/import/csv/skip-lines', 0 );
659
	}
660
}
661