@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function getName() |
| 30 | 30 | { |
| 31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Catalog import CSV' ); |
|
| 31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Catalog import CSV'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function getDescription() |
| 41 | 41 | { |
| 42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Imports new and updates existing categories from CSV files' ); |
|
| 42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing categories from CSV files'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $context = $this->getContext(); |
| 55 | 55 | $config = $context->getConfig(); |
| 56 | 56 | $logger = $context->getLogger(); |
| 57 | - $domains = array( 'media', 'text' ); |
|
| 57 | + $domains = array('media', 'text'); |
|
| 58 | 58 | $mappings = $this->getDefaultMapping(); |
| 59 | 59 | |
| 60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @see controller/common/catalog/import/csv/converter |
| 75 | 75 | * @see controller/common/catalog/import/csv/max-size |
| 76 | 76 | */ |
| 77 | - $domains = $config->get( 'controller/common/catalog/import/csv/domains', $domains ); |
|
| 77 | + $domains = $config->get('controller/common/catalog/import/csv/domains', $domains); |
|
| 78 | 78 | |
| 79 | 79 | /** controller/jobs/catalog/import/csv/domains |
| 80 | 80 | * List of item domain names that should be retrieved along with the catalog items |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @see controller/jobs/catalog/import/csv/backup |
| 95 | 95 | * @see controller/common/catalog/import/csv/max-size |
| 96 | 96 | */ |
| 97 | - $domains = $config->get( 'controller/jobs/catalog/import/csv/domains', $domains ); |
|
| 97 | + $domains = $config->get('controller/jobs/catalog/import/csv/domains', $domains); |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /** controller/common/catalog/import/csv/mapping |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @see controller/common/catalog/import/csv/converter |
| 123 | 123 | * @see controller/common/catalog/import/csv/max-size |
| 124 | 124 | */ |
| 125 | - $mappings = $config->get( 'controller/common/catalog/import/csv/mapping', $mappings ); |
|
| 125 | + $mappings = $config->get('controller/common/catalog/import/csv/mapping', $mappings); |
|
| 126 | 126 | |
| 127 | 127 | /** controller/jobs/catalog/import/csv/mapping |
| 128 | 128 | * List of mappings between the position in the CSV file and item keys |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @see controller/jobs/catalog/import/csv/backup |
| 143 | 143 | * @see controller/common/catalog/import/csv/max-size |
| 144 | 144 | */ |
| 145 | - $mappings = $config->get( 'controller/jobs/catalog/import/csv/mapping', $mappings ); |
|
| 145 | + $mappings = $config->get('controller/jobs/catalog/import/csv/mapping', $mappings); |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | /** controller/common/catalog/import/csv/converter |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @see controller/common/catalog/import/csv/mapping |
| 185 | 185 | * @see controller/common/catalog/import/csv/max-size |
| 186 | 186 | */ |
| 187 | - $converters = $config->get( 'controller/common/catalog/import/csv/converter', [] ); |
|
| 187 | + $converters = $config->get('controller/common/catalog/import/csv/converter', []); |
|
| 188 | 188 | |
| 189 | 189 | /** controller/jobs/catalog/import/csv/converter |
| 190 | 190 | * List of converter names for the values at the position in the CSV file |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @see controller/jobs/catalog/import/csv/backup |
| 205 | 205 | * @see controller/common/catalog/import/csv/max-size |
| 206 | 206 | */ |
| 207 | - $converters = $config->get( 'controller/jobs/catalog/import/csv/converter', $converters ); |
|
| 207 | + $converters = $config->get('controller/jobs/catalog/import/csv/converter', $converters); |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | /** controller/common/catalog/import/csv/max-size |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @see controller/common/catalog/import/csv/mapping |
| 225 | 225 | * @see controller/common/catalog/import/csv/converter |
| 226 | 226 | */ |
| 227 | - $maxcnt = (int) $config->get( 'controller/common/catalog/import/csv/max-size', 1000 ); |
|
| 227 | + $maxcnt = (int) $config->get('controller/common/catalog/import/csv/max-size', 1000); |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | /** controller/jobs/catalog/import/csv/skip-lines |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @see controller/jobs/catalog/import/csv/backup |
| 247 | 247 | * @see controller/common/catalog/import/csv/max-size |
| 248 | 248 | */ |
| 249 | - $skiplines = (int) $config->get( 'controller/jobs/catalog/import/csv/skip-lines', 0 ); |
|
| 249 | + $skiplines = (int) $config->get('controller/jobs/catalog/import/csv/skip-lines', 0); |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | 252 | /** controller/jobs/catalog/import/csv/strict |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @see controller/jobs/catalog/import/csv/backup |
| 271 | 271 | * @see controller/common/catalog/import/csv/max-size |
| 272 | 272 | */ |
| 273 | - $strict = (bool) $config->get( 'controller/jobs/catalog/import/csv/strict', true ); |
|
| 273 | + $strict = (bool) $config->get('controller/jobs/catalog/import/csv/strict', true); |
|
| 274 | 274 | |
| 275 | 275 | |
| 276 | 276 | /** controller/jobs/catalog/import/csv/backup |
@@ -303,75 +303,75 @@ discard block |
||
| 303 | 303 | * @see controller/jobs/catalog/import/csv/strict |
| 304 | 304 | * @see controller/common/catalog/import/csv/max-size |
| 305 | 305 | */ |
| 306 | - $backup = $config->get( 'controller/jobs/catalog/import/csv/backup' ); |
|
| 306 | + $backup = $config->get('controller/jobs/catalog/import/csv/backup'); |
|
| 307 | 307 | |
| 308 | 308 | |
| 309 | - if( !isset( $mappings['item'] ) || !is_array( $mappings['item'] ) ) |
|
| 309 | + if (!isset($mappings['item']) || !is_array($mappings['item'])) |
|
| 310 | 310 | { |
| 311 | - $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
|
| 312 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 311 | + $msg = sprintf('Required mapping key "%1$s" is missing or contains no array', 'item'); |
|
| 312 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | try |
| 316 | 316 | { |
| 317 | 317 | $procMappings = $mappings; |
| 318 | - unset( $procMappings['item'] ); |
|
| 318 | + unset($procMappings['item']); |
|
| 319 | 319 | |
| 320 | - $codePos = $this->getCodePosition( $mappings['item'] ); |
|
| 321 | - $convlist = $this->getConverterList( $converters ); |
|
| 322 | - $processor = $this->getProcessors( $procMappings ); |
|
| 323 | - $catalogMap = $this->getCatalogMap( $domains ); |
|
| 320 | + $codePos = $this->getCodePosition($mappings['item']); |
|
| 321 | + $convlist = $this->getConverterList($converters); |
|
| 322 | + $processor = $this->getProcessors($procMappings); |
|
| 323 | + $catalogMap = $this->getCatalogMap($domains); |
|
| 324 | 324 | $container = $this->getContainer(); |
| 325 | 325 | $path = $container->getName(); |
| 326 | 326 | |
| 327 | 327 | |
| 328 | - $msg = sprintf( 'Started catalog import from "%1$s" (%2$s)', $path, __CLASS__ ); |
|
| 329 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 328 | + $msg = sprintf('Started catalog import from "%1$s" (%2$s)', $path, __CLASS__); |
|
| 329 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
| 330 | 330 | |
| 331 | - foreach( $container as $content ) |
|
| 331 | + foreach ($container as $content) |
|
| 332 | 332 | { |
| 333 | 333 | $name = $content->getName(); |
| 334 | 334 | |
| 335 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
| 335 | + for ($i = 0; $i < $skiplines; $i++) { |
|
| 336 | 336 | $content->next(); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
| 339 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
| 340 | 340 | { |
| 341 | - $data = $this->convertData( $convlist, $data ); |
|
| 342 | - $errcnt = $this->import( $catalogMap, $data, $mappings['item'], $processor, $strict ); |
|
| 343 | - $chunkcnt = count( $data ); |
|
| 341 | + $data = $this->convertData($convlist, $data); |
|
| 342 | + $errcnt = $this->import($catalogMap, $data, $mappings['item'], $processor, $strict); |
|
| 343 | + $chunkcnt = count($data); |
|
| 344 | 344 | |
| 345 | 345 | $msg = 'Imported catalog lines from "%1$s": %2$d/%3$d (%4$s)'; |
| 346 | - $logger->log( sprintf( $msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 346 | + $logger->log(sprintf($msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 347 | 347 | |
| 348 | 348 | $errors += $errcnt; |
| 349 | 349 | $total += $chunkcnt; |
| 350 | - unset( $data ); |
|
| 350 | + unset($data); |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | $container->close(); |
| 355 | 355 | } |
| 356 | - catch( \Exception $e ) |
|
| 356 | + catch (\Exception $e) |
|
| 357 | 357 | { |
| 358 | - $logger->log( 'Catalog import error: ' . $e->getMessage() ); |
|
| 359 | - $logger->log( $e->getTraceAsString() ); |
|
| 358 | + $logger->log('Catalog import error: ' . $e->getMessage()); |
|
| 359 | + $logger->log($e->getTraceAsString()); |
|
| 360 | 360 | |
| 361 | - throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
|
| 361 | + throw new \Aimeos\Controller\Jobs\Exception($e->getMessage()); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | $msg = 'Finished catalog import from "%1$s": %2$d successful, %3$s errors, %4$s total (%5$s)'; |
| 365 | - $logger->log( sprintf( $msg, $path, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 365 | + $logger->log(sprintf($msg, $path, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 366 | 366 | |
| 367 | - if( $errors > 0 ) |
|
| 367 | + if ($errors > 0) |
|
| 368 | 368 | { |
| 369 | - $msg = sprintf( 'Invalid catalog lines in "%1$s": %2$d/%3$d', $path, $errors, $total ); |
|
| 370 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 369 | + $msg = sprintf('Invalid catalog lines in "%1$s": %2$d/%3$d', $path, $errors, $total); |
|
| 370 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if( !empty( $backup ) && @rename( $path, strftime( $backup ) ) === false ) { |
|
| 374 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Unable to move imported file' ) ); |
|
| 373 | + if (!empty($backup) && @rename($path, strftime($backup)) === false) { |
|
| 374 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to move imported file')); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
@@ -383,16 +383,16 @@ discard block |
||
| 383 | 383 | * @return integer Position of the "catalog.code" column |
| 384 | 384 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "catalog.code" is found |
| 385 | 385 | */ |
| 386 | - protected function getCodePosition( array $mapping ) |
|
| 386 | + protected function getCodePosition(array $mapping) |
|
| 387 | 387 | { |
| 388 | - foreach( $mapping as $pos => $key ) |
|
| 388 | + foreach ($mapping as $pos => $key) |
|
| 389 | 389 | { |
| 390 | - if( $key === 'catalog.code' ) { |
|
| 390 | + if ($key === 'catalog.code') { |
|
| 391 | 391 | return $pos; |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "catalog.code" column in CSV mapping found' ) ); |
|
| 395 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "catalog.code" column in CSV mapping found')); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @see controller/jobs/catalog/import/csv/container/content |
| 428 | 428 | * @see controller/jobs/catalog/import/csv/container/options |
| 429 | 429 | */ |
| 430 | - $location = $config->get( 'controller/jobs/catalog/import/csv/location', '.' ); |
|
| 430 | + $location = $config->get('controller/jobs/catalog/import/csv/location', '.'); |
|
| 431 | 431 | |
| 432 | 432 | /** controller/jobs/catalog/import/csv/container/type |
| 433 | 433 | * Nave of the container type to read the data from |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | * @see controller/jobs/catalog/import/csv/container/content |
| 451 | 451 | * @see controller/jobs/catalog/import/csv/container/options |
| 452 | 452 | */ |
| 453 | - $container = $config->get( 'controller/jobs/catalog/import/csv/container/type', 'Directory' ); |
|
| 453 | + $container = $config->get('controller/jobs/catalog/import/csv/container/type', 'Directory'); |
|
| 454 | 454 | |
| 455 | 455 | /** controller/jobs/catalog/import/csv/container/content |
| 456 | 456 | * Name of the content type inside the container to read the data from |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | * @see controller/jobs/catalog/import/csv/container/type |
| 472 | 472 | * @see controller/jobs/catalog/import/csv/container/options |
| 473 | 473 | */ |
| 474 | - $content = $config->get( 'controller/jobs/catalog/import/csv/container/content', 'CSV' ); |
|
| 474 | + $content = $config->get('controller/jobs/catalog/import/csv/container/content', 'CSV'); |
|
| 475 | 475 | |
| 476 | 476 | /** controller/jobs/catalog/import/csv/container/options |
| 477 | 477 | * List of file container options for the catalog import files |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | * @see controller/jobs/catalog/import/csv/container/content |
| 490 | 490 | * @see controller/jobs/catalog/import/csv/container/type |
| 491 | 491 | */ |
| 492 | - $options = $config->get( 'controller/jobs/catalog/import/csv/container/options', [] ); |
|
| 492 | + $options = $config->get('controller/jobs/catalog/import/csv/container/options', []); |
|
| 493 | 493 | |
| 494 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
| 494 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | |
@@ -501,13 +501,13 @@ discard block |
||
| 501 | 501 | * @param array $domains List of domain names whose items should be fetched too |
| 502 | 502 | * @return array Associative list of catalog codes as keys and items implementing \Aimeos\MShop\Catalog\Item\Iface as values |
| 503 | 503 | */ |
| 504 | - protected function getCatalogMap( array $domains ) |
|
| 504 | + protected function getCatalogMap(array $domains) |
|
| 505 | 505 | { |
| 506 | 506 | $map = []; |
| 507 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' ); |
|
| 508 | - $search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
|
| 507 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog'); |
|
| 508 | + $search = $manager->createSearch()->setSlice(0, 0x7fffffff); |
|
| 509 | 509 | |
| 510 | - foreach( $manager->searchItems( $search, $domains ) as $item ) { |
|
| 510 | + foreach ($manager->searchItems($search, $domains) as $item) { |
|
| 511 | 511 | $map[$item->getCode()] = $item; |
| 512 | 512 | } |
| 513 | 513 | |
@@ -523,23 +523,23 @@ discard block |
||
| 523 | 523 | * @param string $code Catalog item code of the parent category |
| 524 | 524 | * @return string|null ID of the parent category or null for top level nodes |
| 525 | 525 | */ |
| 526 | - protected function getParentId( array $catalogMap, array $map, $code ) |
|
| 526 | + protected function getParentId(array $catalogMap, array $map, $code) |
|
| 527 | 527 | { |
| 528 | - if( !isset( $map['catalog.parent'] ) ) |
|
| 528 | + if (!isset($map['catalog.parent'])) |
|
| 529 | 529 | { |
| 530 | - $msg = sprintf( 'Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code ); |
|
| 531 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 530 | + $msg = sprintf('Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code); |
|
| 531 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - $parent = trim( $map['catalog.parent'] ); |
|
| 534 | + $parent = trim($map['catalog.parent']); |
|
| 535 | 535 | |
| 536 | - if( $parent != '' && !isset( $catalogMap[$parent] ) ) |
|
| 536 | + if ($parent != '' && !isset($catalogMap[$parent])) |
|
| 537 | 537 | { |
| 538 | - $msg = sprintf( 'Parent node for code "%1$s" not found', $parent ); |
|
| 539 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 538 | + $msg = sprintf('Parent node for code "%1$s" not found', $parent); |
|
| 539 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - return ( $parent != '' ? $catalogMap[$parent]->getId() : null ); |
|
| 542 | + return ($parent != '' ? $catalogMap[$parent]->getId() : null); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
@@ -554,63 +554,63 @@ discard block |
||
| 554 | 554 | * @return integer Number of catalogs that couldn't be imported |
| 555 | 555 | * @throws \Aimeos\Controller\Jobs\Exception |
| 556 | 556 | */ |
| 557 | - protected function import( array &$catalogMap, array $data, array $mapping, |
|
| 558 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict ) |
|
| 557 | + protected function import(array &$catalogMap, array $data, array $mapping, |
|
| 558 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict) |
|
| 559 | 559 | { |
| 560 | 560 | $errors = 0; |
| 561 | 561 | $context = $this->getContext(); |
| 562 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
|
| 562 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
| 563 | 563 | |
| 564 | - foreach( $data as $code => $list ) |
|
| 564 | + foreach ($data as $code => $list) |
|
| 565 | 565 | { |
| 566 | 566 | $manager->begin(); |
| 567 | 567 | |
| 568 | 568 | try |
| 569 | 569 | { |
| 570 | - $code = trim( $code ); |
|
| 570 | + $code = trim($code); |
|
| 571 | 571 | |
| 572 | - if( isset( $catalogMap[$code] ) ) { |
|
| 572 | + if (isset($catalogMap[$code])) { |
|
| 573 | 573 | $catalogItem = $catalogMap[$code]; |
| 574 | 574 | } else { |
| 575 | 575 | $catalogItem = $manager->createItem(); |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
| 578 | + $map = $this->getMappedChunk($list, $mapping); |
|
| 579 | 579 | |
| 580 | - if( isset( $map[0] ) ) |
|
| 580 | + if (isset($map[0])) |
|
| 581 | 581 | { |
| 582 | 582 | $map = $map[0]; // there can only be one chunk for the base catalog data |
| 583 | - $parentid = $this->getParentId( $catalogMap, $map, $code ); |
|
| 584 | - $catalogItem->fromArray( $this->addItemDefaults( $map ) ); |
|
| 583 | + $parentid = $this->getParentId($catalogMap, $map, $code); |
|
| 584 | + $catalogItem->fromArray($this->addItemDefaults($map)); |
|
| 585 | 585 | |
| 586 | - if( isset( $catalogMap[$code] ) ) |
|
| 586 | + if (isset($catalogMap[$code])) |
|
| 587 | 587 | { |
| 588 | - $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
|
| 589 | - $catalogItem = $manager->saveItem( $catalogItem ); |
|
| 588 | + $manager->moveItem($catalogItem->getId(), $catalogItem->getParentId(), $parentid); |
|
| 589 | + $catalogItem = $manager->saveItem($catalogItem); |
|
| 590 | 590 | } |
| 591 | 591 | else |
| 592 | 592 | { |
| 593 | - $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
|
| 593 | + $catalogItem = $manager->insertItem($catalogItem, $parentid); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - $list = $processor->process( $catalogItem, $list ); |
|
| 596 | + $list = $processor->process($catalogItem, $list); |
|
| 597 | 597 | $catalogMap[$code] = $catalogItem; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | $manager->commit(); |
| 601 | 601 | } |
| 602 | - catch( \Exception $e ) |
|
| 602 | + catch (\Exception $e) |
|
| 603 | 603 | { |
| 604 | 604 | $manager->rollback(); |
| 605 | 605 | |
| 606 | - $msg = sprintf( 'Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
| 607 | - $context->getLogger()->log( $msg ); |
|
| 606 | + $msg = sprintf('Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage()); |
|
| 607 | + $context->getLogger()->log($msg); |
|
| 608 | 608 | |
| 609 | 609 | $errors++; |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - if( $strict && !empty( $list ) ) { |
|
| 613 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
| 612 | + if ($strict && !empty($list)) { |
|
| 613 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
@@ -624,9 +624,9 @@ discard block |
||
| 624 | 624 | * @param array $list Associative list of domain item keys and their values, e.g. "catalog.status" => 1 |
| 625 | 625 | * @return array Given associative list enriched by default values if they were not already set |
| 626 | 626 | */ |
| 627 | - protected function addItemDefaults( array $list ) |
|
| 627 | + protected function addItemDefaults(array $list) |
|
| 628 | 628 | { |
| 629 | - if( !isset( $list['catalog.status'] ) ) { |
|
| 629 | + if (!isset($list['catalog.status'])) { |
|
| 630 | 630 | $list['catalog.status'] = 1; |
| 631 | 631 | } |
| 632 | 632 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function getName() |
| 30 | 30 | { |
| 31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product import CSV' ); |
|
| 31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Product import CSV'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function getDescription() |
| 41 | 41 | { |
| 42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Imports new and updates existing products from CSV files' ); |
|
| 42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing products from CSV files'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $context = $this->getContext(); |
| 55 | 55 | $config = $context->getConfig(); |
| 56 | 56 | $logger = $context->getLogger(); |
| 57 | - $domains = array( 'attribute', 'media', 'price', 'product', 'text' ); |
|
| 57 | + $domains = array('attribute', 'media', 'price', 'product', 'text'); |
|
| 58 | 58 | $mappings = $this->getDefaultMapping(); |
| 59 | 59 | |
| 60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @see controller/common/product/import/csv/converter |
| 75 | 75 | * @see controller/common/product/import/csv/max-size |
| 76 | 76 | */ |
| 77 | - $domains = $config->get( 'controller/common/product/import/csv/domains', $domains ); |
|
| 77 | + $domains = $config->get('controller/common/product/import/csv/domains', $domains); |
|
| 78 | 78 | |
| 79 | 79 | /** controller/jobs/product/import/csv/domains |
| 80 | 80 | * List of item domain names that should be retrieved along with the product items |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @see controller/jobs/product/import/csv/backup |
| 95 | 95 | * @see controller/common/product/import/csv/max-size |
| 96 | 96 | */ |
| 97 | - $domains = $config->get( 'controller/jobs/product/import/csv/domains', $domains ); |
|
| 97 | + $domains = $config->get('controller/jobs/product/import/csv/domains', $domains); |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /** controller/common/product/import/csv/mapping |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @see controller/common/product/import/csv/converter |
| 123 | 123 | * @see controller/common/product/import/csv/max-size |
| 124 | 124 | */ |
| 125 | - $mappings = $config->get( 'controller/common/product/import/csv/mapping', $mappings ); |
|
| 125 | + $mappings = $config->get('controller/common/product/import/csv/mapping', $mappings); |
|
| 126 | 126 | |
| 127 | 127 | /** controller/jobs/product/import/csv/mapping |
| 128 | 128 | * List of mappings between the position in the CSV file and item keys |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @see controller/jobs/product/import/csv/backup |
| 143 | 143 | * @see controller/common/product/import/csv/max-size |
| 144 | 144 | */ |
| 145 | - $mappings = $config->get( 'controller/jobs/product/import/csv/mapping', $mappings ); |
|
| 145 | + $mappings = $config->get('controller/jobs/product/import/csv/mapping', $mappings); |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | /** controller/common/product/import/csv/converter |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @see controller/common/product/import/csv/mapping |
| 185 | 185 | * @see controller/common/product/import/csv/max-size |
| 186 | 186 | */ |
| 187 | - $converters = $config->get( 'controller/common/product/import/csv/converter', [] ); |
|
| 187 | + $converters = $config->get('controller/common/product/import/csv/converter', []); |
|
| 188 | 188 | |
| 189 | 189 | /** controller/jobs/product/import/csv/converter |
| 190 | 190 | * List of converter names for the values at the position in the CSV file |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @see controller/jobs/product/import/csv/backup |
| 205 | 205 | * @see controller/common/product/import/csv/max-size |
| 206 | 206 | */ |
| 207 | - $converters = $config->get( 'controller/jobs/product/import/csv/converter', $converters ); |
|
| 207 | + $converters = $config->get('controller/jobs/product/import/csv/converter', $converters); |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | /** controller/common/product/import/csv/max-size |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @see controller/common/product/import/csv/mapping |
| 225 | 225 | * @see controller/common/product/import/csv/converter |
| 226 | 226 | */ |
| 227 | - $maxcnt = (int) $config->get( 'controller/common/product/import/csv/max-size', 1000 ); |
|
| 227 | + $maxcnt = (int) $config->get('controller/common/product/import/csv/max-size', 1000); |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | /** controller/jobs/product/import/csv/skip-lines |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @see controller/jobs/product/import/csv/backup |
| 247 | 247 | * @see controller/common/product/import/csv/max-size |
| 248 | 248 | */ |
| 249 | - $skiplines = (int) $config->get( 'controller/jobs/product/import/csv/skip-lines', 0 ); |
|
| 249 | + $skiplines = (int) $config->get('controller/jobs/product/import/csv/skip-lines', 0); |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | 252 | /** controller/jobs/product/import/csv/strict |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @see controller/jobs/product/import/csv/backup |
| 271 | 271 | * @see controller/common/product/import/csv/max-size |
| 272 | 272 | */ |
| 273 | - $strict = (bool) $config->get( 'controller/jobs/product/import/csv/strict', true ); |
|
| 273 | + $strict = (bool) $config->get('controller/jobs/product/import/csv/strict', true); |
|
| 274 | 274 | |
| 275 | 275 | |
| 276 | 276 | /** controller/jobs/product/import/csv/backup |
@@ -303,74 +303,74 @@ discard block |
||
| 303 | 303 | * @see controller/jobs/product/import/csv/strict |
| 304 | 304 | * @see controller/common/product/import/csv/max-size |
| 305 | 305 | */ |
| 306 | - $backup = $config->get( 'controller/jobs/product/import/csv/backup' ); |
|
| 306 | + $backup = $config->get('controller/jobs/product/import/csv/backup'); |
|
| 307 | 307 | |
| 308 | 308 | |
| 309 | - if( !isset( $mappings['item'] ) || !is_array( $mappings['item'] ) ) |
|
| 309 | + if (!isset($mappings['item']) || !is_array($mappings['item'])) |
|
| 310 | 310 | { |
| 311 | - $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
|
| 312 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 311 | + $msg = sprintf('Required mapping key "%1$s" is missing or contains no array', 'item'); |
|
| 312 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | try |
| 316 | 316 | { |
| 317 | 317 | $procMappings = $mappings; |
| 318 | - unset( $procMappings['item'] ); |
|
| 318 | + unset($procMappings['item']); |
|
| 319 | 319 | |
| 320 | - $codePos = $this->getCodePosition( $mappings['item'] ); |
|
| 321 | - $convlist = $this->getConverterList( $converters ); |
|
| 322 | - $processor = $this->getProcessors( $procMappings ); |
|
| 320 | + $codePos = $this->getCodePosition($mappings['item']); |
|
| 321 | + $convlist = $this->getConverterList($converters); |
|
| 322 | + $processor = $this->getProcessors($procMappings); |
|
| 323 | 323 | $container = $this->getContainer(); |
| 324 | 324 | $path = $container->getName(); |
| 325 | 325 | |
| 326 | - $msg = sprintf( 'Started product import from "%1$s" (%2$s)', $path, __CLASS__ ); |
|
| 327 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 326 | + $msg = sprintf('Started product import from "%1$s" (%2$s)', $path, __CLASS__); |
|
| 327 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
| 328 | 328 | |
| 329 | - foreach( $container as $content ) |
|
| 329 | + foreach ($container as $content) |
|
| 330 | 330 | { |
| 331 | 331 | $name = $content->getName(); |
| 332 | 332 | |
| 333 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
| 333 | + for ($i = 0; $i < $skiplines; $i++) { |
|
| 334 | 334 | $content->next(); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
| 337 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
| 338 | 338 | { |
| 339 | - $data = $this->convertData( $convlist, $data ); |
|
| 340 | - $products = $this->getProducts( array_keys( $data ), $domains ); |
|
| 341 | - $errcnt = $this->import( $products, $data, $mappings['item'], $processor, $strict ); |
|
| 342 | - $chunkcnt = count( $data ); |
|
| 339 | + $data = $this->convertData($convlist, $data); |
|
| 340 | + $products = $this->getProducts(array_keys($data), $domains); |
|
| 341 | + $errcnt = $this->import($products, $data, $mappings['item'], $processor, $strict); |
|
| 342 | + $chunkcnt = count($data); |
|
| 343 | 343 | |
| 344 | 344 | $msg = 'Imported product lines from "%1$s": %2$d/%3$d (%4$s)'; |
| 345 | - $logger->log( sprintf( $msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 345 | + $logger->log(sprintf($msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 346 | 346 | |
| 347 | 347 | $errors += $errcnt; |
| 348 | 348 | $total += $chunkcnt; |
| 349 | - unset( $products, $data ); |
|
| 349 | + unset($products, $data); |
|
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | $container->close(); |
| 354 | 354 | } |
| 355 | - catch( \Exception $e ) |
|
| 355 | + catch (\Exception $e) |
|
| 356 | 356 | { |
| 357 | - $logger->log( 'Product import error: ' . $e->getMessage() ); |
|
| 358 | - $logger->log( $e->getTraceAsString() ); |
|
| 357 | + $logger->log('Product import error: ' . $e->getMessage()); |
|
| 358 | + $logger->log($e->getTraceAsString()); |
|
| 359 | 359 | |
| 360 | - throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
|
| 360 | + throw new \Aimeos\Controller\Jobs\Exception($e->getMessage()); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $msg = 'Finished product import from "%1$s": %2$d successful, %3$s errors, %4$s total (%5$s)'; |
| 364 | - $logger->log( sprintf( $msg, $path, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 364 | + $logger->log(sprintf($msg, $path, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 365 | 365 | |
| 366 | - if( $errors > 0 ) |
|
| 366 | + if ($errors > 0) |
|
| 367 | 367 | { |
| 368 | - $msg = sprintf( 'Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total ); |
|
| 369 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 368 | + $msg = sprintf('Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total); |
|
| 369 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - if( !empty( $backup ) && @rename( $path, strftime( $backup ) ) === false ) { |
|
| 373 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Unable to move imported file' ) ); |
|
| 372 | + if (!empty($backup) && @rename($path, strftime($backup)) === false) { |
|
| 373 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to move imported file')); |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
@@ -382,16 +382,16 @@ discard block |
||
| 382 | 382 | * @return integer Position of the "product.code" column |
| 383 | 383 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "product.code" is found |
| 384 | 384 | */ |
| 385 | - protected function getCodePosition( array $mapping ) |
|
| 385 | + protected function getCodePosition(array $mapping) |
|
| 386 | 386 | { |
| 387 | - foreach( $mapping as $pos => $key ) |
|
| 387 | + foreach ($mapping as $pos => $key) |
|
| 388 | 388 | { |
| 389 | - if( $key === 'product.code' ) { |
|
| 389 | + if ($key === 'product.code') { |
|
| 390 | 390 | return $pos; |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) ); |
|
| 394 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "product.code" column in CSV mapping found')); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * @see controller/jobs/product/import/csv/container/content |
| 427 | 427 | * @see controller/jobs/product/import/csv/container/options |
| 428 | 428 | */ |
| 429 | - $location = $config->get( 'controller/jobs/product/import/csv/location', '.' ); |
|
| 429 | + $location = $config->get('controller/jobs/product/import/csv/location', '.'); |
|
| 430 | 430 | |
| 431 | 431 | /** controller/jobs/product/import/csv/container/type |
| 432 | 432 | * Nave of the container type to read the data from |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * @see controller/jobs/product/import/csv/container/content |
| 450 | 450 | * @see controller/jobs/product/import/csv/container/options |
| 451 | 451 | */ |
| 452 | - $container = $config->get( 'controller/jobs/product/import/csv/container/type', 'Directory' ); |
|
| 452 | + $container = $config->get('controller/jobs/product/import/csv/container/type', 'Directory'); |
|
| 453 | 453 | |
| 454 | 454 | /** controller/jobs/product/import/csv/container/content |
| 455 | 455 | * Name of the content type inside the container to read the data from |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | * @see controller/jobs/product/import/csv/container/type |
| 471 | 471 | * @see controller/jobs/product/import/csv/container/options |
| 472 | 472 | */ |
| 473 | - $content = $config->get( 'controller/jobs/product/import/csv/container/content', 'CSV' ); |
|
| 473 | + $content = $config->get('controller/jobs/product/import/csv/container/content', 'CSV'); |
|
| 474 | 474 | |
| 475 | 475 | /** controller/jobs/product/import/csv/container/options |
| 476 | 476 | * List of file container options for the product import files |
@@ -488,9 +488,9 @@ discard block |
||
| 488 | 488 | * @see controller/jobs/product/import/csv/container/content |
| 489 | 489 | * @see controller/jobs/product/import/csv/container/type |
| 490 | 490 | */ |
| 491 | - $options = $config->get( 'controller/jobs/product/import/csv/container/options', [] ); |
|
| 491 | + $options = $config->get('controller/jobs/product/import/csv/container/options', []); |
|
| 492 | 492 | |
| 493 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
| 493 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | |
@@ -505,56 +505,56 @@ discard block |
||
| 505 | 505 | * @return integer Number of products that couldn't be imported |
| 506 | 506 | * @throws \Aimeos\Controller\Jobs\Exception |
| 507 | 507 | */ |
| 508 | - protected function import( array $products, array $data, array $mapping, |
|
| 509 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict ) |
|
| 508 | + protected function import(array $products, array $data, array $mapping, |
|
| 509 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict) |
|
| 510 | 510 | { |
| 511 | 511 | $errors = 0; |
| 512 | 512 | $context = $this->getContext(); |
| 513 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
| 513 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
| 514 | 514 | |
| 515 | - foreach( $data as $code => $list ) |
|
| 515 | + foreach ($data as $code => $list) |
|
| 516 | 516 | { |
| 517 | 517 | $manager->begin(); |
| 518 | 518 | |
| 519 | 519 | try |
| 520 | 520 | { |
| 521 | - $code = trim( $code ); |
|
| 521 | + $code = trim($code); |
|
| 522 | 522 | |
| 523 | - if( isset( $products[$code] ) ) { |
|
| 523 | + if (isset($products[$code])) { |
|
| 524 | 524 | $product = $products[$code]; |
| 525 | 525 | } else { |
| 526 | 526 | $product = $manager->createItem(); |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
| 529 | + $map = $this->getMappedChunk($list, $mapping); |
|
| 530 | 530 | |
| 531 | - if( isset( $map[0] ) ) |
|
| 531 | + if (isset($map[0])) |
|
| 532 | 532 | { |
| 533 | 533 | $map = $map[0]; // there can only be one chunk for the base product data |
| 534 | 534 | |
| 535 | - $typecode = trim( isset( $map['product.type'] ) ? $map['product.type'] : 'default' ); |
|
| 536 | - $map['product.typeid'] = $this->getTypeId( 'product/type', 'product', $typecode ); |
|
| 535 | + $typecode = trim(isset($map['product.type']) ? $map['product.type'] : 'default'); |
|
| 536 | + $map['product.typeid'] = $this->getTypeId('product/type', 'product', $typecode); |
|
| 537 | 537 | |
| 538 | - $product->fromArray( $this->addItemDefaults( $map ) ); |
|
| 539 | - $product = $manager->saveItem( $product ); |
|
| 538 | + $product->fromArray($this->addItemDefaults($map)); |
|
| 539 | + $product = $manager->saveItem($product); |
|
| 540 | 540 | |
| 541 | - $list = $processor->process( $product, $list ); |
|
| 541 | + $list = $processor->process($product, $list); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | $manager->commit(); |
| 545 | 545 | } |
| 546 | - catch( \Exception $e ) |
|
| 546 | + catch (\Exception $e) |
|
| 547 | 547 | { |
| 548 | 548 | $manager->rollback(); |
| 549 | 549 | |
| 550 | - $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
| 551 | - $context->getLogger()->log( $msg ); |
|
| 550 | + $msg = sprintf('Unable to import product with code "%1$s": %2$s', $code, $e->getMessage()); |
|
| 551 | + $context->getLogger()->log($msg); |
|
| 552 | 552 | |
| 553 | 553 | $errors++; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - if( $strict && !empty( $list ) ) { |
|
| 557 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
| 556 | + if ($strict && !empty($list)) { |
|
| 557 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
@@ -568,9 +568,9 @@ discard block |
||
| 568 | 568 | * @param array $list Associative list of domain item keys and their values, e.g. "product.status" => 1 |
| 569 | 569 | * @return array Given associative list enriched by default values if they were not already set |
| 570 | 570 | */ |
| 571 | - protected function addItemDefaults( array $list ) |
|
| 571 | + protected function addItemDefaults(array $list) |
|
| 572 | 572 | { |
| 573 | - if( !isset( $list['product.status'] ) ) { |
|
| 573 | + if (!isset($list['product.status'])) { |
|
| 574 | 574 | $list['product.status'] = 1; |
| 575 | 575 | } |
| 576 | 576 | |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | 50 | /** controller/common/catalog/import/csv/processor/text/listtypes |
| 51 | 51 | * Names of the catalog list types for texts that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @see controller/common/catalog/import/csv/processor/price/listtypes |
| 67 | 67 | * @see controller/common/catalog/import/csv/processor/catalog/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/catalog/import/csv/processor/text/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/catalog/import/csv/processor/text/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,40 +77,40 @@ discard block |
||
| 77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
| 78 | 78 | * @return array List of data which hasn't been imported |
| 79 | 79 | */ |
| 80 | - public function process( \Aimeos\MShop\Catalog\Item\Iface $catalog, array $data ) |
|
| 80 | + public function process(\Aimeos\MShop\Catalog\Item\Iface $catalog, array $data) |
|
| 81 | 81 | { |
| 82 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
|
| 83 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'text' ); |
|
| 82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists'); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'text'); |
|
| 84 | 84 | $manager->begin(); |
| 85 | 85 | |
| 86 | 86 | try |
| 87 | 87 | { |
| 88 | 88 | $delete = $listMap = []; |
| 89 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 90 | - $listItems = $catalog->getListItems( 'text', $this->listTypes ); |
|
| 89 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 90 | + $listItems = $catalog->getListItems('text', $this->listTypes); |
|
| 91 | 91 | |
| 92 | - foreach( $listItems as $listItem ) |
|
| 92 | + foreach ($listItems as $listItem) |
|
| 93 | 93 | { |
| 94 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 95 | - $listMap[ $refItem->getContent() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
| 94 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 95 | + $listMap[$refItem->getContent()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - foreach( $map as $pos => $list ) |
|
| 99 | + foreach ($map as $pos => $list) |
|
| 100 | 100 | { |
| 101 | - if( $this->checkEntry( $list ) === false ) { |
|
| 101 | + if ($this->checkEntry($list) === false) { |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $content = trim( $list['text.content'] ); |
|
| 106 | - $type = trim( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
|
| 107 | - $typecode = trim( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
|
| 105 | + $content = trim($list['text.content']); |
|
| 106 | + $type = trim(isset($list['text.type']) ? $list['text.type'] : 'name'); |
|
| 107 | + $typecode = trim(isset($list['catalog.lists.type']) ? $list['catalog.lists.type'] : 'default'); |
|
| 108 | 108 | |
| 109 | - if( isset( $listMap[$content][$type][$typecode] ) ) |
|
| 109 | + if (isset($listMap[$content][$type][$typecode])) |
|
| 110 | 110 | { |
| 111 | 111 | $listItem = $listMap[$content][$type][$typecode]; |
| 112 | 112 | $refItem = $listItem->getRefItem(); |
| 113 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 113 | + unset($listItems[$listItem->getId()]); |
|
| 114 | 114 | } |
| 115 | 115 | else |
| 116 | 116 | { |
@@ -118,33 +118,33 @@ discard block |
||
| 118 | 118 | $refItem = $manager->createItem(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $list['text.typeid'] = $this->getTypeId( 'text/type', 'catalog', $type ); |
|
| 121 | + $list['text.typeid'] = $this->getTypeId('text/type', 'catalog', $type); |
|
| 122 | 122 | $list['text.domain'] = 'catalog'; |
| 123 | 123 | |
| 124 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 125 | - $refItem = $manager->saveItem( $refItem ); |
|
| 124 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 125 | + $refItem = $manager->saveItem($refItem); |
|
| 126 | 126 | |
| 127 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'text', $typecode ); |
|
| 127 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'text', $typecode); |
|
| 128 | 128 | $list['catalog.lists.parentid'] = $catalog->getId(); |
| 129 | 129 | $list['catalog.lists.refid'] = $refItem->getId(); |
| 130 | 130 | $list['catalog.lists.domain'] = 'text'; |
| 131 | 131 | |
| 132 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 133 | - $listManager->saveItem( $listItem, false ); |
|
| 132 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 133 | + $listManager->saveItem($listItem, false); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - foreach( $listItems as $listItem ) { |
|
| 136 | + foreach ($listItems as $listItem) { |
|
| 137 | 137 | $delete[] = $listItem->getRefId(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $manager->deleteItems( $delete ); |
|
| 141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 140 | + $manager->deleteItems($delete); |
|
| 141 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 142 | 142 | |
| 143 | - $data = $this->getObject()->process( $catalog, $data ); |
|
| 143 | + $data = $this->getObject()->process($catalog, $data); |
|
| 144 | 144 | |
| 145 | 145 | $manager->commit(); |
| 146 | 146 | } |
| 147 | - catch( \Exception $e ) |
|
| 147 | + catch (\Exception $e) |
|
| 148 | 148 | { |
| 149 | 149 | $manager->rollback(); |
| 150 | 150 | throw $e; |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | * @param array $list Associative list of domain item keys and their values, e.g. "text.status" => 1 |
| 161 | 161 | * @return array Given associative list enriched by default values if they were not already set |
| 162 | 162 | */ |
| 163 | - protected function addItemDefaults( array $list ) |
|
| 163 | + protected function addItemDefaults(array $list) |
|
| 164 | 164 | { |
| 165 | - if( !isset( $list['text.label'] ) ) { |
|
| 166 | - $list['text.label'] = mb_strcut( trim( $list['text.content'] ), 0, 255 ); |
|
| 165 | + if (!isset($list['text.label'])) { |
|
| 166 | + $list['text.label'] = mb_strcut(trim($list['text.content']), 0, 255); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if( !isset( $list['text.languageid'] ) ) { |
|
| 169 | + if (!isset($list['text.languageid'])) { |
|
| 170 | 170 | $list['text.languageid'] = $this->getContext()->getLocale()->getLanguageId(); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if( !isset( $list['text.status'] ) ) { |
|
| 173 | + if (!isset($list['text.status'])) { |
|
| 174 | 174 | $list['text.status'] = 1; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * @param array $list Associative list of key/value pairs from the mapping |
| 185 | 185 | * @return boolean True if valid, false if not |
| 186 | 186 | */ |
| 187 | - protected function checkEntry( array $list ) |
|
| 187 | + protected function checkEntry(array $list) |
|
| 188 | 188 | { |
| 189 | - if( !isset( $list['text.content'] ) || trim( $list['text.content'] ) === '' || isset( $list['catalog.lists.type'] ) |
|
| 190 | - && $this->listTypes !== null && !in_array( trim( $list['catalog.lists.type'] ), (array) $this->listTypes ) |
|
| 189 | + if (!isset($list['text.content']) || trim($list['text.content']) === '' || isset($list['catalog.lists.type']) |
|
| 190 | + && $this->listTypes !== null && !in_array(trim($list['catalog.lists.type']), (array) $this->listTypes) |
|
| 191 | 191 | ) { |
| 192 | 192 | return false; |
| 193 | 193 | } |
@@ -111,8 +111,7 @@ discard block |
||
| 111 | 111 | $listItem = $listMap[$content][$type][$typecode]; |
| 112 | 112 | $refItem = $listItem->getRefItem(); |
| 113 | 113 | unset( $listItems[ $listItem->getId() ] ); |
| 114 | - } |
|
| 115 | - else |
|
| 114 | + } else |
|
| 116 | 115 | { |
| 117 | 116 | $listItem = $listManager->createItem(); |
| 118 | 117 | $refItem = $manager->createItem(); |
@@ -143,8 +142,7 @@ discard block |
||
| 143 | 142 | $data = $this->getObject()->process( $catalog, $data ); |
| 144 | 143 | |
| 145 | 144 | $manager->commit(); |
| 146 | - } |
|
| 147 | - catch( \Exception $e ) |
|
| 145 | + } catch( \Exception $e ) |
|
| 148 | 146 | { |
| 149 | 147 | $manager->rollback(); |
| 150 | 148 | throw $e; |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | 50 | /** controller/common/catalog/import/csv/processor/media/listtypes |
| 51 | 51 | * Names of the catalog list types for media that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @see controller/common/catalog/import/csv/processor/price/listtypes |
| 67 | 67 | * @see controller/common/catalog/import/csv/processor/text/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/catalog/import/csv/processor/media/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/catalog/import/csv/processor/media/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,45 +77,45 @@ discard block |
||
| 77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
| 78 | 78 | * @return array List of data which hasn't been imported |
| 79 | 79 | */ |
| 80 | - public function process( \Aimeos\MShop\Catalog\Item\Iface $catalog, array $data ) |
|
| 80 | + public function process(\Aimeos\MShop\Catalog\Item\Iface $catalog, array $data) |
|
| 81 | 81 | { |
| 82 | 82 | $context = $this->getContext(); |
| 83 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'media' ); |
|
| 84 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
| 85 | - $separator = $context->getConfig()->get( 'controller/common/catalog/import/csv/separator', "\n" ); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'media'); |
|
| 84 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
| 85 | + $separator = $context->getConfig()->get('controller/common/catalog/import/csv/separator', "\n"); |
|
| 86 | 86 | |
| 87 | 87 | $manager->begin(); |
| 88 | 88 | |
| 89 | 89 | try |
| 90 | 90 | { |
| 91 | 91 | $delete = $listMap = []; |
| 92 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 93 | - $listItems = $catalog->getListItems( 'media', $this->listTypes ); |
|
| 92 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 93 | + $listItems = $catalog->getListItems('media', $this->listTypes); |
|
| 94 | 94 | |
| 95 | - foreach( $listItems as $listItem ) |
|
| 95 | + foreach ($listItems as $listItem) |
|
| 96 | 96 | { |
| 97 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 98 | - $listMap[ $refItem->getUrl() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
| 97 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 98 | + $listMap[$refItem->getUrl()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - foreach( $map as $pos => $list ) |
|
| 102 | + foreach ($map as $pos => $list) |
|
| 103 | 103 | { |
| 104 | - if( $this->checkEntry( $list ) === false ) { |
|
| 104 | + if ($this->checkEntry($list) === false) { |
|
| 105 | 105 | continue; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $urls = explode( $separator, trim( $list['media.url'] ) ); |
|
| 109 | - $type = trim( $this->getValue( $list, 'media.type', 'default' ) ); |
|
| 110 | - $typecode = trim( $this->getValue( $list, 'catalog.lists.type', 'default' ) ); |
|
| 108 | + $urls = explode($separator, trim($list['media.url'])); |
|
| 109 | + $type = trim($this->getValue($list, 'media.type', 'default')); |
|
| 110 | + $typecode = trim($this->getValue($list, 'catalog.lists.type', 'default')); |
|
| 111 | 111 | |
| 112 | - foreach( $urls as $url ) |
|
| 112 | + foreach ($urls as $url) |
|
| 113 | 113 | { |
| 114 | - if( isset( $listMap[$url][$type][$typecode] ) ) |
|
| 114 | + if (isset($listMap[$url][$type][$typecode])) |
|
| 115 | 115 | { |
| 116 | 116 | $listItem = $listMap[$url][$type][$typecode]; |
| 117 | 117 | $refItem = $listItem->getRefItem(); |
| 118 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 118 | + unset($listItems[$listItem->getId()]); |
|
| 119 | 119 | } |
| 120 | 120 | else |
| 121 | 121 | { |
@@ -123,35 +123,35 @@ discard block |
||
| 123 | 123 | $refItem = $manager->createItem(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - $list['media.typeid'] = $this->getTypeId( 'media/type', 'catalog', $type ); |
|
| 126 | + $list['media.typeid'] = $this->getTypeId('media/type', 'catalog', $type); |
|
| 127 | 127 | $list['media.domain'] = 'catalog'; |
| 128 | 128 | $list['media.url'] = $url; |
| 129 | 129 | |
| 130 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 131 | - $refItem = $manager->saveItem( $refItem ); |
|
| 130 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 131 | + $refItem = $manager->saveItem($refItem); |
|
| 132 | 132 | |
| 133 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'media', $typecode ); |
|
| 133 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'media', $typecode); |
|
| 134 | 134 | $list['catalog.lists.parentid'] = $catalog->getId(); |
| 135 | 135 | $list['catalog.lists.refid'] = $refItem->getId(); |
| 136 | 136 | $list['catalog.lists.domain'] = 'media'; |
| 137 | 137 | |
| 138 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
| 139 | - $listManager->saveItem( $listItem, false ); |
|
| 138 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
| 139 | + $listManager->saveItem($listItem, false); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - foreach( $listItems as $listItem ) { |
|
| 143 | + foreach ($listItems as $listItem) { |
|
| 144 | 144 | $delete[] = $listItem->getRefId(); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $manager->deleteItems( $delete ); |
|
| 148 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 147 | + $manager->deleteItems($delete); |
|
| 148 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 149 | 149 | |
| 150 | - $data = $this->getObject()->process( $catalog, $data ); |
|
| 150 | + $data = $this->getObject()->process($catalog, $data); |
|
| 151 | 151 | |
| 152 | 152 | $manager->commit(); |
| 153 | 153 | } |
| 154 | - catch( \Exception $e ) |
|
| 154 | + catch (\Exception $e) |
|
| 155 | 155 | { |
| 156 | 156 | $manager->rollback(); |
| 157 | 157 | throw $e; |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | * @param array $list Associative list of domain item keys and their values, e.g. "media.status" => 1 |
| 168 | 168 | * @return array Given associative list enriched by default values if they were not already set |
| 169 | 169 | */ |
| 170 | - protected function addItemDefaults( array $list ) |
|
| 170 | + protected function addItemDefaults(array $list) |
|
| 171 | 171 | { |
| 172 | - if( !isset( $list['media.label'] ) ) { |
|
| 172 | + if (!isset($list['media.label'])) { |
|
| 173 | 173 | $list['media.label'] = $list['media.url']; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if( !isset( $list['media.preview'] ) ) { |
|
| 176 | + if (!isset($list['media.preview'])) { |
|
| 177 | 177 | $list['media.preview'] = $list['media.url']; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if( !isset( $list['media.status'] ) ) { |
|
| 180 | + if (!isset($list['media.status'])) { |
|
| 181 | 181 | $list['media.status'] = 1; |
| 182 | 182 | } |
| 183 | 183 | |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | * @param array $list Associative list of key/value pairs from the mapping |
| 192 | 192 | * @return boolean True if valid, false if not |
| 193 | 193 | */ |
| 194 | - protected function checkEntry( array $list ) |
|
| 194 | + protected function checkEntry(array $list) |
|
| 195 | 195 | { |
| 196 | - if( !isset( $list['media.url'] ) || trim( $list['media.url'] ) === '' || isset( $list['catalog.lists.type'] ) |
|
| 197 | - && $this->listTypes !== null && !in_array( trim( $list['catalog.lists.type'] ), (array) $this->listTypes ) |
|
| 196 | + if (!isset($list['media.url']) || trim($list['media.url']) === '' || isset($list['catalog.lists.type']) |
|
| 197 | + && $this->listTypes !== null && !in_array(trim($list['catalog.lists.type']), (array) $this->listTypes) |
|
| 198 | 198 | ) { |
| 199 | 199 | return false; |
| 200 | 200 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | 50 | /** controller/common/product/import/csv/processor/price/listtypes |
| 51 | 51 | * Names of the product list types for prices that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @see controller/common/product/import/csv/processor/product/listtypes |
| 67 | 67 | * @see controller/common/product/import/csv/processor/text/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/price/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/price/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,40 +77,40 @@ discard block |
||
| 77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
| 78 | 78 | * @return array List of data which hasn't been imported |
| 79 | 79 | */ |
| 80 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 80 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 81 | 81 | { |
| 82 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 83 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'price' ); |
|
| 82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'price'); |
|
| 84 | 84 | $manager->begin(); |
| 85 | 85 | |
| 86 | 86 | try |
| 87 | 87 | { |
| 88 | 88 | $delete = $listMap = []; |
| 89 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 90 | - $listItems = $product->getListItems( 'price', $this->listTypes ); |
|
| 89 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 90 | + $listItems = $product->getListItems('price', $this->listTypes); |
|
| 91 | 91 | |
| 92 | - foreach( $listItems as $listItem ) |
|
| 92 | + foreach ($listItems as $listItem) |
|
| 93 | 93 | { |
| 94 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 95 | - $listMap[ $refItem->getValue() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
| 94 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 95 | + $listMap[$refItem->getValue()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - foreach( $map as $pos => $list ) |
|
| 99 | + foreach ($map as $pos => $list) |
|
| 100 | 100 | { |
| 101 | - if( $this->checkEntry( $list ) === false ) { |
|
| 101 | + if ($this->checkEntry($list) === false) { |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $value = trim( isset( $list['price.value'] ) ? $list['price.value'] : '0.00' ); |
|
| 106 | - $type = trim( isset( $list['price.type'] ) ? $list['price.type'] : 'default' ); |
|
| 107 | - $typecode = trim( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 105 | + $value = trim(isset($list['price.value']) ? $list['price.value'] : '0.00'); |
|
| 106 | + $type = trim(isset($list['price.type']) ? $list['price.type'] : 'default'); |
|
| 107 | + $typecode = trim(isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 108 | 108 | |
| 109 | - if( isset( $listMap[$value][$type][$typecode] ) ) |
|
| 109 | + if (isset($listMap[$value][$type][$typecode])) |
|
| 110 | 110 | { |
| 111 | 111 | $listItem = $listMap[$value][$type][$typecode]; |
| 112 | 112 | $refItem = $listItem->getRefItem(); |
| 113 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 113 | + unset($listItems[$listItem->getId()]); |
|
| 114 | 114 | } |
| 115 | 115 | else |
| 116 | 116 | { |
@@ -118,33 +118,33 @@ discard block |
||
| 118 | 118 | $refItem = $manager->createItem(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $list['price.typeid'] = $this->getTypeId( 'price/type', 'product', $type ); |
|
| 121 | + $list['price.typeid'] = $this->getTypeId('price/type', 'product', $type); |
|
| 122 | 122 | $list['price.domain'] = 'product'; |
| 123 | 123 | |
| 124 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 125 | - $refItem = $manager->saveItem( $refItem ); |
|
| 124 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 125 | + $refItem = $manager->saveItem($refItem); |
|
| 126 | 126 | |
| 127 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'price', $typecode ); |
|
| 127 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'price', $typecode); |
|
| 128 | 128 | $list['product.lists.parentid'] = $product->getId(); |
| 129 | 129 | $list['product.lists.refid'] = $refItem->getId(); |
| 130 | 130 | $list['product.lists.domain'] = 'price'; |
| 131 | 131 | |
| 132 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 133 | - $listManager->saveItem( $listItem, false ); |
|
| 132 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 133 | + $listManager->saveItem($listItem, false); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - foreach( $listItems as $listItem ) { |
|
| 136 | + foreach ($listItems as $listItem) { |
|
| 137 | 137 | $delete[] = $listItem->getRefId(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $manager->deleteItems( $delete ); |
|
| 141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 140 | + $manager->deleteItems($delete); |
|
| 141 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 142 | 142 | |
| 143 | - $data = $this->getObject()->process( $product, $data ); |
|
| 143 | + $data = $this->getObject()->process($product, $data); |
|
| 144 | 144 | |
| 145 | 145 | $manager->commit(); |
| 146 | 146 | } |
| 147 | - catch( \Exception $e ) |
|
| 147 | + catch (\Exception $e) |
|
| 148 | 148 | { |
| 149 | 149 | $manager->rollback(); |
| 150 | 150 | throw $e; |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | * @param array $list Associative list of domain item keys and their values, e.g. "price.status" => 1 |
| 161 | 161 | * @return array Given associative list enriched by default values if they were not already set |
| 162 | 162 | */ |
| 163 | - protected function addItemDefaults( array $list ) |
|
| 163 | + protected function addItemDefaults(array $list) |
|
| 164 | 164 | { |
| 165 | - if( !isset( $list['price.currencyid'] ) ) { |
|
| 165 | + if (!isset($list['price.currencyid'])) { |
|
| 166 | 166 | $list['price.currencyid'] = $this->getContext()->getLocale()->getCurrencyId(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if( !isset( $list['price.label'] ) ) { |
|
| 169 | + if (!isset($list['price.label'])) { |
|
| 170 | 170 | $list['price.label'] = $list['price.currencyid'] . ' ' . $list['price.value']; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if( !isset( $list['price.status'] ) ) { |
|
| 173 | + if (!isset($list['price.status'])) { |
|
| 174 | 174 | $list['price.status'] = 1; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * @param array $list Associative list of key/value pairs from the mapping |
| 185 | 185 | * @return boolean True if valid, false if not |
| 186 | 186 | */ |
| 187 | - protected function checkEntry( array $list ) |
|
| 187 | + protected function checkEntry(array $list) |
|
| 188 | 188 | { |
| 189 | - if( !isset( $list['price.value'] ) || trim( $list['price.value'] ) === '' || isset( $list['product.lists.type'] ) |
|
| 190 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
| 189 | + if (!isset($list['price.value']) || trim($list['price.value']) === '' || isset($list['product.lists.type']) |
|
| 190 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
| 191 | 191 | ) { |
| 192 | 192 | return false; |
| 193 | 193 | } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 44 | 44 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 45 | 45 | */ |
| 46 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 46 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 48 | 48 | { |
| 49 | - parent::__construct( $context, $mapping, $object ); |
|
| 49 | + parent::__construct($context, $mapping, $object); |
|
| 50 | 50 | |
| 51 | 51 | /** controller/common/product/import/csv/processor/catalog/listtypes |
| 52 | 52 | * Names of the catalog list types that are updated or removed |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @see controller/common/product/import/csv/processor/product/listtypes |
| 68 | 68 | * @see controller/common/product/import/csv/processor/text/listtypes |
| 69 | 69 | */ |
| 70 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/catalog/listtypes' ); |
|
| 70 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/catalog/listtypes'); |
|
| 71 | 71 | |
| 72 | - $this->cache = $this->getCache( 'catalog' ); |
|
| 72 | + $this->cache = $this->getCache('catalog'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @param array $data List of CSV fields with position as key and data as value |
| 81 | 81 | * @return array List of data which hasn't been imported |
| 82 | 82 | */ |
| 83 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 83 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 84 | 84 | { |
| 85 | 85 | $context = $this->getContext(); |
| 86 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
|
| 87 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
| 86 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
| 87 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
| 88 | 88 | |
| 89 | 89 | /** controller/common/product/import/csv/separator |
| 90 | 90 | * Single separator character for multiple entries in one field of the import file |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @category Developer |
| 105 | 105 | * @see controller/common/product/import/csv/domains |
| 106 | 106 | */ |
| 107 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
| 107 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
| 108 | 108 | |
| 109 | 109 | $manager->begin(); |
| 110 | 110 | |
@@ -112,58 +112,58 @@ discard block |
||
| 112 | 112 | { |
| 113 | 113 | $listMap = []; |
| 114 | 114 | $prodid = $product->getId(); |
| 115 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 116 | - $listItems = $this->getListItems( $prodid, $this->listTypes ); |
|
| 115 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 116 | + $listItems = $this->getListItems($prodid, $this->listTypes); |
|
| 117 | 117 | |
| 118 | - foreach( $listItems as $listItem ) { |
|
| 119 | - $listMap[ $listItem->getParentId() ][ $listItem->getType() ] = $listItem; |
|
| 118 | + foreach ($listItems as $listItem) { |
|
| 119 | + $listMap[$listItem->getParentId()][$listItem->getType()] = $listItem; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - foreach( $map as $pos => $list ) |
|
| 122 | + foreach ($map as $pos => $list) |
|
| 123 | 123 | { |
| 124 | - if( $this->checkEntry( $list ) === false ) { |
|
| 124 | + if ($this->checkEntry($list) === false) { |
|
| 125 | 125 | continue; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $codes = explode( $separator, trim( $list['catalog.code'] ) ); |
|
| 129 | - $type = trim( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
|
| 128 | + $codes = explode($separator, trim($list['catalog.code'])); |
|
| 129 | + $type = trim(isset($list['catalog.lists.type']) ? $list['catalog.lists.type'] : 'default'); |
|
| 130 | 130 | |
| 131 | - foreach( $codes as $code ) |
|
| 131 | + foreach ($codes as $code) |
|
| 132 | 132 | { |
| 133 | - $code = trim( $code ); |
|
| 133 | + $code = trim($code); |
|
| 134 | 134 | |
| 135 | - if( ( $catid = $this->cache->get( $code ) ) === null ) |
|
| 135 | + if (($catid = $this->cache->get($code)) === null) |
|
| 136 | 136 | { |
| 137 | 137 | $msg = 'No category for code "%1$s" available when importing product with code "%2$s"'; |
| 138 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
| 138 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'product', $type ); |
|
| 141 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'product', $type); |
|
| 142 | 142 | $list['catalog.lists.parentid'] = $catid; |
| 143 | 143 | $list['catalog.lists.refid'] = $prodid; |
| 144 | 144 | $list['catalog.lists.domain'] = 'product'; |
| 145 | 145 | |
| 146 | - if( isset( $listMap[$catid][$type] ) ) |
|
| 146 | + if (isset($listMap[$catid][$type])) |
|
| 147 | 147 | { |
| 148 | 148 | $listItem = $listMap[$catid][$type]; |
| 149 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 149 | + unset($listItems[$listItem->getId()]); |
|
| 150 | 150 | } |
| 151 | 151 | else |
| 152 | 152 | { |
| 153 | 153 | $listItem = $listManager->createItem(); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
| 157 | - $listManager->saveItem( $listItem, false ); |
|
| 156 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
| 157 | + $listManager->saveItem($listItem, false); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 162 | - $data = $this->getObject()->process( $product, $data ); |
|
| 161 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 162 | + $data = $this->getObject()->process($product, $data); |
|
| 163 | 163 | |
| 164 | 164 | $manager->commit(); |
| 165 | 165 | } |
| 166 | - catch( \Exception $e ) |
|
| 166 | + catch (\Exception $e) |
|
| 167 | 167 | { |
| 168 | 168 | $manager->rollback(); |
| 169 | 169 | throw $e; |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | * @param integer $pos Computed position of the list item in the associated list of items |
| 181 | 181 | * @return array Given associative list enriched by default values if they were not already set |
| 182 | 182 | */ |
| 183 | - protected function addListItemDefaults( array $list, $pos ) |
|
| 183 | + protected function addListItemDefaults(array $list, $pos) |
|
| 184 | 184 | { |
| 185 | - if( !isset( $list['catalog.lists.position'] ) ) { |
|
| 185 | + if (!isset($list['catalog.lists.position'])) { |
|
| 186 | 186 | $list['catalog.lists.position'] = $pos; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if( !isset( $list['catalog.lists.status'] ) ) { |
|
| 189 | + if (!isset($list['catalog.lists.status'])) { |
|
| 190 | 190 | $list['catalog.lists.status'] = 1; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | * @param array $list Associative list of key/value pairs from the mapped data |
| 201 | 201 | * @return boolean True if the entry is valid, false if not |
| 202 | 202 | */ |
| 203 | - protected function checkEntry( array $list ) |
|
| 203 | + protected function checkEntry(array $list) |
|
| 204 | 204 | { |
| 205 | - if( !isset( $list['catalog.code'] ) || trim( $list['catalog.code'] ) === '' || isset( $list['catalog.lists.type'] ) |
|
| 206 | - && $this->listTypes !== null && !in_array( trim( $list['catalog.lists.type'] ), (array) $this->listTypes ) |
|
| 205 | + if (!isset($list['catalog.code']) || trim($list['catalog.code']) === '' || isset($list['catalog.lists.type']) |
|
| 206 | + && $this->listTypes !== null && !in_array(trim($list['catalog.lists.type']), (array) $this->listTypes) |
|
| 207 | 207 | ) { |
| 208 | 208 | return false; |
| 209 | 209 | } |
@@ -219,24 +219,24 @@ discard block |
||
| 219 | 219 | * @param array|null $types List of catalog list types |
| 220 | 220 | * @return array List of catalog list items |
| 221 | 221 | */ |
| 222 | - protected function getListItems( $prodid, $types ) |
|
| 222 | + protected function getListItems($prodid, $types) |
|
| 223 | 223 | { |
| 224 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
|
| 224 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists'); |
|
| 225 | 225 | $search = $manager->createSearch(); |
| 226 | 226 | |
| 227 | 227 | $expr = array( |
| 228 | - $search->compare( '==', 'catalog.lists.domain', 'product' ), |
|
| 229 | - $search->compare( '==', 'catalog.lists.refid', $prodid ), |
|
| 228 | + $search->compare('==', 'catalog.lists.domain', 'product'), |
|
| 229 | + $search->compare('==', 'catalog.lists.refid', $prodid), |
|
| 230 | 230 | ); |
| 231 | 231 | |
| 232 | - if( $types !== null ) { |
|
| 233 | - $expr[] = $search->compare( '==', 'catalog.lists.type.code', $types ); |
|
| 232 | + if ($types !== null) { |
|
| 233 | + $expr[] = $search->compare('==', 'catalog.lists.type.code', $types); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 237 | - $search->setSortations( array( $search->sort( '+', 'catalog.lists.position' ) ) ); |
|
| 238 | - $search->setSlice( 0, 0x7FFFFFFF ); |
|
| 236 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 237 | + $search->setSortations(array($search->sort('+', 'catalog.lists.position'))); |
|
| 238 | + $search->setSlice(0, 0x7FFFFFFF); |
|
| 239 | 239 | |
| 240 | - return $manager->searchItems( $search ); |
|
| 240 | + return $manager->searchItems($search); |
|
| 241 | 241 | } |
| 242 | 242 | } |
@@ -42,12 +42,12 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | - $this->cache = $this->getCache( 'stocktype' ); |
|
| 50 | + $this->cache = $this->getCache('stocktype'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -58,53 +58,53 @@ discard block |
||
| 58 | 58 | * @param array $data List of CSV fields with position as key and data as value |
| 59 | 59 | * @return array List of data which hasn't been imported |
| 60 | 60 | */ |
| 61 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 61 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 62 | 62 | { |
| 63 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 63 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 64 | 64 | $manager->begin(); |
| 65 | 65 | |
| 66 | 66 | try |
| 67 | 67 | { |
| 68 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 69 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 68 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 69 | + $items = $this->getStockItems($product->getCode()); |
|
| 70 | 70 | |
| 71 | - foreach( $map as $pos => $list ) |
|
| 71 | + foreach ($map as $pos => $list) |
|
| 72 | 72 | { |
| 73 | - if( !array_key_exists( 'stock.stocklevel', $list ) ) { |
|
| 73 | + if (!array_key_exists('stock.stocklevel', $list)) { |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $stockType = trim( isset( $list['stock.type'] ) ? $list['stock.type'] : 'default' ); |
|
| 77 | + $stockType = trim(isset($list['stock.type']) ? $list['stock.type'] : 'default'); |
|
| 78 | 78 | |
| 79 | - if( !isset( $list['stock.typeid'] ) ) { |
|
| 80 | - $list['stock.typeid'] = $this->cache->get( $stockType ); |
|
| 79 | + if (!isset($list['stock.typeid'])) { |
|
| 80 | + $list['stock.typeid'] = $this->cache->get($stockType); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if( isset( $list['stock.dateback'] ) && trim( $list['stock.dateback'] ) === '' ) { |
|
| 83 | + if (isset($list['stock.dateback']) && trim($list['stock.dateback']) === '') { |
|
| 84 | 84 | $list['stock.dateback'] = null; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if( trim( $list['stock.stocklevel'] ) === '' ) { |
|
| 87 | + if (trim($list['stock.stocklevel']) === '') { |
|
| 88 | 88 | $list['stock.stocklevel'] = null; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $list['stock.productcode'] = $product->getCode(); |
| 92 | 92 | |
| 93 | - if( ( $item = array_pop( $items ) ) === null ) { |
|
| 93 | + if (($item = array_pop($items)) === null) { |
|
| 94 | 94 | $item = $manager->createItem(); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $item->fromArray( $list ); |
|
| 98 | - $manager->saveItem( $item, false ); |
|
| 97 | + $item->fromArray($list); |
|
| 98 | + $manager->saveItem($item, false); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $manager->deleteItems( array_keys( $items ) ); |
|
| 101 | + $manager->deleteItems(array_keys($items)); |
|
| 102 | 102 | |
| 103 | - $data = $this->getObject()->process( $product, $data ); |
|
| 103 | + $data = $this->getObject()->process($product, $data); |
|
| 104 | 104 | |
| 105 | 105 | $manager->commit(); |
| 106 | 106 | } |
| 107 | - catch( \Exception $e ) |
|
| 107 | + catch (\Exception $e) |
|
| 108 | 108 | { |
| 109 | 109 | $manager->rollback(); |
| 110 | 110 | throw $e; |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | * @param string $code Unique product code |
| 121 | 121 | * @return \Aimeos\MShop\Stock\Item\Iface[] Associative list of stock items |
| 122 | 122 | */ |
| 123 | - protected function getStockItems( $code ) |
|
| 123 | + protected function getStockItems($code) |
|
| 124 | 124 | { |
| 125 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 125 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 126 | 126 | |
| 127 | 127 | $search = $manager->createSearch(); |
| 128 | - $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); |
|
| 128 | + $search->setConditions($search->compare('==', 'stock.productcode', $code)); |
|
| 129 | 129 | |
| 130 | - return $manager->searchItems( $search ); |
|
| 130 | + return $manager->searchItems($search); |
|
| 131 | 131 | } |
| 132 | 132 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | 50 | /** controller/common/product/import/csv/processor/text/listtypes |
| 51 | 51 | * Names of the product list types for texts that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @see controller/common/product/import/csv/processor/price/listtypes |
| 67 | 67 | * @see controller/common/product/import/csv/processor/product/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/text/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/text/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,40 +77,40 @@ discard block |
||
| 77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
| 78 | 78 | * @return array List of data which hasn't been imported |
| 79 | 79 | */ |
| 80 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 80 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 81 | 81 | { |
| 82 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 83 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'text' ); |
|
| 82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'text'); |
|
| 84 | 84 | $manager->begin(); |
| 85 | 85 | |
| 86 | 86 | try |
| 87 | 87 | { |
| 88 | 88 | $delete = $listMap = []; |
| 89 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 90 | - $listItems = $product->getListItems( 'text', $this->listTypes ); |
|
| 89 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 90 | + $listItems = $product->getListItems('text', $this->listTypes); |
|
| 91 | 91 | |
| 92 | - foreach( $listItems as $listItem ) |
|
| 92 | + foreach ($listItems as $listItem) |
|
| 93 | 93 | { |
| 94 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 95 | - $listMap[ $refItem->getContent() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
| 94 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 95 | + $listMap[$refItem->getContent()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - foreach( $map as $pos => $list ) |
|
| 99 | + foreach ($map as $pos => $list) |
|
| 100 | 100 | { |
| 101 | - if( $this->checkEntry( $list ) === false ) { |
|
| 101 | + if ($this->checkEntry($list) === false) { |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $content = trim( $list['text.content'] ); |
|
| 106 | - $type = trim( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
|
| 107 | - $typecode = trim( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 105 | + $content = trim($list['text.content']); |
|
| 106 | + $type = trim(isset($list['text.type']) ? $list['text.type'] : 'name'); |
|
| 107 | + $typecode = trim(isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 108 | 108 | |
| 109 | - if( isset( $listMap[$content][$type][$typecode] ) ) |
|
| 109 | + if (isset($listMap[$content][$type][$typecode])) |
|
| 110 | 110 | { |
| 111 | 111 | $listItem = $listMap[$content][$type][$typecode]; |
| 112 | 112 | $refItem = $listItem->getRefItem(); |
| 113 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 113 | + unset($listItems[$listItem->getId()]); |
|
| 114 | 114 | } |
| 115 | 115 | else |
| 116 | 116 | { |
@@ -118,33 +118,33 @@ discard block |
||
| 118 | 118 | $refItem = $manager->createItem(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $list['text.typeid'] = $this->getTypeId( 'text/type', 'product', $type ); |
|
| 121 | + $list['text.typeid'] = $this->getTypeId('text/type', 'product', $type); |
|
| 122 | 122 | $list['text.domain'] = 'product'; |
| 123 | 123 | |
| 124 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 125 | - $refItem = $manager->saveItem( $refItem ); |
|
| 124 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 125 | + $refItem = $manager->saveItem($refItem); |
|
| 126 | 126 | |
| 127 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'text', $typecode ); |
|
| 127 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'text', $typecode); |
|
| 128 | 128 | $list['product.lists.parentid'] = $product->getId(); |
| 129 | 129 | $list['product.lists.refid'] = $refItem->getId(); |
| 130 | 130 | $list['product.lists.domain'] = 'text'; |
| 131 | 131 | |
| 132 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 133 | - $listManager->saveItem( $listItem, false ); |
|
| 132 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 133 | + $listManager->saveItem($listItem, false); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - foreach( $listItems as $listItem ) { |
|
| 136 | + foreach ($listItems as $listItem) { |
|
| 137 | 137 | $delete[] = $listItem->getRefId(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $manager->deleteItems( $delete ); |
|
| 141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 140 | + $manager->deleteItems($delete); |
|
| 141 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 142 | 142 | |
| 143 | - $data = $this->getObject()->process( $product, $data ); |
|
| 143 | + $data = $this->getObject()->process($product, $data); |
|
| 144 | 144 | |
| 145 | 145 | $manager->commit(); |
| 146 | 146 | } |
| 147 | - catch( \Exception $e ) |
|
| 147 | + catch (\Exception $e) |
|
| 148 | 148 | { |
| 149 | 149 | $manager->rollback(); |
| 150 | 150 | throw $e; |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | * @param array $list Associative list of domain item keys and their values, e.g. "text.status" => 1 |
| 161 | 161 | * @return array Given associative list enriched by default values if they were not already set |
| 162 | 162 | */ |
| 163 | - protected function addItemDefaults( array $list ) |
|
| 163 | + protected function addItemDefaults(array $list) |
|
| 164 | 164 | { |
| 165 | - if( !isset( $list['text.label'] ) ) { |
|
| 166 | - $list['text.label'] = mb_strcut( trim( $list['text.content'] ), 0, 255 ); |
|
| 165 | + if (!isset($list['text.label'])) { |
|
| 166 | + $list['text.label'] = mb_strcut(trim($list['text.content']), 0, 255); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if( !isset( $list['text.languageid'] ) ) { |
|
| 169 | + if (!isset($list['text.languageid'])) { |
|
| 170 | 170 | $list['text.languageid'] = $this->getContext()->getLocale()->getLanguageId(); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if( !isset( $list['text.status'] ) ) { |
|
| 173 | + if (!isset($list['text.status'])) { |
|
| 174 | 174 | $list['text.status'] = 1; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * @param array $list Associative list of key/value pairs from the mapping |
| 185 | 185 | * @return boolean True if valid, false if not |
| 186 | 186 | */ |
| 187 | - protected function checkEntry( array $list ) |
|
| 187 | + protected function checkEntry(array $list) |
|
| 188 | 188 | { |
| 189 | - if( !isset( $list['text.content'] ) || trim( $list['text.content'] ) === '' || isset( $list['product.lists.type'] ) |
|
| 190 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
| 189 | + if (!isset($list['text.content']) || trim($list['text.content']) === '' || isset($list['product.lists.type']) |
|
| 190 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
| 191 | 191 | ) { |
| 192 | 192 | return false; |
| 193 | 193 | } |
@@ -111,8 +111,7 @@ discard block |
||
| 111 | 111 | $listItem = $listMap[$content][$type][$typecode]; |
| 112 | 112 | $refItem = $listItem->getRefItem(); |
| 113 | 113 | unset( $listItems[ $listItem->getId() ] ); |
| 114 | - } |
|
| 115 | - else |
|
| 114 | + } else |
|
| 116 | 115 | { |
| 117 | 116 | $listItem = $listManager->createItem(); |
| 118 | 117 | $refItem = $manager->createItem(); |
@@ -143,8 +142,7 @@ discard block |
||
| 143 | 142 | $data = $this->getObject()->process( $product, $data ); |
| 144 | 143 | |
| 145 | 144 | $manager->commit(); |
| 146 | - } |
|
| 147 | - catch( \Exception $e ) |
|
| 145 | + } catch( \Exception $e ) |
|
| 148 | 146 | { |
| 149 | 147 | $manager->rollback(); |
| 150 | 148 | throw $e; |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 44 | 44 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 45 | 45 | */ |
| 46 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 46 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 48 | 48 | { |
| 49 | - parent::__construct( $context, $mapping, $object ); |
|
| 49 | + parent::__construct($context, $mapping, $object); |
|
| 50 | 50 | |
| 51 | 51 | /** controller/common/product/import/csv/processor/product/listtypes |
| 52 | 52 | * Names of the product list types that are updated or removed |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | * @see controller/common/product/import/csv/processor/price/listtypes |
| 74 | 74 | * @see controller/common/product/import/csv/processor/text/listtypes |
| 75 | 75 | */ |
| 76 | - $default = array( 'default', 'suggestion' ); |
|
| 76 | + $default = array('default', 'suggestion'); |
|
| 77 | 77 | $key = 'controller/common/product/import/csv/processor/product/listtypes'; |
| 78 | - $this->listTypes = $context->getConfig()->get( $key, $default ); |
|
| 78 | + $this->listTypes = $context->getConfig()->get($key, $default); |
|
| 79 | 79 | |
| 80 | - $this->cache = $this->getCache( 'product' ); |
|
| 80 | + $this->cache = $this->getCache('product'); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | * @param array $data List of CSV fields with position as key and data as value |
| 89 | 89 | * @return array List of data which hasn't been imported |
| 90 | 90 | */ |
| 91 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 91 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 92 | 92 | { |
| 93 | 93 | $context = $this->getContext(); |
| 94 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
| 95 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
| 94 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
| 95 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
| 96 | 96 | |
| 97 | - $this->cache->set( $product ); |
|
| 97 | + $this->cache->set($product); |
|
| 98 | 98 | |
| 99 | 99 | $manager->begin(); |
| 100 | 100 | |
@@ -102,39 +102,39 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | $types = []; |
| 104 | 104 | |
| 105 | - foreach( $this->getMappedChunk( $data, $this->getMapping() ) as $list ) |
|
| 105 | + foreach ($this->getMappedChunk($data, $this->getMapping()) as $list) |
|
| 106 | 106 | { |
| 107 | - if( $this->checkEntry( $list ) === false ) { |
|
| 107 | + if ($this->checkEntry($list) === false) { |
|
| 108 | 108 | continue; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | $listMap = []; |
| 112 | - $type = trim( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 112 | + $type = trim(isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 113 | 113 | $types[] = $type; |
| 114 | 114 | |
| 115 | - foreach( explode( $separator, trim( $list['product.code'] ) ) as $code ) |
|
| 115 | + foreach (explode($separator, trim($list['product.code'])) as $code) |
|
| 116 | 116 | { |
| 117 | - $code = trim( $code ); |
|
| 117 | + $code = trim($code); |
|
| 118 | 118 | |
| 119 | - if( ( $prodid = $this->cache->get( $code ) ) === null ) |
|
| 119 | + if (($prodid = $this->cache->get($code)) === null) |
|
| 120 | 120 | { |
| 121 | 121 | $msg = 'No product for code "%1$s" available when importing product with code "%2$s"'; |
| 122 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
| 122 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $listMap[$prodid] = $list; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $manager->updateListItems( $product, $listMap, 'product', $type ); |
|
| 128 | + $manager->updateListItems($product, $listMap, 'product', $type); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $this->deleteListItems( $product->getId(), $types ); |
|
| 131 | + $this->deleteListItems($product->getId(), $types); |
|
| 132 | 132 | |
| 133 | - $data = $this->getObject()->process( $product, $data ); |
|
| 133 | + $data = $this->getObject()->process($product, $data); |
|
| 134 | 134 | |
| 135 | 135 | $manager->commit(); |
| 136 | 136 | } |
| 137 | - catch( \Exception $e ) |
|
| 137 | + catch (\Exception $e) |
|
| 138 | 138 | { |
| 139 | 139 | $manager->rollback(); |
| 140 | 140 | throw $e; |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | * @param array $list Associative list of key/value pairs from the mapping |
| 151 | 151 | * @return boolean True if valid, false if not |
| 152 | 152 | */ |
| 153 | - protected function checkEntry( array $list ) |
|
| 153 | + protected function checkEntry(array $list) |
|
| 154 | 154 | { |
| 155 | - if( !isset( $list['product.code'] ) || trim( $list['product.code'] ) === '' || isset( $list['product.lists.type'] ) |
|
| 156 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
| 155 | + if (!isset($list['product.code']) || trim($list['product.code']) === '' || isset($list['product.lists.type']) |
|
| 156 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
| 157 | 157 | ) { |
| 158 | 158 | return false; |
| 159 | 159 | } |
@@ -168,19 +168,19 @@ discard block |
||
| 168 | 168 | * @param string $prodId Unique product ID |
| 169 | 169 | * @param array $types List of types that have been updated |
| 170 | 170 | */ |
| 171 | - protected function deleteListItems( $prodId, array $types ) |
|
| 171 | + protected function deleteListItems($prodId, array $types) |
|
| 172 | 172 | { |
| 173 | - $codes = array_diff( $this->listTypes, $types ); |
|
| 174 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 173 | + $codes = array_diff($this->listTypes, $types); |
|
| 174 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 175 | 175 | |
| 176 | 176 | $search = $manager->createSearch(); |
| 177 | 177 | $expr = array( |
| 178 | - $search->compare( '==', 'product.lists.parentid', $prodId ), |
|
| 179 | - $search->compare( '==', 'product.lists.domain', 'product' ), |
|
| 180 | - $search->compare( '==', 'product.lists.type.code', $codes ), |
|
| 178 | + $search->compare('==', 'product.lists.parentid', $prodId), |
|
| 179 | + $search->compare('==', 'product.lists.domain', 'product'), |
|
| 180 | + $search->compare('==', 'product.lists.type.code', $codes), |
|
| 181 | 181 | ); |
| 182 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 182 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 183 | 183 | |
| 184 | - $manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
|
| 184 | + $manager->deleteItems(array_keys($manager->searchItems($search))); |
|
| 185 | 185 | } |
| 186 | 186 | } |