@@ -352,8 +352,7 @@ discard block |
||
352 | 352 | } |
353 | 353 | |
354 | 354 | $container->close(); |
355 | - } |
|
356 | - catch( \Exception $e ) |
|
355 | + } catch( \Exception $e ) |
|
357 | 356 | { |
358 | 357 | $logger->log( 'Catalog import error: ' . $e->getMessage() ); |
359 | 358 | $logger->log( $e->getTraceAsString() ); |
@@ -583,8 +582,7 @@ discard block |
||
583 | 582 | { |
584 | 583 | $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
585 | 584 | $catalogItem = $manager->saveItem( $catalogItem ); |
586 | - } |
|
587 | - else |
|
585 | + } else |
|
588 | 586 | { |
589 | 587 | $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
590 | 588 | } |
@@ -594,8 +592,7 @@ discard block |
||
594 | 592 | } |
595 | 593 | |
596 | 594 | $manager->commit(); |
597 | - } |
|
598 | - catch( \Exception $e ) |
|
595 | + } catch( \Exception $e ) |
|
599 | 596 | { |
600 | 597 | $manager->rollback(); |
601 | 598 |
@@ -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,15 +489,15 @@ 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 | - if( $location === null ) |
|
494 | + if ($location === null) |
|
495 | 495 | { |
496 | - $msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/catalog/import/csv/location' ); |
|
497 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
496 | + $msg = sprintf('Required configuration for "%1$s" is missing', 'controller/jobs/catalog/import/csv/location'); |
|
497 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
498 | 498 | } |
499 | 499 | |
500 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
500 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | |
@@ -507,13 +507,13 @@ discard block |
||
507 | 507 | * @param array $domains List of domain names whose items should be fetched too |
508 | 508 | * @return array Associative list of catalog codes as keys and items implementing \Aimeos\MShop\Catalog\Item\Iface as values |
509 | 509 | */ |
510 | - protected function getCatalogMap( array $domains ) |
|
510 | + protected function getCatalogMap(array $domains) |
|
511 | 511 | { |
512 | 512 | $map = []; |
513 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' ); |
|
514 | - $search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
|
513 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog'); |
|
514 | + $search = $manager->createSearch()->setSlice(0, 0x7fffffff); |
|
515 | 515 | |
516 | - foreach( $manager->searchItems( $search, $domains ) as $item ) { |
|
516 | + foreach ($manager->searchItems($search, $domains) as $item) { |
|
517 | 517 | $map[$item->getCode()] = $item; |
518 | 518 | } |
519 | 519 | |
@@ -529,23 +529,23 @@ discard block |
||
529 | 529 | * @param string $code Catalog item code of the parent category |
530 | 530 | * @return string|null ID of the parent category or null for top level nodes |
531 | 531 | */ |
532 | - protected function getParentId( array $catalogMap, array $map, $code ) |
|
532 | + protected function getParentId(array $catalogMap, array $map, $code) |
|
533 | 533 | { |
534 | - if( !isset( $map['catalog.parent'] ) ) |
|
534 | + if (!isset($map['catalog.parent'])) |
|
535 | 535 | { |
536 | - $msg = sprintf( 'Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code ); |
|
537 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
536 | + $msg = sprintf('Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code); |
|
537 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
538 | 538 | } |
539 | 539 | |
540 | - $parent = trim( $map['catalog.parent'] ); |
|
540 | + $parent = trim($map['catalog.parent']); |
|
541 | 541 | |
542 | - if( $parent != '' && !isset( $catalogMap[$parent] ) ) |
|
542 | + if ($parent != '' && !isset($catalogMap[$parent])) |
|
543 | 543 | { |
544 | - $msg = sprintf( 'Parent node for code "%1$s" not found', $parent ); |
|
545 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
544 | + $msg = sprintf('Parent node for code "%1$s" not found', $parent); |
|
545 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
546 | 546 | } |
547 | 547 | |
548 | - return ( $parent != '' ? $catalogMap[$parent]->getId() : null ); |
|
548 | + return ($parent != '' ? $catalogMap[$parent]->getId() : null); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | |
@@ -560,65 +560,65 @@ discard block |
||
560 | 560 | * @return integer Number of catalogs that couldn't be imported |
561 | 561 | * @throws \Aimeos\Controller\Jobs\Exception |
562 | 562 | */ |
563 | - protected function import( array &$catalogMap, array $data, array $mapping, |
|
564 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict ) |
|
563 | + protected function import(array &$catalogMap, array $data, array $mapping, |
|
564 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict) |
|
565 | 565 | { |
566 | 566 | $errors = 0; |
567 | 567 | $context = $this->getContext(); |
568 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
|
568 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
569 | 569 | |
570 | - foreach( $data as $code => $list ) |
|
570 | + foreach ($data as $code => $list) |
|
571 | 571 | { |
572 | 572 | $manager->begin(); |
573 | 573 | |
574 | 574 | try |
575 | 575 | { |
576 | - $code = trim( $code ); |
|
576 | + $code = trim($code); |
|
577 | 577 | |
578 | - if( isset( $catalogMap[$code] ) ) { |
|
578 | + if (isset($catalogMap[$code])) { |
|
579 | 579 | $catalogItem = $catalogMap[$code]; |
580 | 580 | } else { |
581 | 581 | $catalogItem = $manager->createItem(); |
582 | 582 | } |
583 | 583 | |
584 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
584 | + $map = $this->getMappedChunk($list, $mapping); |
|
585 | 585 | |
586 | - if( isset( $map[0] ) ) |
|
586 | + if (isset($map[0])) |
|
587 | 587 | { |
588 | 588 | $map = $map[0]; // there can only be one chunk for the base catalog data |
589 | - $parentid = $this->getParentId( $catalogMap, $map, $code ); |
|
590 | - $catalogItem->fromArray( $this->addItemDefaults( $map ) ); |
|
589 | + $parentid = $this->getParentId($catalogMap, $map, $code); |
|
590 | + $catalogItem->fromArray($this->addItemDefaults($map)); |
|
591 | 591 | |
592 | - if( isset( $catalogMap[$code] ) ) |
|
592 | + if (isset($catalogMap[$code])) |
|
593 | 593 | { |
594 | - $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
|
595 | - $catalogItem = $manager->saveItem( $catalogItem ); |
|
594 | + $manager->moveItem($catalogItem->getId(), $catalogItem->getParentId(), $parentid); |
|
595 | + $catalogItem = $manager->saveItem($catalogItem); |
|
596 | 596 | } |
597 | 597 | else |
598 | 598 | { |
599 | - $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
|
599 | + $catalogItem = $manager->insertItem($catalogItem, $parentid); |
|
600 | 600 | } |
601 | 601 | |
602 | - $list = $processor->process( $catalogItem, $list ); |
|
602 | + $list = $processor->process($catalogItem, $list); |
|
603 | 603 | $catalogMap[$code] = $catalogItem; |
604 | 604 | |
605 | - $manager->saveItem( $catalogItem ); |
|
605 | + $manager->saveItem($catalogItem); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | $manager->commit(); |
609 | 609 | } |
610 | - catch( \Exception $e ) |
|
610 | + catch (\Exception $e) |
|
611 | 611 | { |
612 | 612 | $manager->rollback(); |
613 | 613 | |
614 | - $msg = sprintf( 'Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
615 | - $context->getLogger()->log( $msg ); |
|
614 | + $msg = sprintf('Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage()); |
|
615 | + $context->getLogger()->log($msg); |
|
616 | 616 | |
617 | 617 | $errors++; |
618 | 618 | } |
619 | 619 | |
620 | - if( $strict && !empty( $list ) ) { |
|
621 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
620 | + if ($strict && !empty($list)) { |
|
621 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -632,9 +632,9 @@ discard block |
||
632 | 632 | * @param array $list Associative list of domain item keys and their values, e.g. "catalog.status" => 1 |
633 | 633 | * @return array Given associative list enriched by default values if they were not already set |
634 | 634 | */ |
635 | - protected function addItemDefaults( array $list ) |
|
635 | + protected function addItemDefaults(array $list) |
|
636 | 636 | { |
637 | - if( !isset( $list['catalog.status'] ) ) { |
|
637 | + if (!isset($list['catalog.status'])) { |
|
638 | 638 | $list['catalog.status'] = 1; |
639 | 639 | } |
640 | 640 |
@@ -40,28 +40,28 @@ |
||
40 | 40 | * @param \Aimeos\MShop\Order\Item\Base\Iface $order Full subscription with associated items |
41 | 41 | * @return array Two dimensional associative list of subscription data representing the lines in CSV |
42 | 42 | */ |
43 | - public function process( \Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order ) |
|
43 | + public function process(\Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order) |
|
44 | 44 | { |
45 | 45 | $result = []; |
46 | 46 | $addresses = $order->getAddresses(); |
47 | 47 | |
48 | - krsort( $addresses ); |
|
48 | + krsort($addresses); |
|
49 | 49 | |
50 | - foreach( $addresses as $item ) |
|
50 | + foreach ($addresses as $item) |
|
51 | 51 | { |
52 | 52 | $data = []; |
53 | 53 | $list = $item->toArray(); |
54 | 54 | |
55 | - foreach( $this->getMapping() as $pos => $key ) |
|
55 | + foreach ($this->getMapping() as $pos => $key) |
|
56 | 56 | { |
57 | - if( array_key_exists( $key, $list ) ) { |
|
57 | + if (array_key_exists($key, $list)) { |
|
58 | 58 | $data[$pos] = $list[$key]; |
59 | 59 | } else { |
60 | 60 | $data[$pos] = ''; |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - ksort( $data ); |
|
64 | + ksort($data); |
|
65 | 65 | $result[] = $data; |
66 | 66 | } |
67 | 67 |
@@ -40,24 +40,24 @@ discard block |
||
40 | 40 | * @param \Aimeos\MShop\Order\Item\Base\Iface $order Full order with associated items |
41 | 41 | * @return array Two dimensional associative list of order data representing the lines in CSV |
42 | 42 | */ |
43 | - public function process( \Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order ) |
|
43 | + public function process(\Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order) |
|
44 | 44 | { |
45 | 45 | $result = []; |
46 | 46 | |
47 | - foreach( $order->getProducts() as $item ) |
|
47 | + foreach ($order->getProducts() as $item) |
|
48 | 48 | { |
49 | - if( $subscription->getOrderProductId() != $item->getId() ) { |
|
49 | + if ($subscription->getOrderProductId() != $item->getId()) { |
|
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
53 | 53 | $data = []; |
54 | 54 | $list = $item->toArray(); |
55 | 55 | |
56 | - foreach( $item->getAttributes() as $attrItem ) |
|
56 | + foreach ($item->getAttributes() as $attrItem) |
|
57 | 57 | { |
58 | - foreach( $attrItem->toArray() as $key => $value ) |
|
58 | + foreach ($attrItem->toArray() as $key => $value) |
|
59 | 59 | { |
60 | - if( isset( $list[$key] ) ) { |
|
60 | + if (isset($list[$key])) { |
|
61 | 61 | $list[$key] .= "\n" . $value; |
62 | 62 | } else { |
63 | 63 | $list[$key] = $value; |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - foreach( $this->getMapping() as $pos => $key ) |
|
68 | + foreach ($this->getMapping() as $pos => $key) |
|
69 | 69 | { |
70 | - if( array_key_exists( $key, $list ) ) { |
|
70 | + if (array_key_exists($key, $list)) { |
|
71 | 71 | $data[$pos] = $list[$key]; |
72 | 72 | } else { |
73 | 73 | $data[$pos] = ''; |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - ksort( $data ); |
|
77 | + ksort($data); |
|
78 | 78 | $result[] = $data; |
79 | 79 | } |
80 | 80 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
30 | 30 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
31 | 31 | */ |
32 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping ) |
|
32 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping) |
|
33 | 33 | { |
34 | 34 | $this->context = $context; |
35 | 35 | $this->mapping = $mapping; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
26 | 26 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
27 | 27 | */ |
28 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping ); |
|
28 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping); |
|
29 | 29 | |
30 | 30 | |
31 | 31 | /** |
@@ -35,5 +35,5 @@ discard block |
||
35 | 35 | * @param \Aimeos\MShop\Order\Item\Base\Iface $order Full order with associated items |
36 | 36 | * @return array Two dimensional associative list of order data representing the lines in CSV |
37 | 37 | */ |
38 | - public function process( \Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order ); |
|
38 | + public function process(\Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order); |
|
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -40,21 +40,21 @@ |
||
40 | 40 | * @param \Aimeos\MShop\Order\Item\Base\Iface $order Full order with associated items |
41 | 41 | * @return array Two dimensional associative list of subscription data representing the lines in CSV |
42 | 42 | */ |
43 | - public function process( \Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order ) |
|
43 | + public function process(\Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Base\Iface $order) |
|
44 | 44 | { |
45 | 45 | $result = []; |
46 | 46 | $list = $subscription->toArray() + $order->toArray(); |
47 | 47 | |
48 | - foreach( $this->getMapping() as $pos => $key ) |
|
48 | + foreach ($this->getMapping() as $pos => $key) |
|
49 | 49 | { |
50 | - if( array_key_exists( $key, $list ) ) { |
|
50 | + if (array_key_exists($key, $list)) { |
|
51 | 51 | $result[$pos] = $list[$key]; |
52 | 52 | } else { |
53 | 53 | $result[$pos] = ''; |
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | - ksort( $result ); |
|
57 | + ksort($result); |
|
58 | 58 | |
59 | 59 | return [$result]; |
60 | 60 | } |
@@ -38,77 +38,77 @@ |
||
38 | 38 | ); |
39 | 39 | |
40 | 40 | |
41 | - $object = new \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Address\Standard( $context, $mapping ); |
|
42 | - |
|
43 | - $subscription = $this->getSubscription( $context ); |
|
44 | - $order = \Aimeos\MShop\Factory::createManager( $context, 'order/base' )->load( $subscription->getOrderBaseId() ); |
|
45 | - |
|
46 | - $data = $object->process( $subscription, $order ); |
|
47 | - |
|
48 | - |
|
49 | - $this->assertEquals( 2, count( $data ) ); |
|
50 | - |
|
51 | - $this->assertEquals( 21, count( $data[0] ) ); |
|
52 | - $this->assertEquals( 'payment', $data[0][0] ); |
|
53 | - $this->assertEquals( 'mr', $data[0][1] ); |
|
54 | - $this->assertEquals( '', $data[0][2] ); |
|
55 | - $this->assertEquals( '', $data[0][3] ); |
|
56 | - $this->assertEquals( '', $data[0][4] ); |
|
57 | - $this->assertEquals( 'Our', $data[0][5] ); |
|
58 | - $this->assertEquals( 'Unittest', $data[0][6] ); |
|
59 | - $this->assertEquals( 'Durchschnitt', $data[0][7] ); |
|
60 | - $this->assertEquals( '1', $data[0][8] ); |
|
61 | - $this->assertEquals( '', $data[0][9] ); |
|
62 | - $this->assertEquals( '20146', $data[0][10] ); |
|
63 | - $this->assertEquals( 'Hamburg', $data[0][11] ); |
|
64 | - $this->assertEquals( 'Hamburg', $data[0][12] ); |
|
65 | - $this->assertEquals( 'DE', $data[0][13] ); |
|
66 | - $this->assertEquals( 'de', $data[0][14] ); |
|
67 | - $this->assertEquals( '055544332211', $data[0][15] ); |
|
68 | - $this->assertEquals( '055544332213', $data[0][16] ); |
|
69 | - $this->assertEquals( '[email protected]', $data[0][17] ); |
|
70 | - $this->assertEquals( 'www.metaways.net', $data[0][18] ); |
|
71 | - $this->assertEquals( '11.000000', $data[0][19] ); |
|
72 | - $this->assertEquals( '52.000000', $data[0][20] ); |
|
73 | - |
|
74 | - $this->assertEquals( 21, count( $data[1] ) ); |
|
75 | - $this->assertEquals( 'delivery', $data[1][0] ); |
|
76 | - $this->assertEquals( 'mr', $data[1][1] ); |
|
77 | - $this->assertEquals( 'Example company', $data[1][2] ); |
|
78 | - $this->assertEquals( 'DE999999999', $data[1][3] ); |
|
79 | - $this->assertEquals( 'Dr.', $data[1][4] ); |
|
80 | - $this->assertEquals( 'Our', $data[1][5] ); |
|
81 | - $this->assertEquals( 'Unittest', $data[1][6] ); |
|
82 | - $this->assertEquals( 'Pickhuben', $data[1][7] ); |
|
83 | - $this->assertEquals( '2-4', $data[1][8] ); |
|
84 | - $this->assertEquals( '', $data[1][9] ); |
|
85 | - $this->assertEquals( '20457', $data[1][10] ); |
|
86 | - $this->assertEquals( 'Hamburg', $data[1][11] ); |
|
87 | - $this->assertEquals( 'Hamburg', $data[1][12] ); |
|
88 | - $this->assertEquals( 'DE', $data[1][13] ); |
|
89 | - $this->assertEquals( 'de', $data[1][14] ); |
|
90 | - $this->assertEquals( '055544332211', $data[1][15] ); |
|
91 | - $this->assertEquals( '055544332212', $data[1][16] ); |
|
92 | - $this->assertEquals( '[email protected]', $data[1][17] ); |
|
93 | - $this->assertEquals( 'www.example.com', $data[1][18] ); |
|
94 | - $this->assertEquals( '10.000000', $data[1][19] ); |
|
95 | - $this->assertEquals( '50.000000', $data[1][20] ); |
|
41 | + $object = new \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Address\Standard($context, $mapping); |
|
42 | + |
|
43 | + $subscription = $this->getSubscription($context); |
|
44 | + $order = \Aimeos\MShop\Factory::createManager($context, 'order/base')->load($subscription->getOrderBaseId()); |
|
45 | + |
|
46 | + $data = $object->process($subscription, $order); |
|
47 | + |
|
48 | + |
|
49 | + $this->assertEquals(2, count($data)); |
|
50 | + |
|
51 | + $this->assertEquals(21, count($data[0])); |
|
52 | + $this->assertEquals('payment', $data[0][0]); |
|
53 | + $this->assertEquals('mr', $data[0][1]); |
|
54 | + $this->assertEquals('', $data[0][2]); |
|
55 | + $this->assertEquals('', $data[0][3]); |
|
56 | + $this->assertEquals('', $data[0][4]); |
|
57 | + $this->assertEquals('Our', $data[0][5]); |
|
58 | + $this->assertEquals('Unittest', $data[0][6]); |
|
59 | + $this->assertEquals('Durchschnitt', $data[0][7]); |
|
60 | + $this->assertEquals('1', $data[0][8]); |
|
61 | + $this->assertEquals('', $data[0][9]); |
|
62 | + $this->assertEquals('20146', $data[0][10]); |
|
63 | + $this->assertEquals('Hamburg', $data[0][11]); |
|
64 | + $this->assertEquals('Hamburg', $data[0][12]); |
|
65 | + $this->assertEquals('DE', $data[0][13]); |
|
66 | + $this->assertEquals('de', $data[0][14]); |
|
67 | + $this->assertEquals('055544332211', $data[0][15]); |
|
68 | + $this->assertEquals('055544332213', $data[0][16]); |
|
69 | + $this->assertEquals('[email protected]', $data[0][17]); |
|
70 | + $this->assertEquals('www.metaways.net', $data[0][18]); |
|
71 | + $this->assertEquals('11.000000', $data[0][19]); |
|
72 | + $this->assertEquals('52.000000', $data[0][20]); |
|
73 | + |
|
74 | + $this->assertEquals(21, count($data[1])); |
|
75 | + $this->assertEquals('delivery', $data[1][0]); |
|
76 | + $this->assertEquals('mr', $data[1][1]); |
|
77 | + $this->assertEquals('Example company', $data[1][2]); |
|
78 | + $this->assertEquals('DE999999999', $data[1][3]); |
|
79 | + $this->assertEquals('Dr.', $data[1][4]); |
|
80 | + $this->assertEquals('Our', $data[1][5]); |
|
81 | + $this->assertEquals('Unittest', $data[1][6]); |
|
82 | + $this->assertEquals('Pickhuben', $data[1][7]); |
|
83 | + $this->assertEquals('2-4', $data[1][8]); |
|
84 | + $this->assertEquals('', $data[1][9]); |
|
85 | + $this->assertEquals('20457', $data[1][10]); |
|
86 | + $this->assertEquals('Hamburg', $data[1][11]); |
|
87 | + $this->assertEquals('Hamburg', $data[1][12]); |
|
88 | + $this->assertEquals('DE', $data[1][13]); |
|
89 | + $this->assertEquals('de', $data[1][14]); |
|
90 | + $this->assertEquals('055544332211', $data[1][15]); |
|
91 | + $this->assertEquals('055544332212', $data[1][16]); |
|
92 | + $this->assertEquals('[email protected]', $data[1][17]); |
|
93 | + $this->assertEquals('www.example.com', $data[1][18]); |
|
94 | + $this->assertEquals('10.000000', $data[1][19]); |
|
95 | + $this->assertEquals('50.000000', $data[1][20]); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | - protected function getSubscription( $context ) |
|
99 | + protected function getSubscription($context) |
|
100 | 100 | { |
101 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'subscription' ); |
|
101 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'subscription'); |
|
102 | 102 | |
103 | 103 | $search = $manager->createSearch(); |
104 | - $search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) ); |
|
104 | + $search->setConditions($search->compare('==', 'subscription.dateend', '2010-01-01')); |
|
105 | 105 | |
106 | - $items = $manager->searchItems( $search ); |
|
106 | + $items = $manager->searchItems($search); |
|
107 | 107 | |
108 | - if( ( $item = reset( $items ) ) !== false ) { |
|
108 | + if (($item = reset($items)) !== false) { |
|
109 | 109 | return $item; |
110 | 110 | } |
111 | 111 | |
112 | - throw new \Exception( 'No subscription item found' ); |
|
112 | + throw new \Exception('No subscription item found'); |
|
113 | 113 | } |
114 | 114 | } |
@@ -20,36 +20,36 @@ |
||
20 | 20 | ); |
21 | 21 | |
22 | 22 | |
23 | - $object = new \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Subscription\Standard( $context, $mapping ); |
|
23 | + $object = new \Aimeos\Controller\Common\Subscription\Export\Csv\Processor\Subscription\Standard($context, $mapping); |
|
24 | 24 | |
25 | - $subscription = $this->getSubscription( $context ); |
|
26 | - $order = \Aimeos\MShop\Factory::createManager( $context, 'order/base' )->load( $subscription->getOrderBaseId() ); |
|
25 | + $subscription = $this->getSubscription($context); |
|
26 | + $order = \Aimeos\MShop\Factory::createManager($context, 'order/base')->load($subscription->getOrderBaseId()); |
|
27 | 27 | |
28 | - $data = $object->process( $subscription, $order ); |
|
28 | + $data = $object->process($subscription, $order); |
|
29 | 29 | |
30 | 30 | |
31 | - $this->assertEquals( 1, count( $data ) ); |
|
31 | + $this->assertEquals(1, count($data)); |
|
32 | 32 | |
33 | - $this->assertEquals( 3, count( $data[0] ) ); |
|
34 | - $this->assertEquals( 'P0Y1M0W0D', $data[0][0] ); |
|
35 | - $this->assertEquals( '2000-01-01', $data[0][1] ); |
|
36 | - $this->assertEquals( '2010-01-01', $data[0][2] ); |
|
33 | + $this->assertEquals(3, count($data[0])); |
|
34 | + $this->assertEquals('P0Y1M0W0D', $data[0][0]); |
|
35 | + $this->assertEquals('2000-01-01', $data[0][1]); |
|
36 | + $this->assertEquals('2010-01-01', $data[0][2]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | |
40 | - protected function getSubscription( $context ) |
|
40 | + protected function getSubscription($context) |
|
41 | 41 | { |
42 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'subscription' ); |
|
42 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'subscription'); |
|
43 | 43 | |
44 | 44 | $search = $manager->createSearch(); |
45 | - $search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) ); |
|
45 | + $search->setConditions($search->compare('==', 'subscription.dateend', '2010-01-01')); |
|
46 | 46 | |
47 | - $items = $manager->searchItems( $search ); |
|
47 | + $items = $manager->searchItems($search); |
|
48 | 48 | |
49 | - if( ( $item = reset( $items ) ) !== false ) { |
|
49 | + if (($item = reset($items)) !== false) { |
|
50 | 50 | return $item; |
51 | 51 | } |
52 | 52 | |
53 | - throw new \Exception( 'No subscription item found' ); |
|
53 | + throw new \Exception('No subscription item found'); |
|
54 | 54 | } |
55 | 55 | } |
@@ -121,8 +121,7 @@ |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | $this->export( $processors, $data, $maxcnt ); |
124 | - } |
|
125 | - catch( \Exception $e ) |
|
124 | + } catch( \Exception $e ) |
|
126 | 125 | { |
127 | 126 | $logger->log( 'Subscription export error: ' . $e->getMessage() ); |
128 | 127 | $logger->log( $e->getTraceAsString() ); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Subscription export CSV' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Subscription export 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', 'Exports subscriptions to CSV file' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Exports subscriptions to CSV file'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @category Developer |
74 | 74 | * @see controller/common/subscription/export/csv/max-size |
75 | 75 | */ |
76 | - $mappings = $config->get( 'controller/common/subscription/export/csv/mapping', $mappings ); |
|
76 | + $mappings = $config->get('controller/common/subscription/export/csv/mapping', $mappings); |
|
77 | 77 | |
78 | 78 | /** controller/jobs/subscription/export/csv/mapping |
79 | 79 | * List of mappings between the position in the CSV file and item keys |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @category Developer |
89 | 89 | * @see controller/common/subscription/export/csv/max-size |
90 | 90 | */ |
91 | - $mappings = $config->get( 'controller/jobs/subscription/export/csv/mapping', $mappings ); |
|
91 | + $mappings = $config->get('controller/jobs/subscription/export/csv/mapping', $mappings); |
|
92 | 92 | |
93 | 93 | |
94 | 94 | /** controller/common/subscription/export/csv/max-size |
@@ -106,29 +106,29 @@ discard block |
||
106 | 106 | * @category Developer |
107 | 107 | * @see controller/common/subscription/export/csv/mapping |
108 | 108 | */ |
109 | - $maxcnt = (int) $config->get( 'controller/common/subscription/export/csv/max-size', 1000 ); |
|
109 | + $maxcnt = (int) $config->get('controller/common/subscription/export/csv/max-size', 1000); |
|
110 | 110 | |
111 | 111 | |
112 | - $processors = $this->getProcessors( $mappings ); |
|
113 | - $mq = $context->getMessageQueueManager()->get( 'mq-admin' )->getQueue( 'subscription-export' ); |
|
112 | + $processors = $this->getProcessors($mappings); |
|
113 | + $mq = $context->getMessageQueueManager()->get('mq-admin')->getQueue('subscription-export'); |
|
114 | 114 | |
115 | - while( ( $msg = $mq->get() ) !== null ) |
|
115 | + while (($msg = $mq->get()) !== null) |
|
116 | 116 | { |
117 | 117 | try |
118 | 118 | { |
119 | - if( ( $data = json_decode( $msg->getBody(), true ) ) === null ) { |
|
120 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid message: %1$s', $msg->getBody() ) ); |
|
119 | + if (($data = json_decode($msg->getBody(), true)) === null) { |
|
120 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid message: %1$s', $msg->getBody())); |
|
121 | 121 | } |
122 | 122 | |
123 | - $this->export( $processors, $data, $maxcnt ); |
|
123 | + $this->export($processors, $data, $maxcnt); |
|
124 | 124 | } |
125 | - catch( \Exception $e ) |
|
125 | + catch (\Exception $e) |
|
126 | 126 | { |
127 | - $logger->log( 'Subscription export error: ' . $e->getMessage() ); |
|
128 | - $logger->log( $e->getTraceAsString() ); |
|
127 | + $logger->log('Subscription export error: ' . $e->getMessage()); |
|
128 | + $logger->log($e->getTraceAsString()); |
|
129 | 129 | } |
130 | 130 | |
131 | - $mq->del( $msg ); |
|
131 | + $mq->del($msg); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | * @param \Aimeos\MShop\Context\Item\Iface $context Context item |
140 | 140 | * @param string $path Absolute path to the exported file |
141 | 141 | */ |
142 | - protected function addJob( $context, $path ) |
|
142 | + protected function addJob($context, $path) |
|
143 | 143 | { |
144 | - $manager = \Aimeos\MAdmin\Factory::createManager( $context, 'job' ); |
|
144 | + $manager = \Aimeos\MAdmin\Factory::createManager($context, 'job'); |
|
145 | 145 | |
146 | 146 | $item = $manager->createItem(); |
147 | - $item->setResult( ['file' => $path] ); |
|
148 | - $item->setLabel( $path ); |
|
147 | + $item->setResult(['file' => $path]); |
|
148 | + $item->setLabel($path); |
|
149 | 149 | |
150 | - $manager->saveItem( $item, false ); |
|
150 | + $manager->saveItem($item, false); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @see controller/jobs/subscription/export/csv/container/content |
178 | 178 | * @see controller/jobs/subscription/export/csv/container/options |
179 | 179 | */ |
180 | - $location = $config->get( 'controller/jobs/subscription/export/csv/location', sys_get_temp_dir() ); |
|
180 | + $location = $config->get('controller/jobs/subscription/export/csv/location', sys_get_temp_dir()); |
|
181 | 181 | |
182 | 182 | /** controller/jobs/subscription/export/csv/container/type |
183 | 183 | * Nave of the container type to read the data from |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @see controller/jobs/subscription/export/csv/container/content |
201 | 201 | * @see controller/jobs/subscription/export/csv/container/options |
202 | 202 | */ |
203 | - $container = $config->get( 'controller/jobs/subscription/export/csv/container/type', 'Directory' ); |
|
203 | + $container = $config->get('controller/jobs/subscription/export/csv/container/type', 'Directory'); |
|
204 | 204 | |
205 | 205 | /** controller/jobs/subscription/export/csv/container/content |
206 | 206 | * Name of the content type inside the container to read the data from |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @see controller/jobs/subscription/export/csv/container/type |
222 | 222 | * @see controller/jobs/subscription/export/csv/container/options |
223 | 223 | */ |
224 | - $content = $config->get( 'controller/jobs/subscription/export/csv/container/content', 'CSV' ); |
|
224 | + $content = $config->get('controller/jobs/subscription/export/csv/container/content', 'CSV'); |
|
225 | 225 | |
226 | 226 | /** controller/jobs/subscription/export/csv/container/options |
227 | 227 | * List of file container options for the subscription export files |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | * @see controller/jobs/subscription/export/csv/container/content |
240 | 240 | * @see controller/jobs/subscription/export/csv/container/type |
241 | 241 | */ |
242 | - $options = $config->get( 'controller/jobs/subscription/export/csv/container/options', [] ); |
|
242 | + $options = $config->get('controller/jobs/subscription/export/csv/container/options', []); |
|
243 | 243 | |
244 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
244 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -253,56 +253,56 @@ discard block |
||
253 | 253 | * @param integer $maxcnt Maximum number of retrieved subscriptions at once |
254 | 254 | * @return string Path of the file containing the exported data |
255 | 255 | */ |
256 | - protected function export( array $processors, $msg, $maxcnt ) |
|
256 | + protected function export(array $processors, $msg, $maxcnt) |
|
257 | 257 | { |
258 | - $lcontext = $this->getLocaleContext( $msg ); |
|
258 | + $lcontext = $this->getLocaleContext($msg); |
|
259 | 259 | $baseRef = ['order/base/address', 'order/base/product']; |
260 | 260 | |
261 | - $manager = \Aimeos\MShop\Factory::createManager( $lcontext, 'subscription' ); |
|
262 | - $baseManager = \Aimeos\MShop\Factory::createManager( $lcontext, 'order/base' ); |
|
261 | + $manager = \Aimeos\MShop\Factory::createManager($lcontext, 'subscription'); |
|
262 | + $baseManager = \Aimeos\MShop\Factory::createManager($lcontext, 'order/base'); |
|
263 | 263 | |
264 | 264 | $container = $this->getContainer(); |
265 | - $content = $container->create( 'subscription-export_' . date( 'Y-m-d_H-i-s' ) ); |
|
266 | - $search = $this->initCriteria( $manager->createSearch()->setSlice( 0, 0x7fffffff ), $msg ); |
|
265 | + $content = $container->create('subscription-export_' . date('Y-m-d_H-i-s')); |
|
266 | + $search = $this->initCriteria($manager->createSearch()->setSlice(0, 0x7fffffff), $msg); |
|
267 | 267 | $start = 0; |
268 | 268 | |
269 | 269 | do |
270 | 270 | { |
271 | 271 | $baseIds = []; |
272 | - $search->setSlice( $start, $maxcnt ); |
|
273 | - $items = $manager->searchItems( $search ); |
|
272 | + $search->setSlice($start, $maxcnt); |
|
273 | + $items = $manager->searchItems($search); |
|
274 | 274 | |
275 | - foreach( $items as $item ) { |
|
275 | + foreach ($items as $item) { |
|
276 | 276 | $baseIds[] = $item->getOrderBaseId(); |
277 | 277 | } |
278 | 278 | |
279 | 279 | $baseSearch = $baseManager->createSearch(); |
280 | - $baseSearch->setConditions( $baseSearch->compare( '==', 'order.base.id', $baseIds ) ); |
|
281 | - $baseSearch->setSlice( 0, count( $baseIds ) ); |
|
280 | + $baseSearch->setConditions($baseSearch->compare('==', 'order.base.id', $baseIds)); |
|
281 | + $baseSearch->setSlice(0, count($baseIds)); |
|
282 | 282 | |
283 | - $baseItems = $baseManager->searchItems( $baseSearch, $baseRef ); |
|
283 | + $baseItems = $baseManager->searchItems($baseSearch, $baseRef); |
|
284 | 284 | |
285 | - foreach( $items as $id => $item ) |
|
285 | + foreach ($items as $id => $item) |
|
286 | 286 | { |
287 | - foreach( $processors as $type => $processor ) |
|
287 | + foreach ($processors as $type => $processor) |
|
288 | 288 | { |
289 | - foreach( $processor->process( $item, $baseItems[$item->getOrderBaseId()] ) as $line ) { |
|
290 | - $content->add( [0 => $type, 1 => $id] + $line ); |
|
289 | + foreach ($processor->process($item, $baseItems[$item->getOrderBaseId()]) as $line) { |
|
290 | + $content->add([0 => $type, 1 => $id] + $line); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | - $count = count( $items ); |
|
295 | + $count = count($items); |
|
296 | 296 | $start += $count; |
297 | 297 | } |
298 | - while( $count === $search->getSliceSize() ); |
|
298 | + while ($count === $search->getSliceSize()); |
|
299 | 299 | |
300 | 300 | $path = $content->getResource(); |
301 | - $container->add( $content ); |
|
301 | + $container->add($content); |
|
302 | 302 | $container->close(); |
303 | 303 | |
304 | - $path = $this->moveFile( $lcontext, $path ); |
|
305 | - $this->addJob( $lcontext, $path ); |
|
304 | + $path = $this->moveFile($lcontext, $path); |
|
305 | + $this->addJob($lcontext, $path); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | |
@@ -312,15 +312,15 @@ discard block |
||
312 | 312 | * @param array $msg Message data including a "sitecode" value |
313 | 313 | * @return \Aimeos\MShop\Context\Item\Iface New context item with updated locale |
314 | 314 | */ |
315 | - protected function getLocaleContext( array $msg ) |
|
315 | + protected function getLocaleContext(array $msg) |
|
316 | 316 | { |
317 | 317 | $lcontext = clone $this->getContext(); |
318 | - $manager = \Aimeos\MShop\Factory::createManager( $lcontext, 'locale' ); |
|
318 | + $manager = \Aimeos\MShop\Factory::createManager($lcontext, 'locale'); |
|
319 | 319 | |
320 | - $sitecode = ( isset( $msg['sitecode'] ) ? $msg['sitecode'] : 'default' ); |
|
321 | - $localeItem = $manager->bootstrap( $sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE ); |
|
320 | + $sitecode = (isset($msg['sitecode']) ? $msg['sitecode'] : 'default'); |
|
321 | + $localeItem = $manager->bootstrap($sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE); |
|
322 | 322 | |
323 | - return $lcontext->setLocale( $localeItem ); |
|
323 | + return $lcontext->setLocale($localeItem); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | * @param array $msg Message data |
332 | 332 | * @return \Aimeos\MW\Criteria\Iface Initialized criteria object |
333 | 333 | */ |
334 | - protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $msg ) |
|
334 | + protected function initCriteria(\Aimeos\MW\Criteria\Iface $criteria, array $msg) |
|
335 | 335 | { |
336 | - if( isset( $msg['filter'] ) ) { |
|
337 | - $criteria->setConditions( $criteria->toConditions( $msg['filter'] ) ); |
|
336 | + if (isset($msg['filter'])) { |
|
337 | + $criteria->setConditions($criteria->toConditions($msg['filter'])); |
|
338 | 338 | } |
339 | 339 | |
340 | - if( isset( $msg['sort'] ) ) { |
|
341 | - $criteria->setSortations( $criteria->toSortations( $msg['sort'] ) ); |
|
340 | + if (isset($msg['sort'])) { |
|
341 | + $criteria->setSortations($criteria->toSortations($msg['sort'])); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $criteria; |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | * @param string $path Absolute path to the exported file |
353 | 353 | * @return string Relative path of the file in the storage |
354 | 354 | */ |
355 | - protected function moveFile( $context, $path ) |
|
355 | + protected function moveFile($context, $path) |
|
356 | 356 | { |
357 | - $filename = basename( $path ); |
|
358 | - $context->getFileSystemManager()->get( 'fs-admin' )->writef( $filename, $path ); |
|
357 | + $filename = basename($path); |
|
358 | + $context->getFileSystemManager()->get('fs-admin')->writef($filename, $path); |
|
359 | 359 | |
360 | - unlink( $path ); |
|
360 | + unlink($path); |
|
361 | 361 | return $filename; |
362 | 362 | } |
363 | 363 | } |