@@ -16,43 +16,43 @@ |
||
16 | 16 | |
17 | 17 | protected function setUp() |
18 | 18 | { |
19 | - \Aimeos\MShop\Factory::setCache( true ); |
|
19 | + \Aimeos\MShop\Factory::setCache(true); |
|
20 | 20 | |
21 | 21 | $context = \TestHelperCntl::getContext(); |
22 | - $this->object = new \Aimeos\Controller\Common\Product\Import\Csv\Cache\Stocktype\Standard( $context ); |
|
22 | + $this->object = new \Aimeos\Controller\Common\Product\Import\Csv\Cache\Stocktype\Standard($context); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | |
26 | 26 | protected function tearDown() |
27 | 27 | { |
28 | - \Aimeos\MShop\Factory::setCache( false ); |
|
28 | + \Aimeos\MShop\Factory::setCache(false); |
|
29 | 29 | \Aimeos\MShop\Factory::clear(); |
30 | 30 | } |
31 | 31 | |
32 | 32 | |
33 | 33 | public function testGet() |
34 | 34 | { |
35 | - $result = $this->object->get( 'default' ); |
|
35 | + $result = $this->object->get('default'); |
|
36 | 36 | |
37 | - $this->assertNotEquals( null, $result ); |
|
37 | + $this->assertNotEquals(null, $result); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | |
41 | 41 | public function testGetUnknown() |
42 | 42 | { |
43 | - $this->assertEquals( null, $this->object->get( 'cache-test' ) ); |
|
43 | + $this->assertEquals(null, $this->object->get('cache-test')); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
47 | 47 | public function testSet() |
48 | 48 | { |
49 | - $item = \Aimeos\MShop\Factory::createManager( \TestHelperCntl::getContext(), 'stock/type' )->createItem(); |
|
50 | - $item->setCode( 'cache-test' ); |
|
51 | - $item->setId( 1 ); |
|
49 | + $item = \Aimeos\MShop\Factory::createManager(\TestHelperCntl::getContext(), 'stock/type')->createItem(); |
|
50 | + $item->setCode('cache-test'); |
|
51 | + $item->setId(1); |
|
52 | 52 | |
53 | - $this->object->set( $item ); |
|
54 | - $id = $this->object->get( 'cache-test' ); |
|
53 | + $this->object->set($item); |
|
54 | + $id = $this->object->get('cache-test'); |
|
55 | 55 | |
56 | - $this->assertEquals( $item->getId(), $id ); |
|
56 | + $this->assertEquals($item->getId(), $id); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string|null $name Name of the controller or "Standard" if null |
30 | 30 | * @return \Aimeos\Controller\Jobs\Iface New controller object |
31 | 31 | */ |
32 | - public static function createController( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null ) |
|
32 | + public static function createController(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null) |
|
33 | 33 | { |
34 | 34 | /** controller/jobs/media/scale/name |
35 | 35 | * Class name of the used media scale job controller implementation |
@@ -64,20 +64,20 @@ discard block |
||
64 | 64 | * @since 2017.01 |
65 | 65 | * @category Developer |
66 | 66 | */ |
67 | - if( $name === null ) { |
|
68 | - $name = $context->getConfig()->get( 'controller/jobs/media/scale/name', 'Standard' ); |
|
67 | + if ($name === null) { |
|
68 | + $name = $context->getConfig()->get('controller/jobs/media/scale/name', 'Standard'); |
|
69 | 69 | } |
70 | 70 | |
71 | - if( ctype_alnum( $name ) === false ) |
|
71 | + if (ctype_alnum($name) === false) |
|
72 | 72 | { |
73 | - $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Jobs\\Media\\Scale\\' . $name : '<not a string>'; |
|
74 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
73 | + $classname = is_string($name) ? '\\Aimeos\\Controller\\Jobs\\Media\\Scale\\' . $name : '<not a string>'; |
|
74 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $iface = '\\Aimeos\\Controller\\Jobs\\Iface'; |
78 | 78 | $classname = '\\Aimeos\\Controller\\Jobs\\Media\\Scale\\' . $name; |
79 | 79 | |
80 | - $controller = self::createControllerBase( $context, $aimeos, $classname, $iface ); |
|
80 | + $controller = self::createControllerBase($context, $aimeos, $classname, $iface); |
|
81 | 81 | |
82 | 82 | /** controller/jobs/media/scale/decorators/excludes |
83 | 83 | * Excludes decorators added by the "common" option from the media scale controllers |
@@ -153,6 +153,6 @@ discard block |
||
153 | 153 | * @see controller/jobs/media/scale/decorators/excludes |
154 | 154 | * @see controller/jobs/media/scale/decorators/global |
155 | 155 | */ |
156 | - return self::addControllerDecorators( $context, $aimeos, $controller, 'media/scale' ); |
|
156 | + return self::addControllerDecorators($context, $aimeos, $controller, 'media/scale'); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | \ No newline at end of file |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | $context = \TestHelperJobs::getContext(); |
17 | 17 | $aimeos = \TestHelperJobs::getAimeos(); |
18 | 18 | |
19 | - $obj = \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos ); |
|
20 | - $this->assertInstanceOf( '\\Aimeos\\Controller\\Jobs\\Iface', $obj ); |
|
19 | + $obj = \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos); |
|
20 | + $this->assertInstanceOf('\\Aimeos\\Controller\\Jobs\\Iface', $obj); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | $context = \TestHelperJobs::getContext(); |
27 | 27 | $aimeos = \TestHelperJobs::getAimeos(); |
28 | 28 | |
29 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
30 | - \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos, 'Wrong$$$Name' ); |
|
29 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
30 | + \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos, 'Wrong$$$Name'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | $context = \TestHelperJobs::getContext(); |
37 | 37 | $aimeos = \TestHelperJobs::getAimeos(); |
38 | 38 | |
39 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
40 | - \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos, 'WrongClass' ); |
|
39 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
40 | + \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos, 'WrongClass'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | $context = \TestHelperJobs::getContext(); |
47 | 47 | $aimeos = \TestHelperJobs::getAimeos(); |
48 | 48 | |
49 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
50 | - \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos, 'Factory' ); |
|
49 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
50 | + \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos, 'Factory'); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Rescale product images' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Rescale product images'); |
|
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', 'Rescales product images to the new sizes' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Rescales product images to the new sizes'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,33 +50,33 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function run() |
52 | 52 | { |
53 | - $cntl = \Aimeos\Controller\Common\Media\Factory::createController( $this->getContext() ); |
|
54 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'media' ); |
|
53 | + $cntl = \Aimeos\Controller\Common\Media\Factory::createController($this->getContext()); |
|
54 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'media'); |
|
55 | 55 | |
56 | 56 | $search = $manager->createSearch(); |
57 | 57 | $expr = array( |
58 | - $search->compare( '==', 'media.domain', 'product' ), |
|
59 | - $search->compare( '=~', 'media.mimetype', 'image/' ), |
|
58 | + $search->compare('==', 'media.domain', 'product'), |
|
59 | + $search->compare('=~', 'media.mimetype', 'image/'), |
|
60 | 60 | ); |
61 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
62 | - $search->setSortations( array( $search->sort( '+', 'media.id' ) ) ); |
|
61 | + $search->setConditions($search->combine('&&', $expr)); |
|
62 | + $search->setSortations(array($search->sort('+', 'media.id'))); |
|
63 | 63 | |
64 | 64 | $start = 0; |
65 | 65 | |
66 | 66 | do |
67 | 67 | { |
68 | - $search->setSlice( $start ); |
|
69 | - $items = $manager->searchItems( $search ); |
|
68 | + $search->setSlice($start); |
|
69 | + $items = $manager->searchItems($search); |
|
70 | 70 | |
71 | - foreach( $items as $item ) |
|
71 | + foreach ($items as $item) |
|
72 | 72 | { |
73 | - $cntl->scale( $item, 'fs-media' ); |
|
74 | - $manager->saveItem( $item ); |
|
73 | + $cntl->scale($item, 'fs-media'); |
|
74 | + $manager->saveItem($item); |
|
75 | 75 | } |
76 | 76 | |
77 | - $count = count( $items ); |
|
77 | + $count = count($items); |
|
78 | 78 | $start += $count; |
79 | 79 | } |
80 | - while( $count === $search->getSliceSize() ); |
|
80 | + while ($count === $search->getSliceSize()); |
|
81 | 81 | } |
82 | 82 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | $context = \TestHelperJobs::getContext(); |
20 | 20 | $aimeos = \TestHelperJobs::getAimeos(); |
21 | 21 | |
22 | - $this->object = new \Aimeos\Controller\Jobs\Media\Scale\Standard( $context, $aimeos ); |
|
22 | + $this->object = new \Aimeos\Controller\Jobs\Media\Scale\Standard($context, $aimeos); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | |
32 | 32 | public function testGetName() |
33 | 33 | { |
34 | - $this->assertEquals( 'Rescale product images', $this->object->getName() ); |
|
34 | + $this->assertEquals('Rescale product images', $this->object->getName()); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | |
38 | 38 | public function testGetDescription() |
39 | 39 | { |
40 | 40 | $text = 'Rescales product images to the new sizes'; |
41 | - $this->assertEquals( $text, $this->object->getDescription() ); |
|
41 | + $this->assertEquals($text, $this->object->getDescription()); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
@@ -49,31 +49,31 @@ discard block |
||
49 | 49 | |
50 | 50 | |
51 | 51 | $name = 'ControllerJobsMediaScaleStandardRun'; |
52 | - $context->getConfig()->set( 'mshop/media/manager/name', $name ); |
|
53 | - $context->getConfig()->set( 'controller/common/media/name', $name ); |
|
52 | + $context->getConfig()->set('mshop/media/manager/name', $name); |
|
53 | + $context->getConfig()->set('controller/common/media/name', $name); |
|
54 | 54 | |
55 | 55 | |
56 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Media\\Manager\\Standard' ) |
|
57 | - ->setMethods( array( 'saveItem' ) ) |
|
58 | - ->setConstructorArgs( array( $context ) ) |
|
56 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Media\\Manager\\Standard') |
|
57 | + ->setMethods(array('saveItem')) |
|
58 | + ->setConstructorArgs(array($context)) |
|
59 | 59 | ->getMock(); |
60 | 60 | |
61 | - \Aimeos\MShop\Media\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Media\\Manager\\' . $name, $managerStub ); |
|
61 | + \Aimeos\MShop\Media\Manager\Factory::injectManager('\\Aimeos\\MShop\\Media\\Manager\\' . $name, $managerStub); |
|
62 | 62 | |
63 | - $managerStub->expects( $this->atLeast( 1 ) )->method( 'saveItem' ); |
|
63 | + $managerStub->expects($this->atLeast(1))->method('saveItem'); |
|
64 | 64 | |
65 | 65 | |
66 | - $cntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Media\\Standard' ) |
|
67 | - ->setMethods( array( 'scale' ) ) |
|
68 | - ->setConstructorArgs( array( $context ) ) |
|
66 | + $cntlStub = $this->getMockBuilder('\\Aimeos\\Controller\\Common\\Media\\Standard') |
|
67 | + ->setMethods(array('scale')) |
|
68 | + ->setConstructorArgs(array($context)) |
|
69 | 69 | ->getMock(); |
70 | 70 | |
71 | - \Aimeos\Controller\Common\Media\Factory::injectController( '\\Aimeos\\Controller\\Common\\Media\\' . $name, $cntlStub ); |
|
71 | + \Aimeos\Controller\Common\Media\Factory::injectController('\\Aimeos\\Controller\\Common\\Media\\' . $name, $cntlStub); |
|
72 | 72 | |
73 | - $cntlStub->expects( $this->atLeast( 1 ) )->method( 'scale' ); |
|
73 | + $cntlStub->expects($this->atLeast(1))->method('scale'); |
|
74 | 74 | |
75 | 75 | |
76 | - $object = new \Aimeos\Controller\Jobs\Media\Scale\Standard( $context, $aimeos ); |
|
76 | + $object = new \Aimeos\Controller\Jobs\Media\Scale\Standard($context, $aimeos); |
|
77 | 77 | $object->run(); |
78 | 78 | } |
79 | 79 | } |
@@ -133,7 +133,7 @@ |
||
133 | 133 | * |
134 | 134 | * @param array $list Associative list of key/value pairs |
135 | 135 | * @param string $key Key for the value to retrieve |
136 | - * @param mixed $default Default value if key isn't found |
|
136 | + * @param string $default Default value if key isn't found |
|
137 | 137 | * @param mixed Value for the key in the list of the default value |
138 | 138 | */ |
139 | 139 | protected function getValue( array $list, $key, $default ) |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
33 | 33 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
34 | 34 | */ |
35 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
36 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
35 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
36 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
37 | 37 | { |
38 | 38 | $this->context = $context; |
39 | 39 | $this->mapping = $mapping; |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | * @param integer $pos Computed position of the list item in the associated list of items |
49 | 49 | * @return array Given associative list enriched by default values if they were not already set |
50 | 50 | */ |
51 | - protected function addListItemDefaults( array $list, $pos ) |
|
51 | + protected function addListItemDefaults(array $list, $pos) |
|
52 | 52 | { |
53 | - if( !isset( $list['product.lists.position'] ) ) { |
|
53 | + if (!isset($list['product.lists.position'])) { |
|
54 | 54 | $list['product.lists.position'] = $pos; |
55 | 55 | } |
56 | 56 | |
57 | - if( !isset( $list['product.lists.status'] ) ) { |
|
57 | + if (!isset($list['product.lists.status'])) { |
|
58 | 58 | $list['product.lists.status'] = 1; |
59 | 59 | } |
60 | 60 | |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function getObject() |
94 | 94 | { |
95 | - if( $this->object === null ) { |
|
96 | - throw new \Aimeos\Controller\Jobs\Exception( 'No processor object available' ); |
|
95 | + if ($this->object === null) { |
|
96 | + throw new \Aimeos\Controller\Jobs\Exception('No processor object available'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | return $this->object; |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @param mixed $default Default value if key isn't found |
109 | 109 | * @param mixed Value for the key in the list of the default value |
110 | 110 | */ |
111 | - protected function getValue( array $list, $key, $default ) |
|
111 | + protected function getValue(array $list, $key, $default) |
|
112 | 112 | { |
113 | - return ( isset( $list[$key] ) ? $list[$key] : $default ); |
|
113 | + return (isset($list[$key]) ? $list[$key] : $default); |
|
114 | 114 | } |
115 | 115 | } |
@@ -116,8 +116,7 @@ discard block |
||
116 | 116 | $listItem = $listMap[$url][$type][$typecode]; |
117 | 117 | $refItem = $listItem->getRefItem(); |
118 | 118 | unset( $listItems[ $listItem->getId() ] ); |
119 | - } |
|
120 | - else |
|
119 | + } else |
|
121 | 120 | { |
122 | 121 | $listItem = $listManager->createItem(); |
123 | 122 | $refItem = $manager->createItem(); |
@@ -150,8 +149,7 @@ discard block |
||
150 | 149 | $data = $this->getObject()->process( $product, $data ); |
151 | 150 | |
152 | 151 | $manager->commit(); |
153 | - } |
|
154 | - catch( \Exception $e ) |
|
152 | + } catch( \Exception $e ) |
|
155 | 153 | { |
156 | 154 | $manager->rollback(); |
157 | 155 | 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\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/media/listtypes |
51 | 51 | * Names of the product list types for media 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/text/listtypes |
68 | 68 | */ |
69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/media/listtypes' ); |
|
69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/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\Product\Item\Iface $product, array $data ) |
|
80 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
81 | 81 | { |
82 | 82 | $context = $this->getContext(); |
83 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'media' ); |
|
84 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists' ); |
|
85 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
83 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'media'); |
|
84 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists'); |
|
85 | + $separator = $context->getConfig()->get('controller/common/product/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 = $product->getListItems( 'media', $this->listTypes ); |
|
92 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
93 | + $listItems = $product->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, $list['media.url'] ); |
|
109 | - $type = $this->getValue( $list, 'media.type', 'default' ); |
|
110 | - $typecode = $this->getValue( $list, 'product.lists.type', 'default' ); |
|
108 | + $urls = explode($separator, $list['media.url']); |
|
109 | + $type = $this->getValue($list, 'media.type', 'default'); |
|
110 | + $typecode = $this->getValue($list, 'product.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', 'product', $type ); |
|
126 | + $list['media.typeid'] = $this->getTypeId('media/type', 'product', $type); |
|
127 | 127 | $list['media.domain'] = 'product'; |
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['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'media', $typecode ); |
|
133 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'media', $typecode); |
|
134 | 134 | $list['product.lists.parentid'] = $product->getId(); |
135 | 135 | $list['product.lists.refid'] = $refItem->getId(); |
136 | 136 | $list['product.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( $product, $data ); |
|
150 | + $data = $this->getObject()->process($product, $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'] ) || $list['media.url'] === '' || isset( $list['product.lists.type'] ) |
|
197 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
196 | + if (!isset($list['media.url']) || $list['media.url'] === '' || isset($list['product.lists.type']) |
|
197 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
198 | 198 | ) { |
199 | 199 | return false; |
200 | 200 | } |
@@ -69,8 +69,7 @@ discard block |
||
69 | 69 | { |
70 | 70 | $item = $propMap[ $list['product.property.value'] ][$typecode]; |
71 | 71 | unset( $items[ $item->getId() ] ); |
72 | - } |
|
73 | - else |
|
72 | + } else |
|
74 | 73 | { |
75 | 74 | $item = $manager->createItem(); |
76 | 75 | } |
@@ -84,8 +83,7 @@ discard block |
||
84 | 83 | $data = $this->getObject()->process( $product, $data ); |
85 | 84 | |
86 | 85 | $manager->commit(); |
87 | - } |
|
88 | - catch( \Exception $e ) |
|
86 | + } catch( \Exception $e ) |
|
89 | 87 | { |
90 | 88 | $manager->rollback(); |
91 | 89 | throw $e; |
@@ -40,52 +40,52 @@ discard block |
||
40 | 40 | * @param array $data List of CSV fields with position as key and data as value |
41 | 41 | * @return array List of data which hasn't been imported |
42 | 42 | */ |
43 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
43 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
44 | 44 | { |
45 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/property' ); |
|
45 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/property'); |
|
46 | 46 | $manager->begin(); |
47 | 47 | |
48 | 48 | try |
49 | 49 | { |
50 | 50 | $propMap = []; |
51 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
52 | - $items = $this->getPropertyItems( $product->getId() ); |
|
51 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
52 | + $items = $this->getPropertyItems($product->getId()); |
|
53 | 53 | |
54 | - foreach( $items as $item ) { |
|
55 | - $propMap[ $item->getValue() ][ $item->getType() ] = $item; |
|
54 | + foreach ($items as $item) { |
|
55 | + $propMap[$item->getValue()][$item->getType()] = $item; |
|
56 | 56 | } |
57 | 57 | |
58 | - foreach( $map as $list ) |
|
58 | + foreach ($map as $list) |
|
59 | 59 | { |
60 | - if( $list['product.property.type'] == '' || $list['product.property.value'] == '' ) { |
|
60 | + if ($list['product.property.type'] == '' || $list['product.property.value'] == '') { |
|
61 | 61 | continue; |
62 | 62 | } |
63 | 63 | |
64 | 64 | $typecode = $list['product.property.type']; |
65 | - $list['product.property.typeid'] = $this->getTypeId( 'product/property/type', 'product', $typecode ); |
|
65 | + $list['product.property.typeid'] = $this->getTypeId('product/property/type', 'product', $typecode); |
|
66 | 66 | $list['product.property.parentid'] = $product->getId(); |
67 | 67 | |
68 | - if( isset( $propMap[ $list['product.property.value'] ][$typecode] ) ) |
|
68 | + if (isset($propMap[$list['product.property.value']][$typecode])) |
|
69 | 69 | { |
70 | - $item = $propMap[ $list['product.property.value'] ][$typecode]; |
|
71 | - unset( $items[ $item->getId() ] ); |
|
70 | + $item = $propMap[$list['product.property.value']][$typecode]; |
|
71 | + unset($items[$item->getId()]); |
|
72 | 72 | } |
73 | 73 | else |
74 | 74 | { |
75 | 75 | $item = $manager->createItem(); |
76 | 76 | } |
77 | 77 | |
78 | - $item->fromArray( $list ); |
|
79 | - $manager->saveItem( $item, false ); |
|
78 | + $item->fromArray($list); |
|
79 | + $manager->saveItem($item, false); |
|
80 | 80 | } |
81 | 81 | |
82 | - $manager->deleteItems( array_keys( $items ) ); |
|
82 | + $manager->deleteItems(array_keys($items)); |
|
83 | 83 | |
84 | - $data = $this->getObject()->process( $product, $data ); |
|
84 | + $data = $this->getObject()->process($product, $data); |
|
85 | 85 | |
86 | 86 | $manager->commit(); |
87 | 87 | } |
88 | - catch( \Exception $e ) |
|
88 | + catch (\Exception $e) |
|
89 | 89 | { |
90 | 90 | $manager->rollback(); |
91 | 91 | throw $e; |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | * @param string $prodid Unique product ID |
102 | 102 | * @return array Associative list of product property items |
103 | 103 | */ |
104 | - protected function getPropertyItems( $prodid ) |
|
104 | + protected function getPropertyItems($prodid) |
|
105 | 105 | { |
106 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/property' ); |
|
106 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/property'); |
|
107 | 107 | |
108 | 108 | $search = $manager->createSearch(); |
109 | - $search->setConditions( $search->compare( '==', 'product.property.parentid', $prodid ) ); |
|
109 | + $search->setConditions($search->compare('==', 'product.property.parentid', $prodid)); |
|
110 | 110 | |
111 | - return $manager->searchItems( $search ); |
|
111 | + return $manager->searchItems($search); |
|
112 | 112 | } |
113 | 113 | } |
@@ -127,8 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $listItem = $listMap[$code][$typecode]; |
129 | 129 | unset( $listItems[ $listItem->getId() ] ); |
130 | - } |
|
131 | - else |
|
130 | + } else |
|
132 | 131 | { |
133 | 132 | $listItem = $listManager->createItem(); |
134 | 133 | } |
@@ -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/attribute/listtypes |
52 | 52 | * Names of the product list types for attributes that are updated or removed |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * @see controller/common/product/import/csv/processor/price/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/attribute/listtypes'); |
|
70 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/attribute/listtypes'); |
|
71 | 71 | |
72 | - $this->cache = $this->getCache( 'attribute' ); |
|
72 | + $this->cache = $this->getCache('attribute'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -80,71 +80,71 @@ 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, 'attribute' ); |
|
87 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists' ); |
|
88 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
86 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'attribute'); |
|
87 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists'); |
|
88 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
89 | 89 | |
90 | 90 | $manager->begin(); |
91 | 91 | |
92 | 92 | try |
93 | 93 | { |
94 | 94 | $listMap = []; |
95 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
96 | - $listItems = $product->getListItems( 'attribute', $this->listTypes ); |
|
95 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
96 | + $listItems = $product->getListItems('attribute', $this->listTypes); |
|
97 | 97 | |
98 | - foreach( $listItems as $listItem ) |
|
98 | + foreach ($listItems as $listItem) |
|
99 | 99 | { |
100 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
101 | - $listMap[ $refItem->getCode() ][ $listItem->getType() ] = $listItem; |
|
100 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
101 | + $listMap[$refItem->getCode()][$listItem->getType()] = $listItem; |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | - foreach( $map as $pos => $list ) |
|
105 | + foreach ($map as $pos => $list) |
|
106 | 106 | { |
107 | - if( $this->checkEntry( $list ) === false ) { |
|
107 | + if ($this->checkEntry($list) === false) { |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | |
111 | - $codes = explode( $separator, $list['attribute.code'] ); |
|
111 | + $codes = explode($separator, $list['attribute.code']); |
|
112 | 112 | |
113 | - foreach( $codes as $code ) |
|
113 | + foreach ($codes as $code) |
|
114 | 114 | { |
115 | - $attrItem = $this->getAttributeItem( $code, $list['attribute.type'] ); |
|
116 | - $attrItem->fromArray( $list ); |
|
117 | - $attrItem->setCode( $code ); |
|
118 | - $attrItem = $manager->saveItem( $attrItem ); |
|
115 | + $attrItem = $this->getAttributeItem($code, $list['attribute.type']); |
|
116 | + $attrItem->fromArray($list); |
|
117 | + $attrItem->setCode($code); |
|
118 | + $attrItem = $manager->saveItem($attrItem); |
|
119 | 119 | |
120 | - $typecode = $this->getValue( $list, 'product.lists.type', 'default' ); |
|
121 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'attribute', $typecode ); |
|
120 | + $typecode = $this->getValue($list, 'product.lists.type', 'default'); |
|
121 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'attribute', $typecode); |
|
122 | 122 | $list['product.lists.refid'] = $attrItem->getId(); |
123 | 123 | $list['product.lists.parentid'] = $product->getId(); |
124 | 124 | $list['product.lists.domain'] = 'attribute'; |
125 | 125 | |
126 | - if( isset( $listMap[$code][$typecode] ) ) |
|
126 | + if (isset($listMap[$code][$typecode])) |
|
127 | 127 | { |
128 | 128 | $listItem = $listMap[$code][$typecode]; |
129 | - unset( $listItems[ $listItem->getId() ] ); |
|
129 | + unset($listItems[$listItem->getId()]); |
|
130 | 130 | } |
131 | 131 | else |
132 | 132 | { |
133 | 133 | $listItem = $listManager->createItem(); |
134 | 134 | } |
135 | 135 | |
136 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
137 | - $listManager->saveItem( $listItem, false ); |
|
136 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
137 | + $listManager->saveItem($listItem, false); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
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,11 +160,11 @@ discard block |
||
160 | 160 | * @param array $list Associative list of key/value pairs from the mapped data |
161 | 161 | * @return boolean True if the entry is valid, false if not |
162 | 162 | */ |
163 | - protected function checkEntry( array $list ) |
|
163 | + protected function checkEntry(array $list) |
|
164 | 164 | { |
165 | - if( !isset( $list['attribute.code'] ) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
166 | - || isset( $list['product.lists.type'] ) && $this->listTypes !== null |
|
167 | - && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
165 | + if (!isset($list['attribute.code']) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
166 | + || isset($list['product.lists.type']) && $this->listTypes !== null |
|
167 | + && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
168 | 168 | ) { |
169 | 169 | return false; |
170 | 170 | } |
@@ -180,22 +180,22 @@ discard block |
||
180 | 180 | * @param string $type Attribute type |
181 | 181 | * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item object |
182 | 182 | */ |
183 | - protected function getAttributeItem( $code, $type ) |
|
183 | + protected function getAttributeItem($code, $type) |
|
184 | 184 | { |
185 | - if( ( $item = $this->cache->get( $code, $type ) ) === null ) |
|
185 | + if (($item = $this->cache->get($code, $type)) === null) |
|
186 | 186 | { |
187 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
187 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
188 | 188 | |
189 | 189 | $item = $manager->createItem(); |
190 | - $item->setTypeId( $this->getTypeId( 'attribute/type', 'product', $type ) ); |
|
191 | - $item->setDomain( 'product' ); |
|
192 | - $item->setLabel( $type . ' ' . $code ); |
|
193 | - $item->setCode( $code ); |
|
194 | - $item->setStatus( 1 ); |
|
190 | + $item->setTypeId($this->getTypeId('attribute/type', 'product', $type)); |
|
191 | + $item->setDomain('product'); |
|
192 | + $item->setLabel($type . ' ' . $code); |
|
193 | + $item->setCode($code); |
|
194 | + $item->setStatus(1); |
|
195 | 195 | |
196 | - $item = $manager->saveItem( $item ); |
|
196 | + $item = $manager->saveItem($item); |
|
197 | 197 | |
198 | - $this->cache->set( $item ); |
|
198 | + $this->cache->set($item); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | return $item; |