@@ -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 | } |
@@ -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 | } |
@@ -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,47 +77,47 @@ 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, trim( $list['media.url'] ) ); |
|
109 | - $type = trim( $this->getValue( $list, 'media.type', 'default' ) ); |
|
110 | - $typecode = trim( $this->getValue( $list, 'product.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, 'product.lists.type', 'default')); |
|
111 | 111 | |
112 | - foreach( $urls as $url ) |
|
112 | + foreach ($urls as $url) |
|
113 | 113 | { |
114 | - $url = trim( $url ); |
|
114 | + $url = trim($url); |
|
115 | 115 | |
116 | - if( isset( $listMap[$url][$type][$typecode] ) ) |
|
116 | + if (isset($listMap[$url][$type][$typecode])) |
|
117 | 117 | { |
118 | 118 | $listItem = $listMap[$url][$type][$typecode]; |
119 | 119 | $refItem = $listItem->getRefItem(); |
120 | - unset( $listItems[ $listItem->getId() ] ); |
|
120 | + unset($listItems[$listItem->getId()]); |
|
121 | 121 | } |
122 | 122 | else |
123 | 123 | { |
@@ -125,35 +125,35 @@ discard block |
||
125 | 125 | $refItem = $manager->createItem(); |
126 | 126 | } |
127 | 127 | |
128 | - $list['media.typeid'] = $this->getTypeId( 'media/type', 'product', $type ); |
|
128 | + $list['media.typeid'] = $this->getTypeId('media/type', 'product', $type); |
|
129 | 129 | $list['media.domain'] = 'product'; |
130 | 130 | $list['media.url'] = $url; |
131 | 131 | |
132 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
133 | - $refItem = $manager->saveItem( $refItem ); |
|
132 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
133 | + $refItem = $manager->saveItem($refItem); |
|
134 | 134 | |
135 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'media', $typecode ); |
|
135 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'media', $typecode); |
|
136 | 136 | $list['product.lists.parentid'] = $product->getId(); |
137 | 137 | $list['product.lists.refid'] = $refItem->getId(); |
138 | 138 | $list['product.lists.domain'] = 'media'; |
139 | 139 | |
140 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
141 | - $listManager->saveItem( $listItem, false ); |
|
140 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
141 | + $listManager->saveItem($listItem, false); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - foreach( $listItems as $listItem ) { |
|
145 | + foreach ($listItems as $listItem) { |
|
146 | 146 | $delete[] = $listItem->getRefId(); |
147 | 147 | } |
148 | 148 | |
149 | - $manager->deleteItems( $delete ); |
|
150 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
149 | + $manager->deleteItems($delete); |
|
150 | + $listManager->deleteItems(array_keys($listItems)); |
|
151 | 151 | |
152 | - $data = $this->getObject()->process( $product, $data ); |
|
152 | + $data = $this->getObject()->process($product, $data); |
|
153 | 153 | |
154 | 154 | $manager->commit(); |
155 | 155 | } |
156 | - catch( \Exception $e ) |
|
156 | + catch (\Exception $e) |
|
157 | 157 | { |
158 | 158 | $manager->rollback(); |
159 | 159 | throw $e; |
@@ -169,17 +169,17 @@ discard block |
||
169 | 169 | * @param array $list Associative list of domain item keys and their values, e.g. "media.status" => 1 |
170 | 170 | * @return array Given associative list enriched by default values if they were not already set |
171 | 171 | */ |
172 | - protected function addItemDefaults( array $list ) |
|
172 | + protected function addItemDefaults(array $list) |
|
173 | 173 | { |
174 | - if( !isset( $list['media.label'] ) ) { |
|
174 | + if (!isset($list['media.label'])) { |
|
175 | 175 | $list['media.label'] = $list['media.url']; |
176 | 176 | } |
177 | 177 | |
178 | - if( !isset( $list['media.preview'] ) ) { |
|
178 | + if (!isset($list['media.preview'])) { |
|
179 | 179 | $list['media.preview'] = $list['media.url']; |
180 | 180 | } |
181 | 181 | |
182 | - if( !isset( $list['media.status'] ) ) { |
|
182 | + if (!isset($list['media.status'])) { |
|
183 | 183 | $list['media.status'] = 1; |
184 | 184 | } |
185 | 185 | |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * @param array $list Associative list of key/value pairs from the mapping |
194 | 194 | * @return boolean True if valid, false if not |
195 | 195 | */ |
196 | - protected function checkEntry( array $list ) |
|
196 | + protected function checkEntry(array $list) |
|
197 | 197 | { |
198 | - if( !isset( $list['media.url'] ) || trim( $list['media.url'] ) === '' || isset( $list['product.lists.type'] ) |
|
199 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
198 | + if (!isset($list['media.url']) || trim($list['media.url']) === '' || isset($list['product.lists.type']) |
|
199 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
200 | 200 | ) { |
201 | 201 | return false; |
202 | 202 | } |
@@ -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,73 +80,73 @@ 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, trim( $list['attribute.code'] ) ); |
|
111 | + $codes = explode($separator, trim($list['attribute.code'])); |
|
112 | 112 | |
113 | - foreach( $codes as $code ) |
|
113 | + foreach ($codes as $code) |
|
114 | 114 | { |
115 | - $code = trim( $code ); |
|
115 | + $code = trim($code); |
|
116 | 116 | |
117 | - $attrItem = $this->getAttributeItem( $code, trim( $list['attribute.type'] ) ); |
|
118 | - $attrItem->fromArray( $list ); |
|
119 | - $attrItem->setCode( $code ); |
|
120 | - $attrItem = $manager->saveItem( $attrItem ); |
|
117 | + $attrItem = $this->getAttributeItem($code, trim($list['attribute.type'])); |
|
118 | + $attrItem->fromArray($list); |
|
119 | + $attrItem->setCode($code); |
|
120 | + $attrItem = $manager->saveItem($attrItem); |
|
121 | 121 | |
122 | - $typecode = trim( $this->getValue( $list, 'product.lists.type', 'default' ) ); |
|
123 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'attribute', $typecode ); |
|
122 | + $typecode = trim($this->getValue($list, 'product.lists.type', 'default')); |
|
123 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'attribute', $typecode); |
|
124 | 124 | $list['product.lists.refid'] = $attrItem->getId(); |
125 | 125 | $list['product.lists.parentid'] = $product->getId(); |
126 | 126 | $list['product.lists.domain'] = 'attribute'; |
127 | 127 | |
128 | - if( isset( $listMap[$code][$typecode] ) ) |
|
128 | + if (isset($listMap[$code][$typecode])) |
|
129 | 129 | { |
130 | 130 | $listItem = $listMap[$code][$typecode]; |
131 | - unset( $listItems[ $listItem->getId() ] ); |
|
131 | + unset($listItems[$listItem->getId()]); |
|
132 | 132 | } |
133 | 133 | else |
134 | 134 | { |
135 | 135 | $listItem = $listManager->createItem(); |
136 | 136 | } |
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 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
143 | + $listManager->deleteItems(array_keys($listItems)); |
|
144 | 144 | |
145 | - $data = $this->getObject()->process( $product, $data ); |
|
145 | + $data = $this->getObject()->process($product, $data); |
|
146 | 146 | |
147 | 147 | $manager->commit(); |
148 | 148 | } |
149 | - catch( \Exception $e ) |
|
149 | + catch (\Exception $e) |
|
150 | 150 | { |
151 | 151 | $manager->rollback(); |
152 | 152 | throw $e; |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * @param array $list Associative list of key/value pairs from the mapped data |
163 | 163 | * @return boolean True if the entry is valid, false if not |
164 | 164 | */ |
165 | - protected function checkEntry( array $list ) |
|
165 | + protected function checkEntry(array $list) |
|
166 | 166 | { |
167 | - if( !isset( $list['attribute.code'] ) || trim( $list['attribute.code'] ) === '' |
|
168 | - || trim( $list['attribute.type'] ) === '' || isset( $list['product.lists.type'] ) |
|
169 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
167 | + if (!isset($list['attribute.code']) || trim($list['attribute.code']) === '' |
|
168 | + || trim($list['attribute.type']) === '' || isset($list['product.lists.type']) |
|
169 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
170 | 170 | ) { |
171 | 171 | return false; |
172 | 172 | } |
@@ -182,22 +182,22 @@ discard block |
||
182 | 182 | * @param string $type Attribute type |
183 | 183 | * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item object |
184 | 184 | */ |
185 | - protected function getAttributeItem( $code, $type ) |
|
185 | + protected function getAttributeItem($code, $type) |
|
186 | 186 | { |
187 | - if( ( $item = $this->cache->get( $code, $type ) ) === null ) |
|
187 | + if (($item = $this->cache->get($code, $type)) === null) |
|
188 | 188 | { |
189 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
189 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
190 | 190 | |
191 | 191 | $item = $manager->createItem(); |
192 | - $item->setTypeId( $this->getTypeId( 'attribute/type', 'product', $type ) ); |
|
193 | - $item->setDomain( 'product' ); |
|
194 | - $item->setLabel( $code ); |
|
195 | - $item->setCode( $code ); |
|
196 | - $item->setStatus( 1 ); |
|
192 | + $item->setTypeId($this->getTypeId('attribute/type', 'product', $type)); |
|
193 | + $item->setDomain('product'); |
|
194 | + $item->setLabel($code); |
|
195 | + $item->setCode($code); |
|
196 | + $item->setStatus(1); |
|
197 | 197 | |
198 | - $item = $manager->saveItem( $item ); |
|
198 | + $item = $manager->saveItem($item); |
|
199 | 199 | |
200 | - $this->cache->set( $item ); |
|
200 | + $this->cache->set($item); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return $item; |
@@ -145,8 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | $listItem = $listMap[$catid][$type]; |
147 | 147 | unset( $listItems[ $listItem->getId() ] ); |
148 | - } |
|
149 | - else |
|
148 | + } else |
|
150 | 149 | { |
151 | 150 | $listItem = $listManager->createItem(); |
152 | 151 | } |
@@ -160,8 +159,7 @@ discard block |
||
160 | 159 | $data = $this->getObject()->process( $product, $data ); |
161 | 160 | |
162 | 161 | $manager->commit(); |
163 | - } |
|
164 | - catch( \Exception $e ) |
|
162 | + } catch( \Exception $e ) |
|
165 | 163 | { |
166 | 164 | $manager->rollback(); |
167 | 165 | 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/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 | } |
@@ -131,8 +131,7 @@ |
||
131 | 131 | $data = $this->getObject()->process( $product, $data ); |
132 | 132 | |
133 | 133 | $manager->commit(); |
134 | - } |
|
135 | - catch( \Exception $e ) |
|
134 | + } catch( \Exception $e ) |
|
136 | 135 | { |
137 | 136 | $manager->rollback(); |
138 | 137 | 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 | } |
@@ -111,8 +111,7 @@ discard block |
||
111 | 111 | $listItem = $listMap[$value][$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; |
@@ -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,13 +160,13 @@ 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.label'] ) ) { |
|
165 | + if (!isset($list['price.label'])) { |
|
166 | 166 | $list['price.label'] = $list['price.currencyid'] . ' ' . $list['price.value']; |
167 | 167 | } |
168 | 168 | |
169 | - if( !isset( $list['price.status'] ) ) { |
|
169 | + if (!isset($list['price.status'])) { |
|
170 | 170 | $list['price.status'] = 1; |
171 | 171 | } |
172 | 172 | |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | * @param array $list Associative list of key/value pairs from the mapping |
181 | 181 | * @return boolean True if valid, false if not |
182 | 182 | */ |
183 | - protected function checkEntry( array $list ) |
|
183 | + protected function checkEntry(array $list) |
|
184 | 184 | { |
185 | - if( !isset( $list['price.value'] ) || trim( $list['price.value'] ) === '' || isset( $list['product.lists.type'] ) |
|
186 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
185 | + if (!isset($list['price.value']) || trim($list['price.value']) === '' || isset($list['product.lists.type']) |
|
186 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
187 | 187 | ) { |
188 | 188 | return false; |
189 | 189 | } |
@@ -351,8 +351,7 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | $container->close(); |
354 | - } |
|
355 | - catch( \Exception $e ) |
|
354 | + } catch( \Exception $e ) |
|
356 | 355 | { |
357 | 356 | $logger->log( 'Product import error: ' . $e->getMessage() ); |
358 | 357 | $logger->log( $e->getTraceAsString() ); |
@@ -540,8 +539,7 @@ discard block |
||
540 | 539 | } |
541 | 540 | |
542 | 541 | $manager->commit(); |
543 | - } |
|
544 | - catch( \Exception $e ) |
|
542 | + } catch( \Exception $e ) |
|
545 | 543 | { |
546 | 544 | $manager->rollback(); |
547 | 545 |
@@ -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,15 +488,15 @@ 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 | - if( $location === null ) |
|
493 | + if ($location === null) |
|
494 | 494 | { |
495 | - $msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/product/import/csv/location' ); |
|
496 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
495 | + $msg = sprintf('Required configuration for "%1$s" is missing', 'controller/jobs/product/import/csv/location'); |
|
496 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
497 | 497 | } |
498 | 498 | |
499 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
499 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -511,56 +511,56 @@ discard block |
||
511 | 511 | * @return integer Number of products that couldn't be imported |
512 | 512 | * @throws \Aimeos\Controller\Jobs\Exception |
513 | 513 | */ |
514 | - protected function import( array $products, array $data, array $mapping, |
|
515 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict ) |
|
514 | + protected function import(array $products, array $data, array $mapping, |
|
515 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict) |
|
516 | 516 | { |
517 | 517 | $errors = 0; |
518 | 518 | $context = $this->getContext(); |
519 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
519 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
520 | 520 | |
521 | - foreach( $data as $code => $list ) |
|
521 | + foreach ($data as $code => $list) |
|
522 | 522 | { |
523 | 523 | $manager->begin(); |
524 | 524 | |
525 | 525 | try |
526 | 526 | { |
527 | - $code = trim( $code ); |
|
527 | + $code = trim($code); |
|
528 | 528 | |
529 | - if( isset( $products[$code] ) ) { |
|
529 | + if (isset($products[$code])) { |
|
530 | 530 | $product = $products[$code]; |
531 | 531 | } else { |
532 | 532 | $product = $manager->createItem(); |
533 | 533 | } |
534 | 534 | |
535 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
535 | + $map = $this->getMappedChunk($list, $mapping); |
|
536 | 536 | |
537 | - if( isset( $map[0] ) ) |
|
537 | + if (isset($map[0])) |
|
538 | 538 | { |
539 | 539 | $map = $map[0]; // there can only be one chunk for the base product data |
540 | 540 | |
541 | - $typecode = trim( isset( $map['product.type'] ) ? $map['product.type'] : 'default' ); |
|
542 | - $map['product.typeid'] = $this->getTypeId( 'product/type', 'product', $typecode ); |
|
541 | + $typecode = trim(isset($map['product.type']) ? $map['product.type'] : 'default'); |
|
542 | + $map['product.typeid'] = $this->getTypeId('product/type', 'product', $typecode); |
|
543 | 543 | |
544 | - $product->fromArray( $this->addItemDefaults( $map ) ); |
|
545 | - $product = $manager->saveItem( $product ); |
|
544 | + $product->fromArray($this->addItemDefaults($map)); |
|
545 | + $product = $manager->saveItem($product); |
|
546 | 546 | |
547 | - $list = $processor->process( $product, $list ); |
|
547 | + $list = $processor->process($product, $list); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | $manager->commit(); |
551 | 551 | } |
552 | - catch( \Exception $e ) |
|
552 | + catch (\Exception $e) |
|
553 | 553 | { |
554 | 554 | $manager->rollback(); |
555 | 555 | |
556 | - $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
557 | - $context->getLogger()->log( $msg ); |
|
556 | + $msg = sprintf('Unable to import product with code "%1$s": %2$s', $code, $e->getMessage()); |
|
557 | + $context->getLogger()->log($msg); |
|
558 | 558 | |
559 | 559 | $errors++; |
560 | 560 | } |
561 | 561 | |
562 | - if( $strict && !empty( $list ) ) { |
|
563 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
562 | + if ($strict && !empty($list)) { |
|
563 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
564 | 564 | } |
565 | 565 | } |
566 | 566 | |
@@ -574,9 +574,9 @@ discard block |
||
574 | 574 | * @param array $list Associative list of domain item keys and their values, e.g. "product.status" => 1 |
575 | 575 | * @return array Given associative list enriched by default values if they were not already set |
576 | 576 | */ |
577 | - protected function addItemDefaults( array $list ) |
|
577 | + protected function addItemDefaults(array $list) |
|
578 | 578 | { |
579 | - if( !isset( $list['product.status'] ) ) { |
|
579 | + if (!isset($list['product.status'])) { |
|
580 | 580 | $list['product.status'] = 1; |
581 | 581 | } |
582 | 582 |