@@ -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; |
@@ -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 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product site map' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Product site map'); |
|
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', 'Creates a product site map for search engines' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Creates a product site map for search engines'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | { |
53 | 53 | $container = $this->createContainer(); |
54 | 54 | |
55 | - $files = $this->export( $container ); |
|
56 | - $this->createSitemapIndex( $container, $files ); |
|
55 | + $files = $this->export($container); |
|
56 | + $this->createSitemapIndex($container, $files); |
|
57 | 57 | |
58 | 58 | $container->close(); |
59 | 59 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param \Aimeos\MW\Container\Content\Iface $content File content object |
66 | 66 | * @param \Aimeos\MShop\Product\Item\Iface[] $items List of product items |
67 | 67 | */ |
68 | - protected function addItems( \Aimeos\MW\Container\Content\Iface $content, array $items ) |
|
68 | + protected function addItems(\Aimeos\MW\Container\Content\Iface $content, array $items) |
|
69 | 69 | { |
70 | 70 | $config = $this->getContext()->getConfig(); |
71 | 71 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @see controller/jobs/product/export/sitemap/max-items |
97 | 97 | * @see controller/jobs/product/export/sitemap/max-query |
98 | 98 | */ |
99 | - $changefreq = $config->get( 'controller/jobs/product/export/sitemap/changefreq', 'daily' ); |
|
99 | + $changefreq = $config->get('controller/jobs/product/export/sitemap/changefreq', 'daily'); |
|
100 | 100 | |
101 | 101 | /** controller/jobs/product/export/sitemap/standard/template-items |
102 | 102 | * Relative path to the XML items template of the product site map job controller. |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $view->siteItems = $items; |
130 | 130 | $view->siteFreq = $changefreq; |
131 | 131 | |
132 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
132 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @see controller/jobs/product/export/sitemap/max-query |
176 | 176 | * @see controller/jobs/product/export/sitemap/changefreq |
177 | 177 | */ |
178 | - $location = $config->get( 'controller/jobs/product/export/sitemap/location' ); |
|
178 | + $location = $config->get('controller/jobs/product/export/sitemap/location'); |
|
179 | 179 | |
180 | 180 | /** controller/jobs/product/export/sitemap/container/options |
181 | 181 | * List of file container options for the site map files |
@@ -196,16 +196,16 @@ discard block |
||
196 | 196 | * @see controller/jobs/product/export/sitemap/max-query |
197 | 197 | * @see controller/jobs/product/export/sitemap/changefreq |
198 | 198 | */ |
199 | - $default = array( 'gzip-mode' => 'wb' ); |
|
200 | - $options = $config->get( 'controller/jobs/product/export/sitemap/container/options', $default ); |
|
199 | + $default = array('gzip-mode' => 'wb'); |
|
200 | + $options = $config->get('controller/jobs/product/export/sitemap/container/options', $default); |
|
201 | 201 | |
202 | - if( $location === null ) |
|
202 | + if ($location === null) |
|
203 | 203 | { |
204 | - $msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/product/export/sitemap/location' ); |
|
205 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
204 | + $msg = sprintf('Required configuration for "%1$s" is missing', 'controller/jobs/product/export/sitemap/location'); |
|
205 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
206 | 206 | } |
207 | 207 | |
208 | - return \Aimeos\MW\Container\Factory::getContainer( $location, 'Directory', 'Gzip', $options ); |
|
208 | + return \Aimeos\MW\Container\Factory::getContainer($location, 'Directory', 'Gzip', $options); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @param integer $filenum New file number |
217 | 217 | * @return \Aimeos\MW\Container\Content\Iface New content object |
218 | 218 | */ |
219 | - protected function createContent( \Aimeos\MW\Container\Iface $container, $filenum ) |
|
219 | + protected function createContent(\Aimeos\MW\Container\Iface $container, $filenum) |
|
220 | 220 | { |
221 | 221 | /** controller/jobs/product/export/sitemap/standard/template-header |
222 | 222 | * Relative path to the XML site map header template of the product site map job controller. |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | $context = $this->getContext(); |
247 | 247 | $view = $context->getView(); |
248 | 248 | |
249 | - $content = $container->create( $this->getFilename( $filenum ) ); |
|
250 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
251 | - $container->add( $content ); |
|
249 | + $content = $container->create($this->getFilename($filenum)); |
|
250 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
251 | + $container->add($content); |
|
252 | 252 | |
253 | 253 | return $content; |
254 | 254 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @param \Aimeos\MW\Container\Content\Iface $content |
261 | 261 | */ |
262 | - protected function closeContent( \Aimeos\MW\Container\Content\Iface $content ) |
|
262 | + protected function closeContent(\Aimeos\MW\Container\Content\Iface $content) |
|
263 | 263 | { |
264 | 264 | /** controller/jobs/product/export/sitemap/standard/template-footer |
265 | 265 | * Relative path to the XML site map footer template of the product site map job controller. |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $context = $this->getContext(); |
290 | 290 | $view = $context->getView(); |
291 | 291 | |
292 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
292 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param \Aimeos\MW\Container\Iface $container File container object |
300 | 300 | * @param array $files List of generated site map file names |
301 | 301 | */ |
302 | - protected function createSitemapIndex( \Aimeos\MW\Container\Iface $container, array $files ) |
|
302 | + protected function createSitemapIndex(\Aimeos\MW\Container\Iface $container, array $files) |
|
303 | 303 | { |
304 | 304 | /** controller/jobs/product/export/sitemap/standard/template-index |
305 | 305 | * Relative path to the XML site map index template of the product site map job controller. |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | |
332 | 332 | $view->siteFiles = $files; |
333 | 333 | |
334 | - $content = $container->create( 'aimeos-sitemap-index.xml' ); |
|
335 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
336 | - $container->add( $content ); |
|
334 | + $content = $container->create('aimeos-sitemap-index.xml'); |
|
335 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
336 | + $container->add($content); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | |
@@ -344,11 +344,11 @@ discard block |
||
344 | 344 | * @param mixed $default Default value if name is unknown |
345 | 345 | * @return mixed Configuration value |
346 | 346 | */ |
347 | - protected function getConfig( $name, $default = null ) |
|
347 | + protected function getConfig($name, $default = null) |
|
348 | 348 | { |
349 | 349 | $config = $this->getContext()->getConfig(); |
350 | 350 | |
351 | - switch( $name ) |
|
351 | + switch ($name) |
|
352 | 352 | { |
353 | 353 | case 'domain': |
354 | 354 | return []; |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @see controller/jobs/product/export/sitemap/max-query |
376 | 376 | * @see controller/jobs/product/export/sitemap/changefreq |
377 | 377 | */ |
378 | - return $config->get( 'controller/jobs/product/export/sitemap/max-items', 50000 ); |
|
378 | + return $config->get('controller/jobs/product/export/sitemap/max-items', 50000); |
|
379 | 379 | |
380 | 380 | case 'max-query': |
381 | 381 | /** controller/jobs/product/export/sitemap/max-query |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | * @see controller/jobs/product/export/sitemap/max-items |
396 | 396 | * @see controller/jobs/product/export/sitemap/changefreq |
397 | 397 | */ |
398 | - return $config->get( 'controller/jobs/product/export/sitemap/max-query', 1000 ); |
|
398 | + return $config->get('controller/jobs/product/export/sitemap/max-query', 1000); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | return $default; |
@@ -408,8 +408,8 @@ discard block |
||
408 | 408 | * @param integer $number Current file number |
409 | 409 | * @return string New file name |
410 | 410 | */ |
411 | - protected function getFilename( $number ) |
|
411 | + protected function getFilename($number) |
|
412 | 412 | { |
413 | - return sprintf( 'aimeos-sitemap-%d.xml', $number ); |
|
413 | + return sprintf('aimeos-sitemap-%d.xml', $number); |
|
414 | 414 | } |
415 | 415 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Catalog import CSV' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Catalog import CSV'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getDescription() |
41 | 41 | { |
42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Imports new and updates existing categories from CSV files' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing categories from CSV files'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $context = $this->getContext(); |
55 | 55 | $config = $context->getConfig(); |
56 | 56 | $logger = $context->getLogger(); |
57 | - $domains = array( 'media', 'text' ); |
|
57 | + $domains = array('media', 'text'); |
|
58 | 58 | $mappings = $this->getDefaultMapping(); |
59 | 59 | |
60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @see controller/common/catalog/import/csv/converter |
75 | 75 | * @see controller/common/catalog/import/csv/max-size |
76 | 76 | */ |
77 | - $domains = $config->get( 'controller/common/catalog/import/csv/domains', $domains ); |
|
77 | + $domains = $config->get('controller/common/catalog/import/csv/domains', $domains); |
|
78 | 78 | |
79 | 79 | /** controller/jobs/catalog/import/csv/domains |
80 | 80 | * List of item domain names that should be retrieved along with the catalog items |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @see controller/jobs/catalog/import/csv/backup |
95 | 95 | * @see controller/common/catalog/import/csv/max-size |
96 | 96 | */ |
97 | - $domains = $config->get( 'controller/jobs/catalog/import/csv/domains', $domains ); |
|
97 | + $domains = $config->get('controller/jobs/catalog/import/csv/domains', $domains); |
|
98 | 98 | |
99 | 99 | |
100 | 100 | /** controller/common/catalog/import/csv/mapping |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @see controller/common/catalog/import/csv/converter |
123 | 123 | * @see controller/common/catalog/import/csv/max-size |
124 | 124 | */ |
125 | - $mappings = $config->get( 'controller/common/catalog/import/csv/mapping', $mappings ); |
|
125 | + $mappings = $config->get('controller/common/catalog/import/csv/mapping', $mappings); |
|
126 | 126 | |
127 | 127 | /** controller/jobs/catalog/import/csv/mapping |
128 | 128 | * List of mappings between the position in the CSV file and item keys |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @see controller/jobs/catalog/import/csv/backup |
143 | 143 | * @see controller/common/catalog/import/csv/max-size |
144 | 144 | */ |
145 | - $mappings = $config->get( 'controller/jobs/catalog/import/csv/mapping', $mappings ); |
|
145 | + $mappings = $config->get('controller/jobs/catalog/import/csv/mapping', $mappings); |
|
146 | 146 | |
147 | 147 | |
148 | 148 | /** controller/common/catalog/import/csv/converter |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @see controller/common/catalog/import/csv/mapping |
185 | 185 | * @see controller/common/catalog/import/csv/max-size |
186 | 186 | */ |
187 | - $converters = $config->get( 'controller/common/catalog/import/csv/converter', [] ); |
|
187 | + $converters = $config->get('controller/common/catalog/import/csv/converter', []); |
|
188 | 188 | |
189 | 189 | /** controller/jobs/catalog/import/csv/converter |
190 | 190 | * List of converter names for the values at the position in the CSV file |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @see controller/jobs/catalog/import/csv/backup |
205 | 205 | * @see controller/common/catalog/import/csv/max-size |
206 | 206 | */ |
207 | - $converters = $config->get( 'controller/jobs/catalog/import/csv/converter', $converters ); |
|
207 | + $converters = $config->get('controller/jobs/catalog/import/csv/converter', $converters); |
|
208 | 208 | |
209 | 209 | |
210 | 210 | /** controller/common/catalog/import/csv/max-size |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @see controller/common/catalog/import/csv/mapping |
225 | 225 | * @see controller/common/catalog/import/csv/converter |
226 | 226 | */ |
227 | - $maxcnt = (int) $config->get( 'controller/common/catalog/import/csv/max-size', 1000 ); |
|
227 | + $maxcnt = (int) $config->get('controller/common/catalog/import/csv/max-size', 1000); |
|
228 | 228 | |
229 | 229 | |
230 | 230 | /** controller/jobs/catalog/import/csv/skip-lines |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @see controller/jobs/catalog/import/csv/backup |
247 | 247 | * @see controller/common/catalog/import/csv/max-size |
248 | 248 | */ |
249 | - $skiplines = (int) $config->get( 'controller/jobs/catalog/import/csv/skip-lines', 0 ); |
|
249 | + $skiplines = (int) $config->get('controller/jobs/catalog/import/csv/skip-lines', 0); |
|
250 | 250 | |
251 | 251 | |
252 | 252 | /** controller/jobs/catalog/import/csv/strict |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @see controller/jobs/catalog/import/csv/backup |
271 | 271 | * @see controller/common/catalog/import/csv/max-size |
272 | 272 | */ |
273 | - $strict = (bool) $config->get( 'controller/jobs/catalog/import/csv/strict', true ); |
|
273 | + $strict = (bool) $config->get('controller/jobs/catalog/import/csv/strict', true); |
|
274 | 274 | |
275 | 275 | |
276 | 276 | /** controller/jobs/catalog/import/csv/backup |
@@ -303,75 +303,75 @@ discard block |
||
303 | 303 | * @see controller/jobs/catalog/import/csv/strict |
304 | 304 | * @see controller/common/catalog/import/csv/max-size |
305 | 305 | */ |
306 | - $backup = $config->get( 'controller/jobs/catalog/import/csv/backup' ); |
|
306 | + $backup = $config->get('controller/jobs/catalog/import/csv/backup'); |
|
307 | 307 | |
308 | 308 | |
309 | - if( !isset( $mappings['item'] ) || !is_array( $mappings['item'] ) ) |
|
309 | + if (!isset($mappings['item']) || !is_array($mappings['item'])) |
|
310 | 310 | { |
311 | - $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
|
312 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
311 | + $msg = sprintf('Required mapping key "%1$s" is missing or contains no array', 'item'); |
|
312 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | try |
316 | 316 | { |
317 | 317 | $procMappings = $mappings; |
318 | - unset( $procMappings['item'] ); |
|
318 | + unset($procMappings['item']); |
|
319 | 319 | |
320 | - $codePos = $this->getCodePosition( $mappings['item'] ); |
|
321 | - $convlist = $this->getConverterList( $converters ); |
|
322 | - $processor = $this->getProcessors( $procMappings ); |
|
323 | - $catalogMap = $this->getCatalogMap( $domains ); |
|
320 | + $codePos = $this->getCodePosition($mappings['item']); |
|
321 | + $convlist = $this->getConverterList($converters); |
|
322 | + $processor = $this->getProcessors($procMappings); |
|
323 | + $catalogMap = $this->getCatalogMap($domains); |
|
324 | 324 | $container = $this->getContainer(); |
325 | 325 | $path = $container->getName(); |
326 | 326 | |
327 | 327 | |
328 | - $msg = sprintf( 'Started catalog import from "%1$s" (%2$s)', $path, __CLASS__ ); |
|
329 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
328 | + $msg = sprintf('Started catalog import from "%1$s" (%2$s)', $path, __CLASS__); |
|
329 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
330 | 330 | |
331 | - foreach( $container as $content ) |
|
331 | + foreach ($container as $content) |
|
332 | 332 | { |
333 | 333 | $name = $content->getName(); |
334 | 334 | |
335 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
335 | + for ($i = 0; $i < $skiplines; $i++) { |
|
336 | 336 | $content->next(); |
337 | 337 | } |
338 | 338 | |
339 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
339 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
340 | 340 | { |
341 | - $data = $this->convertData( $convlist, $data ); |
|
342 | - $errcnt = $this->import( $catalogMap, $data, $mappings['item'], $processor, $strict ); |
|
343 | - $chunkcnt = count( $data ); |
|
341 | + $data = $this->convertData($convlist, $data); |
|
342 | + $errcnt = $this->import($catalogMap, $data, $mappings['item'], $processor, $strict); |
|
343 | + $chunkcnt = count($data); |
|
344 | 344 | |
345 | 345 | $msg = 'Imported catalog lines from "%1$s": %2$d/%3$d (%4$s)'; |
346 | - $logger->log( sprintf( $msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
346 | + $logger->log(sprintf($msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
347 | 347 | |
348 | 348 | $errors += $errcnt; |
349 | 349 | $total += $chunkcnt; |
350 | - unset( $data ); |
|
350 | + unset($data); |
|
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | 354 | $container->close(); |
355 | 355 | } |
356 | - catch( \Exception $e ) |
|
356 | + catch (\Exception $e) |
|
357 | 357 | { |
358 | - $logger->log( 'Catalog import error: ' . $e->getMessage() ); |
|
359 | - $logger->log( $e->getTraceAsString() ); |
|
358 | + $logger->log('Catalog import error: ' . $e->getMessage()); |
|
359 | + $logger->log($e->getTraceAsString()); |
|
360 | 360 | |
361 | - throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
|
361 | + throw new \Aimeos\Controller\Jobs\Exception($e->getMessage()); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | $msg = 'Finished catalog import from "%1$s": %2$d successful, %3$s errors, %4$s total (%5$s)'; |
365 | - $logger->log( sprintf( $msg, $path, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
365 | + $logger->log(sprintf($msg, $path, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
366 | 366 | |
367 | - if( $errors > 0 ) |
|
367 | + if ($errors > 0) |
|
368 | 368 | { |
369 | - $msg = sprintf( 'Invalid catalog lines in "%1$s": %2$d/%3$d', $path, $errors, $total ); |
|
370 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
369 | + $msg = sprintf('Invalid catalog lines in "%1$s": %2$d/%3$d', $path, $errors, $total); |
|
370 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
371 | 371 | } |
372 | 372 | |
373 | - if( !empty( $backup ) && @rename( $path, strftime( $backup ) ) === false ) { |
|
374 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Unable to move imported file' ) ); |
|
373 | + if (!empty($backup) && @rename($path, strftime($backup)) === false) { |
|
374 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to move imported file')); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
@@ -383,16 +383,16 @@ discard block |
||
383 | 383 | * @return integer Position of the "catalog.code" column |
384 | 384 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "catalog.code" is found |
385 | 385 | */ |
386 | - protected function getCodePosition( array $mapping ) |
|
386 | + protected function getCodePosition(array $mapping) |
|
387 | 387 | { |
388 | - foreach( $mapping as $pos => $key ) |
|
388 | + foreach ($mapping as $pos => $key) |
|
389 | 389 | { |
390 | - if( $key === 'catalog.code' ) { |
|
390 | + if ($key === 'catalog.code') { |
|
391 | 391 | return $pos; |
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
395 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "catalog.code" column in CSV mapping found' ) ); |
|
395 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "catalog.code" column in CSV mapping found')); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @see controller/jobs/catalog/import/csv/container/content |
428 | 428 | * @see controller/jobs/catalog/import/csv/container/options |
429 | 429 | */ |
430 | - $location = $config->get( 'controller/jobs/catalog/import/csv/location' ); |
|
430 | + $location = $config->get('controller/jobs/catalog/import/csv/location'); |
|
431 | 431 | |
432 | 432 | /** controller/jobs/catalog/import/csv/container/type |
433 | 433 | * Nave of the container type to read the data from |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | * @see controller/jobs/catalog/import/csv/container/content |
451 | 451 | * @see controller/jobs/catalog/import/csv/container/options |
452 | 452 | */ |
453 | - $container = $config->get( 'controller/jobs/catalog/import/csv/container/type', 'Directory' ); |
|
453 | + $container = $config->get('controller/jobs/catalog/import/csv/container/type', 'Directory'); |
|
454 | 454 | |
455 | 455 | /** controller/jobs/catalog/import/csv/container/content |
456 | 456 | * Name of the content type inside the container to read the data from |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @see controller/jobs/catalog/import/csv/container/type |
472 | 472 | * @see controller/jobs/catalog/import/csv/container/options |
473 | 473 | */ |
474 | - $content = $config->get( 'controller/jobs/catalog/import/csv/container/content', 'CSV' ); |
|
474 | + $content = $config->get('controller/jobs/catalog/import/csv/container/content', 'CSV'); |
|
475 | 475 | |
476 | 476 | /** controller/jobs/catalog/import/csv/container/options |
477 | 477 | * List of file container options for the catalog import files |
@@ -489,15 +489,15 @@ discard block |
||
489 | 489 | * @see controller/jobs/catalog/import/csv/container/content |
490 | 490 | * @see controller/jobs/catalog/import/csv/container/type |
491 | 491 | */ |
492 | - $options = $config->get( 'controller/jobs/catalog/import/csv/container/options', [] ); |
|
492 | + $options = $config->get('controller/jobs/catalog/import/csv/container/options', []); |
|
493 | 493 | |
494 | - if( $location === null ) |
|
494 | + if ($location === null) |
|
495 | 495 | { |
496 | - $msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/catalog/import/csv/location' ); |
|
497 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
496 | + $msg = sprintf('Required configuration for "%1$s" is missing', 'controller/jobs/catalog/import/csv/location'); |
|
497 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
498 | 498 | } |
499 | 499 | |
500 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
500 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | |
@@ -507,13 +507,13 @@ discard block |
||
507 | 507 | * @param array $domains List of domain names whose items should be fetched too |
508 | 508 | * @return array Associative list of catalog codes as keys and items implementing \Aimeos\MShop\Catalog\Item\Iface as values |
509 | 509 | */ |
510 | - protected function getCatalogMap( array $domains ) |
|
510 | + protected function getCatalogMap(array $domains) |
|
511 | 511 | { |
512 | 512 | $map = []; |
513 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' ); |
|
514 | - $search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
|
513 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog'); |
|
514 | + $search = $manager->createSearch()->setSlice(0, 0x7fffffff); |
|
515 | 515 | |
516 | - foreach( $manager->searchItems( $search, $domains ) as $item ) { |
|
516 | + foreach ($manager->searchItems($search, $domains) as $item) { |
|
517 | 517 | $map[$item->getCode()] = $item; |
518 | 518 | } |
519 | 519 | |
@@ -529,23 +529,23 @@ discard block |
||
529 | 529 | * @param string $code Catalog item code of the parent category |
530 | 530 | * @return string|null ID of the parent category or null for top level nodes |
531 | 531 | */ |
532 | - protected function getParentId( array $catalogMap, array $map, $code ) |
|
532 | + protected function getParentId(array $catalogMap, array $map, $code) |
|
533 | 533 | { |
534 | - if( !isset( $map['catalog.parent'] ) ) |
|
534 | + if (!isset($map['catalog.parent'])) |
|
535 | 535 | { |
536 | - $msg = sprintf( 'Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code ); |
|
537 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
536 | + $msg = sprintf('Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code); |
|
537 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
538 | 538 | } |
539 | 539 | |
540 | - $parent = trim( $map['catalog.parent'] ); |
|
540 | + $parent = trim($map['catalog.parent']); |
|
541 | 541 | |
542 | - if( $parent != '' && !isset( $catalogMap[$parent] ) ) |
|
542 | + if ($parent != '' && !isset($catalogMap[$parent])) |
|
543 | 543 | { |
544 | - $msg = sprintf( 'Parent node for code "%1$s" not found', $parent ); |
|
545 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
544 | + $msg = sprintf('Parent node for code "%1$s" not found', $parent); |
|
545 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
546 | 546 | } |
547 | 547 | |
548 | - return ( $parent != '' ? $catalogMap[$parent]->getId() : null ); |
|
548 | + return ($parent != '' ? $catalogMap[$parent]->getId() : null); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | |
@@ -560,63 +560,63 @@ discard block |
||
560 | 560 | * @return integer Number of catalogs that couldn't be imported |
561 | 561 | * @throws \Aimeos\Controller\Jobs\Exception |
562 | 562 | */ |
563 | - protected function import( array &$catalogMap, array $data, array $mapping, |
|
564 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict ) |
|
563 | + protected function import(array &$catalogMap, array $data, array $mapping, |
|
564 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict) |
|
565 | 565 | { |
566 | 566 | $errors = 0; |
567 | 567 | $context = $this->getContext(); |
568 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
|
568 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
569 | 569 | |
570 | - foreach( $data as $code => $list ) |
|
570 | + foreach ($data as $code => $list) |
|
571 | 571 | { |
572 | 572 | $manager->begin(); |
573 | 573 | |
574 | 574 | try |
575 | 575 | { |
576 | - $code = trim( $code ); |
|
576 | + $code = trim($code); |
|
577 | 577 | |
578 | - if( isset( $catalogMap[$code] ) ) { |
|
578 | + if (isset($catalogMap[$code])) { |
|
579 | 579 | $catalogItem = $catalogMap[$code]; |
580 | 580 | } else { |
581 | 581 | $catalogItem = $manager->createItem(); |
582 | 582 | } |
583 | 583 | |
584 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
584 | + $map = $this->getMappedChunk($list, $mapping); |
|
585 | 585 | |
586 | - if( isset( $map[0] ) ) |
|
586 | + if (isset($map[0])) |
|
587 | 587 | { |
588 | 588 | $map = $map[0]; // there can only be one chunk for the base catalog data |
589 | - $parentid = $this->getParentId( $catalogMap, $map, $code ); |
|
590 | - $catalogItem->fromArray( $this->addItemDefaults( $map ) ); |
|
589 | + $parentid = $this->getParentId($catalogMap, $map, $code); |
|
590 | + $catalogItem->fromArray($this->addItemDefaults($map)); |
|
591 | 591 | |
592 | - if( isset( $catalogMap[$code] ) ) |
|
592 | + if (isset($catalogMap[$code])) |
|
593 | 593 | { |
594 | - $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
|
595 | - $catalogItem = $manager->saveItem( $catalogItem ); |
|
594 | + $manager->moveItem($catalogItem->getId(), $catalogItem->getParentId(), $parentid); |
|
595 | + $catalogItem = $manager->saveItem($catalogItem); |
|
596 | 596 | } |
597 | 597 | else |
598 | 598 | { |
599 | - $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
|
599 | + $catalogItem = $manager->insertItem($catalogItem, $parentid); |
|
600 | 600 | } |
601 | 601 | |
602 | - $list = $processor->process( $catalogItem, $list ); |
|
602 | + $list = $processor->process($catalogItem, $list); |
|
603 | 603 | $catalogMap[$code] = $catalogItem; |
604 | 604 | } |
605 | 605 | |
606 | 606 | $manager->commit(); |
607 | 607 | } |
608 | - catch( \Exception $e ) |
|
608 | + catch (\Exception $e) |
|
609 | 609 | { |
610 | 610 | $manager->rollback(); |
611 | 611 | |
612 | - $msg = sprintf( 'Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
613 | - $context->getLogger()->log( $msg ); |
|
612 | + $msg = sprintf('Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage()); |
|
613 | + $context->getLogger()->log($msg); |
|
614 | 614 | |
615 | 615 | $errors++; |
616 | 616 | } |
617 | 617 | |
618 | - if( $strict && !empty( $list ) ) { |
|
619 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
618 | + if ($strict && !empty($list)) { |
|
619 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
620 | 620 | } |
621 | 621 | } |
622 | 622 | |
@@ -630,9 +630,9 @@ discard block |
||
630 | 630 | * @param array $list Associative list of domain item keys and their values, e.g. "catalog.status" => 1 |
631 | 631 | * @return array Given associative list enriched by default values if they were not already set |
632 | 632 | */ |
633 | - protected function addItemDefaults( array $list ) |
|
633 | + protected function addItemDefaults(array $list) |
|
634 | 634 | { |
635 | - if( !isset( $list['catalog.status'] ) ) { |
|
635 | + if (!isset($list['catalog.status'])) { |
|
636 | 636 | $list['catalog.status'] = 1; |
637 | 637 | } |
638 | 638 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Order export CSV' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Order export CSV'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getDescription() |
41 | 41 | { |
42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Exports orders to CSV file' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Exports orders to CSV file'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @category Developer |
74 | 74 | * @see controller/common/order/export/csv/max-size |
75 | 75 | */ |
76 | - $mappings = $config->get( 'controller/common/order/export/csv/mapping', $mappings ); |
|
76 | + $mappings = $config->get('controller/common/order/export/csv/mapping', $mappings); |
|
77 | 77 | |
78 | 78 | /** controller/jobs/order/export/csv/mapping |
79 | 79 | * List of mappings between the position in the CSV file and item keys |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @category Developer |
89 | 89 | * @see controller/common/order/export/csv/max-size |
90 | 90 | */ |
91 | - $mappings = $config->get( 'controller/jobs/order/export/csv/mapping', $mappings ); |
|
91 | + $mappings = $config->get('controller/jobs/order/export/csv/mapping', $mappings); |
|
92 | 92 | |
93 | 93 | |
94 | 94 | /** controller/common/order/export/csv/max-size |
@@ -106,29 +106,29 @@ discard block |
||
106 | 106 | * @category Developer |
107 | 107 | * @see controller/common/order/export/csv/mapping |
108 | 108 | */ |
109 | - $maxcnt = (int) $config->get( 'controller/common/order/export/csv/max-size', 1000 ); |
|
109 | + $maxcnt = (int) $config->get('controller/common/order/export/csv/max-size', 1000); |
|
110 | 110 | |
111 | 111 | |
112 | - $processors = $this->getProcessors( $mappings ); |
|
113 | - $mq = $context->getMessageQueueManager()->get( 'mq-admin' )->getQueue( 'order-export' ); |
|
112 | + $processors = $this->getProcessors($mappings); |
|
113 | + $mq = $context->getMessageQueueManager()->get('mq-admin')->getQueue('order-export'); |
|
114 | 114 | |
115 | - while( ( $msg = $mq->get() ) !== null ) |
|
115 | + while (($msg = $mq->get()) !== null) |
|
116 | 116 | { |
117 | 117 | try |
118 | 118 | { |
119 | - if( ( $data = json_decode( $msg->getBody(), true ) ) === null ) { |
|
120 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid message: %1$s', $msg->getBody() ) ); |
|
119 | + if (($data = json_decode($msg->getBody(), true)) === null) { |
|
120 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid message: %1$s', $msg->getBody())); |
|
121 | 121 | } |
122 | 122 | |
123 | - $this->export( $processors, $data, $maxcnt ); |
|
123 | + $this->export($processors, $data, $maxcnt); |
|
124 | 124 | } |
125 | - catch( \Exception $e ) |
|
125 | + catch (\Exception $e) |
|
126 | 126 | { |
127 | - $logger->log( 'Order export error: ' . $e->getMessage() ); |
|
128 | - $logger->log( $e->getTraceAsString() ); |
|
127 | + $logger->log('Order export error: ' . $e->getMessage()); |
|
128 | + $logger->log($e->getTraceAsString()); |
|
129 | 129 | } |
130 | 130 | |
131 | - $mq->del( $msg ); |
|
131 | + $mq->del($msg); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | * @param \Aimeos\MShop\Context\Item\Iface $context Context item |
140 | 140 | * @param string $path Absolute path to the exported file |
141 | 141 | */ |
142 | - protected function addJob( $context, $path ) |
|
142 | + protected function addJob($context, $path) |
|
143 | 143 | { |
144 | - $manager = \Aimeos\MAdmin\Factory::createManager( $context, 'job' ); |
|
144 | + $manager = \Aimeos\MAdmin\Factory::createManager($context, 'job'); |
|
145 | 145 | |
146 | 146 | $item = $manager->createItem(); |
147 | - $item->setResult( ['file' => $path] ); |
|
148 | - $item->setLabel( $path ); |
|
147 | + $item->setResult(['file' => $path]); |
|
148 | + $item->setLabel($path); |
|
149 | 149 | |
150 | - $manager->saveItem( $item, false ); |
|
150 | + $manager->saveItem($item, false); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @see controller/jobs/order/export/csv/container/content |
178 | 178 | * @see controller/jobs/order/export/csv/container/options |
179 | 179 | */ |
180 | - $location = $config->get( 'controller/jobs/order/export/csv/location', sys_get_temp_dir() ); |
|
180 | + $location = $config->get('controller/jobs/order/export/csv/location', sys_get_temp_dir()); |
|
181 | 181 | |
182 | 182 | /** controller/jobs/order/export/csv/container/type |
183 | 183 | * Nave of the container type to read the data from |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @see controller/jobs/order/export/csv/container/content |
201 | 201 | * @see controller/jobs/order/export/csv/container/options |
202 | 202 | */ |
203 | - $container = $config->get( 'controller/jobs/order/export/csv/container/type', 'Directory' ); |
|
203 | + $container = $config->get('controller/jobs/order/export/csv/container/type', 'Directory'); |
|
204 | 204 | |
205 | 205 | /** controller/jobs/order/export/csv/container/content |
206 | 206 | * Name of the content type inside the container to read the data from |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @see controller/jobs/order/export/csv/container/type |
222 | 222 | * @see controller/jobs/order/export/csv/container/options |
223 | 223 | */ |
224 | - $content = $config->get( 'controller/jobs/order/export/csv/container/content', 'CSV' ); |
|
224 | + $content = $config->get('controller/jobs/order/export/csv/container/content', 'CSV'); |
|
225 | 225 | |
226 | 226 | /** controller/jobs/order/export/csv/container/options |
227 | 227 | * List of file container options for the order export files |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | * @see controller/jobs/order/export/csv/container/content |
240 | 240 | * @see controller/jobs/order/export/csv/container/type |
241 | 241 | */ |
242 | - $options = $config->get( 'controller/jobs/order/export/csv/container/options', [] ); |
|
242 | + $options = $config->get('controller/jobs/order/export/csv/container/options', []); |
|
243 | 243 | |
244 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
244 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -253,56 +253,56 @@ discard block |
||
253 | 253 | * @param integer $maxcnt Maximum number of retrieved orders at once |
254 | 254 | * @return string Path of the file containing the exported data |
255 | 255 | */ |
256 | - protected function export( array $processors, $msg, $maxcnt ) |
|
256 | + protected function export(array $processors, $msg, $maxcnt) |
|
257 | 257 | { |
258 | - $lcontext = $this->getLocaleContext( $msg ); |
|
258 | + $lcontext = $this->getLocaleContext($msg); |
|
259 | 259 | $baseRef = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
260 | 260 | |
261 | - $manager = \Aimeos\MShop\Factory::createManager( $lcontext, 'order' ); |
|
262 | - $baseManager = \Aimeos\MShop\Factory::createManager( $lcontext, 'order/base' ); |
|
261 | + $manager = \Aimeos\MShop\Factory::createManager($lcontext, 'order'); |
|
262 | + $baseManager = \Aimeos\MShop\Factory::createManager($lcontext, 'order/base'); |
|
263 | 263 | |
264 | 264 | $container = $this->getContainer(); |
265 | - $content = $container->create( 'order-export_' . date( 'Y-m-d_H-i-s' ) ); |
|
266 | - $search = $this->initCriteria( $manager->createSearch()->setSlice( 0, 0x7fffffff ), $msg ); |
|
265 | + $content = $container->create('order-export_' . date('Y-m-d_H-i-s')); |
|
266 | + $search = $this->initCriteria($manager->createSearch()->setSlice(0, 0x7fffffff), $msg); |
|
267 | 267 | $start = 0; |
268 | 268 | |
269 | 269 | do |
270 | 270 | { |
271 | 271 | $baseIds = []; |
272 | - $search->setSlice( $start, $maxcnt ); |
|
273 | - $items = $manager->searchItems( $search ); |
|
272 | + $search->setSlice($start, $maxcnt); |
|
273 | + $items = $manager->searchItems($search); |
|
274 | 274 | |
275 | - foreach( $items as $item ) { |
|
275 | + foreach ($items as $item) { |
|
276 | 276 | $baseIds[] = $item->getBaseId(); |
277 | 277 | } |
278 | 278 | |
279 | 279 | $baseSearch = $baseManager->createSearch(); |
280 | - $baseSearch->setConditions( $baseSearch->compare( '==', 'order.base.id', $baseIds ) ); |
|
281 | - $baseSearch->setSlice( 0, count( $baseIds ) ); |
|
280 | + $baseSearch->setConditions($baseSearch->compare('==', 'order.base.id', $baseIds)); |
|
281 | + $baseSearch->setSlice(0, count($baseIds)); |
|
282 | 282 | |
283 | - $baseItems = $baseManager->searchItems( $baseSearch, $baseRef ); |
|
283 | + $baseItems = $baseManager->searchItems($baseSearch, $baseRef); |
|
284 | 284 | |
285 | - foreach( $items as $id => $item ) |
|
285 | + foreach ($items as $id => $item) |
|
286 | 286 | { |
287 | - foreach( $processors as $type => $processor ) |
|
287 | + foreach ($processors as $type => $processor) |
|
288 | 288 | { |
289 | - foreach( $processor->process( $item, $baseItems[$item->getBaseId()] ) as $line ) { |
|
290 | - $content->add( [0 => $type, 1 => $id] + $line ); |
|
289 | + foreach ($processor->process($item, $baseItems[$item->getBaseId()]) as $line) { |
|
290 | + $content->add([0 => $type, 1 => $id] + $line); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | - $count = count( $items ); |
|
295 | + $count = count($items); |
|
296 | 296 | $start += $count; |
297 | 297 | } |
298 | - while( $count === $search->getSliceSize() ); |
|
298 | + while ($count === $search->getSliceSize()); |
|
299 | 299 | |
300 | 300 | $path = $content->getResource(); |
301 | - $container->add( $content ); |
|
301 | + $container->add($content); |
|
302 | 302 | $container->close(); |
303 | 303 | |
304 | - $path = $this->moveFile( $lcontext, $path ); |
|
305 | - $this->addJob( $lcontext, $path ); |
|
304 | + $path = $this->moveFile($lcontext, $path); |
|
305 | + $this->addJob($lcontext, $path); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | |
@@ -312,15 +312,15 @@ discard block |
||
312 | 312 | * @param array $msg Message data including a "sitecode" value |
313 | 313 | * @return \Aimeos\MShop\Context\Item\Iface New context item with updated locale |
314 | 314 | */ |
315 | - protected function getLocaleContext( array $msg ) |
|
315 | + protected function getLocaleContext(array $msg) |
|
316 | 316 | { |
317 | 317 | $lcontext = clone $this->getContext(); |
318 | - $manager = \Aimeos\MShop\Factory::createManager( $lcontext, 'locale' ); |
|
318 | + $manager = \Aimeos\MShop\Factory::createManager($lcontext, 'locale'); |
|
319 | 319 | |
320 | - $sitecode = ( isset( $msg['sitecode'] ) ? $msg['sitecode'] : 'default' ); |
|
321 | - $localeItem = $manager->bootstrap( $sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE ); |
|
320 | + $sitecode = (isset($msg['sitecode']) ? $msg['sitecode'] : 'default'); |
|
321 | + $localeItem = $manager->bootstrap($sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE); |
|
322 | 322 | |
323 | - return $lcontext->setLocale( $localeItem ); |
|
323 | + return $lcontext->setLocale($localeItem); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | * @param array $msg Message data |
332 | 332 | * @return \Aimeos\MW\Criteria\Iface Initialized criteria object |
333 | 333 | */ |
334 | - protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $msg ) |
|
334 | + protected function initCriteria(\Aimeos\MW\Criteria\Iface $criteria, array $msg) |
|
335 | 335 | { |
336 | - if( isset( $msg['filter'] ) ) { |
|
337 | - $criteria->setConditions( $criteria->toConditions( $msg['filter'] ) ); |
|
336 | + if (isset($msg['filter'])) { |
|
337 | + $criteria->setConditions($criteria->toConditions($msg['filter'])); |
|
338 | 338 | } |
339 | 339 | |
340 | - if( isset( $msg['sort'] ) ) { |
|
341 | - $criteria->setSortations( $criteria->toSortations( $msg['sort'] ) ); |
|
340 | + if (isset($msg['sort'])) { |
|
341 | + $criteria->setSortations($criteria->toSortations($msg['sort'])); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $criteria; |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | * @param string $path Absolute path to the exported file |
353 | 353 | * @return string Relative path of the file in the storage |
354 | 354 | */ |
355 | - protected function moveFile( $context, $path ) |
|
355 | + protected function moveFile($context, $path) |
|
356 | 356 | { |
357 | - $filename = basename( $path ); |
|
358 | - $context->getFileSystemManager()->get( 'fs-admin' )->writef( $filename, $path ); |
|
357 | + $filename = basename($path); |
|
358 | + $context->getFileSystemManager()->get('fs-admin')->writef($filename, $path); |
|
359 | 359 | |
360 | - unlink( $path ); |
|
360 | + unlink($path); |
|
361 | 361 | return $filename; |
362 | 362 | } |
363 | 363 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Subscription export CSV' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Subscription export CSV'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getDescription() |
41 | 41 | { |
42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Exports subscriptions to CSV file' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Exports subscriptions to CSV file'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @category Developer |
74 | 74 | * @see controller/common/subscription/export/csv/max-size |
75 | 75 | */ |
76 | - $mappings = $config->get( 'controller/common/subscription/export/csv/mapping', $mappings ); |
|
76 | + $mappings = $config->get('controller/common/subscription/export/csv/mapping', $mappings); |
|
77 | 77 | |
78 | 78 | /** controller/jobs/subscription/export/csv/mapping |
79 | 79 | * List of mappings between the position in the CSV file and item keys |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @category Developer |
89 | 89 | * @see controller/common/subscription/export/csv/max-size |
90 | 90 | */ |
91 | - $mappings = $config->get( 'controller/jobs/subscription/export/csv/mapping', $mappings ); |
|
91 | + $mappings = $config->get('controller/jobs/subscription/export/csv/mapping', $mappings); |
|
92 | 92 | |
93 | 93 | |
94 | 94 | /** controller/common/subscription/export/csv/max-size |
@@ -106,29 +106,29 @@ discard block |
||
106 | 106 | * @category Developer |
107 | 107 | * @see controller/common/subscription/export/csv/mapping |
108 | 108 | */ |
109 | - $maxcnt = (int) $config->get( 'controller/common/subscription/export/csv/max-size', 1000 ); |
|
109 | + $maxcnt = (int) $config->get('controller/common/subscription/export/csv/max-size', 1000); |
|
110 | 110 | |
111 | 111 | |
112 | - $processors = $this->getProcessors( $mappings ); |
|
113 | - $mq = $context->getMessageQueueManager()->get( 'mq-admin' )->getQueue( 'subscription-export' ); |
|
112 | + $processors = $this->getProcessors($mappings); |
|
113 | + $mq = $context->getMessageQueueManager()->get('mq-admin')->getQueue('subscription-export'); |
|
114 | 114 | |
115 | - while( ( $msg = $mq->get() ) !== null ) |
|
115 | + while (($msg = $mq->get()) !== null) |
|
116 | 116 | { |
117 | 117 | try |
118 | 118 | { |
119 | - if( ( $data = json_decode( $msg->getBody(), true ) ) === null ) { |
|
120 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid message: %1$s', $msg->getBody() ) ); |
|
119 | + if (($data = json_decode($msg->getBody(), true)) === null) { |
|
120 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid message: %1$s', $msg->getBody())); |
|
121 | 121 | } |
122 | 122 | |
123 | - $this->export( $processors, $data, $maxcnt ); |
|
123 | + $this->export($processors, $data, $maxcnt); |
|
124 | 124 | } |
125 | - catch( \Exception $e ) |
|
125 | + catch (\Exception $e) |
|
126 | 126 | { |
127 | - $logger->log( 'Subscription export error: ' . $e->getMessage() ); |
|
128 | - $logger->log( $e->getTraceAsString() ); |
|
127 | + $logger->log('Subscription export error: ' . $e->getMessage()); |
|
128 | + $logger->log($e->getTraceAsString()); |
|
129 | 129 | } |
130 | 130 | |
131 | - $mq->del( $msg ); |
|
131 | + $mq->del($msg); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | * @param \Aimeos\MShop\Context\Item\Iface $context Context item |
140 | 140 | * @param string $path Absolute path to the exported file |
141 | 141 | */ |
142 | - protected function addJob( $context, $path ) |
|
142 | + protected function addJob($context, $path) |
|
143 | 143 | { |
144 | - $manager = \Aimeos\MAdmin\Factory::createManager( $context, 'job' ); |
|
144 | + $manager = \Aimeos\MAdmin\Factory::createManager($context, 'job'); |
|
145 | 145 | |
146 | 146 | $item = $manager->createItem(); |
147 | - $item->setResult( ['file' => $path] ); |
|
148 | - $item->setLabel( $path ); |
|
147 | + $item->setResult(['file' => $path]); |
|
148 | + $item->setLabel($path); |
|
149 | 149 | |
150 | - $manager->saveItem( $item, false ); |
|
150 | + $manager->saveItem($item, false); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @see controller/jobs/subscription/export/csv/container/content |
178 | 178 | * @see controller/jobs/subscription/export/csv/container/options |
179 | 179 | */ |
180 | - $location = $config->get( 'controller/jobs/subscription/export/csv/location', sys_get_temp_dir() ); |
|
180 | + $location = $config->get('controller/jobs/subscription/export/csv/location', sys_get_temp_dir()); |
|
181 | 181 | |
182 | 182 | /** controller/jobs/subscription/export/csv/container/type |
183 | 183 | * Nave of the container type to read the data from |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @see controller/jobs/subscription/export/csv/container/content |
201 | 201 | * @see controller/jobs/subscription/export/csv/container/options |
202 | 202 | */ |
203 | - $container = $config->get( 'controller/jobs/subscription/export/csv/container/type', 'Directory' ); |
|
203 | + $container = $config->get('controller/jobs/subscription/export/csv/container/type', 'Directory'); |
|
204 | 204 | |
205 | 205 | /** controller/jobs/subscription/export/csv/container/content |
206 | 206 | * Name of the content type inside the container to read the data from |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @see controller/jobs/subscription/export/csv/container/type |
222 | 222 | * @see controller/jobs/subscription/export/csv/container/options |
223 | 223 | */ |
224 | - $content = $config->get( 'controller/jobs/subscription/export/csv/container/content', 'CSV' ); |
|
224 | + $content = $config->get('controller/jobs/subscription/export/csv/container/content', 'CSV'); |
|
225 | 225 | |
226 | 226 | /** controller/jobs/subscription/export/csv/container/options |
227 | 227 | * List of file container options for the subscription export files |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | * @see controller/jobs/subscription/export/csv/container/content |
240 | 240 | * @see controller/jobs/subscription/export/csv/container/type |
241 | 241 | */ |
242 | - $options = $config->get( 'controller/jobs/subscription/export/csv/container/options', [] ); |
|
242 | + $options = $config->get('controller/jobs/subscription/export/csv/container/options', []); |
|
243 | 243 | |
244 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
244 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -253,56 +253,56 @@ discard block |
||
253 | 253 | * @param integer $maxcnt Maximum number of retrieved subscriptions at once |
254 | 254 | * @return string Path of the file containing the exported data |
255 | 255 | */ |
256 | - protected function export( array $processors, $msg, $maxcnt ) |
|
256 | + protected function export(array $processors, $msg, $maxcnt) |
|
257 | 257 | { |
258 | - $lcontext = $this->getLocaleContext( $msg ); |
|
258 | + $lcontext = $this->getLocaleContext($msg); |
|
259 | 259 | $baseRef = ['order/base/address', 'order/base/product']; |
260 | 260 | |
261 | - $manager = \Aimeos\MShop\Factory::createManager( $lcontext, 'subscription' ); |
|
262 | - $baseManager = \Aimeos\MShop\Factory::createManager( $lcontext, 'order/base' ); |
|
261 | + $manager = \Aimeos\MShop\Factory::createManager($lcontext, 'subscription'); |
|
262 | + $baseManager = \Aimeos\MShop\Factory::createManager($lcontext, 'order/base'); |
|
263 | 263 | |
264 | 264 | $container = $this->getContainer(); |
265 | - $content = $container->create( 'subscription-export_' . date( 'Y-m-d_H-i-s' ) ); |
|
266 | - $search = $this->initCriteria( $manager->createSearch()->setSlice( 0, 0x7fffffff ), $msg ); |
|
265 | + $content = $container->create('subscription-export_' . date('Y-m-d_H-i-s')); |
|
266 | + $search = $this->initCriteria($manager->createSearch()->setSlice(0, 0x7fffffff), $msg); |
|
267 | 267 | $start = 0; |
268 | 268 | |
269 | 269 | do |
270 | 270 | { |
271 | 271 | $baseIds = []; |
272 | - $search->setSlice( $start, $maxcnt ); |
|
273 | - $items = $manager->searchItems( $search ); |
|
272 | + $search->setSlice($start, $maxcnt); |
|
273 | + $items = $manager->searchItems($search); |
|
274 | 274 | |
275 | - foreach( $items as $item ) { |
|
275 | + foreach ($items as $item) { |
|
276 | 276 | $baseIds[] = $item->getOrderBaseId(); |
277 | 277 | } |
278 | 278 | |
279 | 279 | $baseSearch = $baseManager->createSearch(); |
280 | - $baseSearch->setConditions( $baseSearch->compare( '==', 'order.base.id', $baseIds ) ); |
|
281 | - $baseSearch->setSlice( 0, count( $baseIds ) ); |
|
280 | + $baseSearch->setConditions($baseSearch->compare('==', 'order.base.id', $baseIds)); |
|
281 | + $baseSearch->setSlice(0, count($baseIds)); |
|
282 | 282 | |
283 | - $baseItems = $baseManager->searchItems( $baseSearch, $baseRef ); |
|
283 | + $baseItems = $baseManager->searchItems($baseSearch, $baseRef); |
|
284 | 284 | |
285 | - foreach( $items as $id => $item ) |
|
285 | + foreach ($items as $id => $item) |
|
286 | 286 | { |
287 | - foreach( $processors as $type => $processor ) |
|
287 | + foreach ($processors as $type => $processor) |
|
288 | 288 | { |
289 | - foreach( $processor->process( $item, $baseItems[$item->getOrderBaseId()] ) as $line ) { |
|
290 | - $content->add( [0 => $type, 1 => $id] + $line ); |
|
289 | + foreach ($processor->process($item, $baseItems[$item->getOrderBaseId()]) as $line) { |
|
290 | + $content->add([0 => $type, 1 => $id] + $line); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | - $count = count( $items ); |
|
295 | + $count = count($items); |
|
296 | 296 | $start += $count; |
297 | 297 | } |
298 | - while( $count === $search->getSliceSize() ); |
|
298 | + while ($count === $search->getSliceSize()); |
|
299 | 299 | |
300 | 300 | $path = $content->getResource(); |
301 | - $container->add( $content ); |
|
301 | + $container->add($content); |
|
302 | 302 | $container->close(); |
303 | 303 | |
304 | - $path = $this->moveFile( $lcontext, $path ); |
|
305 | - $this->addJob( $lcontext, $path ); |
|
304 | + $path = $this->moveFile($lcontext, $path); |
|
305 | + $this->addJob($lcontext, $path); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | |
@@ -312,15 +312,15 @@ discard block |
||
312 | 312 | * @param array $msg Message data including a "sitecode" value |
313 | 313 | * @return \Aimeos\MShop\Context\Item\Iface New context item with updated locale |
314 | 314 | */ |
315 | - protected function getLocaleContext( array $msg ) |
|
315 | + protected function getLocaleContext(array $msg) |
|
316 | 316 | { |
317 | 317 | $lcontext = clone $this->getContext(); |
318 | - $manager = \Aimeos\MShop\Factory::createManager( $lcontext, 'locale' ); |
|
318 | + $manager = \Aimeos\MShop\Factory::createManager($lcontext, 'locale'); |
|
319 | 319 | |
320 | - $sitecode = ( isset( $msg['sitecode'] ) ? $msg['sitecode'] : 'default' ); |
|
321 | - $localeItem = $manager->bootstrap( $sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE ); |
|
320 | + $sitecode = (isset($msg['sitecode']) ? $msg['sitecode'] : 'default'); |
|
321 | + $localeItem = $manager->bootstrap($sitecode, '', '', false, \Aimeos\MShop\Locale\Manager\Base::SITE_ONE); |
|
322 | 322 | |
323 | - return $lcontext->setLocale( $localeItem ); |
|
323 | + return $lcontext->setLocale($localeItem); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | * @param array $msg Message data |
332 | 332 | * @return \Aimeos\MW\Criteria\Iface Initialized criteria object |
333 | 333 | */ |
334 | - protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $msg ) |
|
334 | + protected function initCriteria(\Aimeos\MW\Criteria\Iface $criteria, array $msg) |
|
335 | 335 | { |
336 | - if( isset( $msg['filter'] ) ) { |
|
337 | - $criteria->setConditions( $criteria->toConditions( $msg['filter'] ) ); |
|
336 | + if (isset($msg['filter'])) { |
|
337 | + $criteria->setConditions($criteria->toConditions($msg['filter'])); |
|
338 | 338 | } |
339 | 339 | |
340 | - if( isset( $msg['sort'] ) ) { |
|
341 | - $criteria->setSortations( $criteria->toSortations( $msg['sort'] ) ); |
|
340 | + if (isset($msg['sort'])) { |
|
341 | + $criteria->setSortations($criteria->toSortations($msg['sort'])); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $criteria; |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | * @param string $path Absolute path to the exported file |
353 | 353 | * @return string Relative path of the file in the storage |
354 | 354 | */ |
355 | - protected function moveFile( $context, $path ) |
|
355 | + protected function moveFile($context, $path) |
|
356 | 356 | { |
357 | - $filename = basename( $path ); |
|
358 | - $context->getFileSystemManager()->get( 'fs-admin' )->writef( $filename, $path ); |
|
357 | + $filename = basename($path); |
|
358 | + $context->getFileSystemManager()->get('fs-admin')->writef($filename, $path); |
|
359 | 359 | |
360 | - unlink( $path ); |
|
360 | + unlink($path); |
|
361 | 361 | return $filename; |
362 | 362 | } |
363 | 363 | } |
@@ -15,14 +15,14 @@ discard block |
||
15 | 15 | public static function bootstrap() |
16 | 16 | { |
17 | 17 | self::getAimeos(); |
18 | - \Aimeos\MShop\Factory::setCache( false ); |
|
18 | + \Aimeos\MShop\Factory::setCache(false); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | |
22 | - public static function getContext( $site = 'unittest' ) |
|
22 | + public static function getContext($site = 'unittest') |
|
23 | 23 | { |
24 | - if( !isset( self::$context[$site] ) ) { |
|
25 | - self::$context[$site] = self::createContext( $site ); |
|
24 | + if (!isset(self::$context[$site])) { |
|
25 | + self::$context[$site] = self::createContext($site); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | return clone self::$context[$site]; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | |
32 | 32 | public static function getAimeos() |
33 | 33 | { |
34 | - if( !isset( self::$aimeos ) ) |
|
34 | + if (!isset(self::$aimeos)) |
|
35 | 35 | { |
36 | 36 | require_once 'Bootstrap.php'; |
37 | - spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
|
37 | + spl_autoload_register('Aimeos\\Bootstrap::autoload'); |
|
38 | 38 | |
39 | - $extdir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ); |
|
40 | - self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), true ); |
|
39 | + $extdir = dirname(dirname(dirname(dirname(dirname(__FILE__))))); |
|
40 | + self::$aimeos = new \Aimeos\Bootstrap(array($extdir), true); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return self::$aimeos; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @param string $site |
49 | 49 | */ |
50 | - private static function createContext( $site ) |
|
50 | + private static function createContext($site) |
|
51 | 51 | { |
52 | 52 | $ctx = new \Aimeos\MShop\Context\Item\Standard(); |
53 | 53 | $aimeos = self::getAimeos(); |
@@ -57,30 +57,30 @@ discard block |
||
57 | 57 | $paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
58 | 58 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
59 | 59 | |
60 | - $conf = new \Aimeos\MW\Config\PHPArray( [], $paths ); |
|
61 | - $conf = new \Aimeos\MW\Config\Decorator\Memory( $conf ); |
|
62 | - $conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file ); |
|
63 | - $ctx->setConfig( $conf ); |
|
60 | + $conf = new \Aimeos\MW\Config\PHPArray([], $paths); |
|
61 | + $conf = new \Aimeos\MW\Config\Decorator\Memory($conf); |
|
62 | + $conf = new \Aimeos\MW\Config\Decorator\Documentor($conf, $file); |
|
63 | + $ctx->setConfig($conf); |
|
64 | 64 | |
65 | 65 | |
66 | - $dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
|
67 | - $ctx->setDatabaseManager( $dbm ); |
|
66 | + $dbm = new \Aimeos\MW\DB\Manager\PDO($conf); |
|
67 | + $ctx->setDatabaseManager($dbm); |
|
68 | 68 | |
69 | 69 | |
70 | - $logger = new \Aimeos\MW\Logger\File( 'unittest.log', \Aimeos\MW\Logger\Base::DEBUG ); |
|
71 | - $ctx->setLogger( $logger ); |
|
70 | + $logger = new \Aimeos\MW\Logger\File('unittest.log', \Aimeos\MW\Logger\Base::DEBUG); |
|
71 | + $ctx->setLogger($logger); |
|
72 | 72 | |
73 | 73 | |
74 | 74 | $session = new \Aimeos\MW\Session\None(); |
75 | - $ctx->setSession( $session ); |
|
75 | + $ctx->setSession($session); |
|
76 | 76 | |
77 | 77 | |
78 | - $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx ); |
|
79 | - $locale = $localeManager->bootstrap( $site, '', '', false ); |
|
80 | - $ctx->setLocale( $locale ); |
|
78 | + $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($ctx); |
|
79 | + $locale = $localeManager->bootstrap($site, '', '', false); |
|
80 | + $ctx->setLocale($locale); |
|
81 | 81 | |
82 | 82 | |
83 | - $ctx->setEditor( 'core:controller/common' ); |
|
83 | + $ctx->setEditor('core:controller/common'); |
|
84 | 84 | |
85 | 85 | return $ctx; |
86 | 86 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
43 | 43 | * @param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object Decorated processor |
44 | 44 | */ |
45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null ) |
|
45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $object = null) |
|
47 | 47 | { |
48 | - parent::__construct( $context, $mapping, $object ); |
|
48 | + parent::__construct($context, $mapping, $object); |
|
49 | 49 | |
50 | 50 | /** controller/common/catalog/import/csv/processor/text/listtypes |
51 | 51 | * Names of the catalog list types for texts that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @see controller/common/catalog/import/csv/processor/price/listtypes |
67 | 67 | * @see controller/common/catalog/import/csv/processor/catalog/listtypes |
68 | 68 | */ |
69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/catalog/import/csv/processor/text/listtypes' ); |
|
69 | + $this->listTypes = $context->getConfig()->get('controller/common/catalog/import/csv/processor/text/listtypes'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -77,40 +77,40 @@ discard block |
||
77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
78 | 78 | * @return array List of data which hasn't been imported |
79 | 79 | */ |
80 | - public function process( \Aimeos\MShop\Catalog\Item\Iface $catalog, array $data ) |
|
80 | + public function process(\Aimeos\MShop\Catalog\Item\Iface $catalog, array $data) |
|
81 | 81 | { |
82 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
|
83 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'text' ); |
|
82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists'); |
|
83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'text'); |
|
84 | 84 | $manager->begin(); |
85 | 85 | |
86 | 86 | try |
87 | 87 | { |
88 | 88 | $delete = $listMap = []; |
89 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
90 | - $listItems = $catalog->getListItems( 'text', $this->listTypes ); |
|
89 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
90 | + $listItems = $catalog->getListItems('text', $this->listTypes); |
|
91 | 91 | |
92 | - foreach( $listItems as $listItem ) |
|
92 | + foreach ($listItems as $listItem) |
|
93 | 93 | { |
94 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
95 | - $listMap[ $refItem->getContent() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
94 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
95 | + $listMap[$refItem->getContent()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - foreach( $map as $pos => $list ) |
|
99 | + foreach ($map as $pos => $list) |
|
100 | 100 | { |
101 | - if( $this->checkEntry( $list ) === false ) { |
|
101 | + if ($this->checkEntry($list) === false) { |
|
102 | 102 | continue; |
103 | 103 | } |
104 | 104 | |
105 | - $content = trim( $list['text.content'] ); |
|
106 | - $type = trim( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
|
107 | - $typecode = trim( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
|
105 | + $content = trim($list['text.content']); |
|
106 | + $type = trim(isset($list['text.type']) ? $list['text.type'] : 'name'); |
|
107 | + $typecode = trim(isset($list['catalog.lists.type']) ? $list['catalog.lists.type'] : 'default'); |
|
108 | 108 | |
109 | - if( isset( $listMap[$content][$type][$typecode] ) ) |
|
109 | + if (isset($listMap[$content][$type][$typecode])) |
|
110 | 110 | { |
111 | 111 | $listItem = $listMap[$content][$type][$typecode]; |
112 | 112 | $refItem = $listItem->getRefItem(); |
113 | - unset( $listItems[ $listItem->getId() ] ); |
|
113 | + unset($listItems[$listItem->getId()]); |
|
114 | 114 | } |
115 | 115 | else |
116 | 116 | { |
@@ -118,33 +118,33 @@ discard block |
||
118 | 118 | $refItem = $manager->createItem(); |
119 | 119 | } |
120 | 120 | |
121 | - $list['text.typeid'] = $this->getTypeId( 'text/type', 'catalog', $type ); |
|
121 | + $list['text.typeid'] = $this->getTypeId('text/type', 'catalog', $type); |
|
122 | 122 | $list['text.domain'] = 'catalog'; |
123 | 123 | |
124 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
125 | - $refItem = $manager->saveItem( $refItem ); |
|
124 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
125 | + $refItem = $manager->saveItem($refItem); |
|
126 | 126 | |
127 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'text', $typecode ); |
|
127 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'text', $typecode); |
|
128 | 128 | $list['catalog.lists.parentid'] = $catalog->getId(); |
129 | 129 | $list['catalog.lists.refid'] = $refItem->getId(); |
130 | 130 | $list['catalog.lists.domain'] = 'text'; |
131 | 131 | |
132 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
133 | - $listManager->saveItem( $listItem, false ); |
|
132 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
133 | + $listManager->saveItem($listItem, false); |
|
134 | 134 | } |
135 | 135 | |
136 | - foreach( $listItems as $listItem ) { |
|
136 | + foreach ($listItems as $listItem) { |
|
137 | 137 | $delete[] = $listItem->getRefId(); |
138 | 138 | } |
139 | 139 | |
140 | - $manager->deleteItems( $delete ); |
|
141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
140 | + $manager->deleteItems($delete); |
|
141 | + $listManager->deleteItems(array_keys($listItems)); |
|
142 | 142 | |
143 | - $data = $this->getObject()->process( $catalog, $data ); |
|
143 | + $data = $this->getObject()->process($catalog, $data); |
|
144 | 144 | |
145 | 145 | $manager->commit(); |
146 | 146 | } |
147 | - catch( \Exception $e ) |
|
147 | + catch (\Exception $e) |
|
148 | 148 | { |
149 | 149 | $manager->rollback(); |
150 | 150 | throw $e; |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | * @param array $list Associative list of domain item keys and their values, e.g. "text.status" => 1 |
161 | 161 | * @return array Given associative list enriched by default values if they were not already set |
162 | 162 | */ |
163 | - protected function addItemDefaults( array $list ) |
|
163 | + protected function addItemDefaults(array $list) |
|
164 | 164 | { |
165 | - if( !isset( $list['text.label'] ) ) { |
|
166 | - $list['text.label'] = mb_strcut( trim( $list['text.content'] ), 0, 255 ); |
|
165 | + if (!isset($list['text.label'])) { |
|
166 | + $list['text.label'] = mb_strcut(trim($list['text.content']), 0, 255); |
|
167 | 167 | } |
168 | 168 | |
169 | - if( !isset( $list['text.status'] ) ) { |
|
169 | + if (!isset($list['text.status'])) { |
|
170 | 170 | $list['text.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['text.content'] ) || trim( $list['text.content'] ) === '' || isset( $list['catalog.lists.type'] ) |
|
186 | - && $this->listTypes !== null && !in_array( trim( $list['catalog.lists.type'] ), (array) $this->listTypes ) |
|
185 | + if (!isset($list['text.content']) || trim($list['text.content']) === '' || isset($list['catalog.lists.type']) |
|
186 | + && $this->listTypes !== null && !in_array(trim($list['catalog.lists.type']), (array) $this->listTypes) |
|
187 | 187 | ) { |
188 | 188 | return false; |
189 | 189 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
44 | 44 | */ |
45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
47 | 47 | { |
48 | - parent::__construct( $context, $mapping, $object ); |
|
48 | + parent::__construct($context, $mapping, $object); |
|
49 | 49 | |
50 | 50 | /** controller/common/product/import/csv/processor/text/listtypes |
51 | 51 | * Names of the product list types for texts that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @see controller/common/product/import/csv/processor/price/listtypes |
67 | 67 | * @see controller/common/product/import/csv/processor/product/listtypes |
68 | 68 | */ |
69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/text/listtypes' ); |
|
69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/text/listtypes'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -77,40 +77,40 @@ discard block |
||
77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
78 | 78 | * @return array List of data which hasn't been imported |
79 | 79 | */ |
80 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
80 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
81 | 81 | { |
82 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
83 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'text' ); |
|
82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'text'); |
|
84 | 84 | $manager->begin(); |
85 | 85 | |
86 | 86 | try |
87 | 87 | { |
88 | 88 | $delete = $listMap = []; |
89 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
90 | - $listItems = $product->getListItems( 'text', $this->listTypes ); |
|
89 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
90 | + $listItems = $product->getListItems('text', $this->listTypes); |
|
91 | 91 | |
92 | - foreach( $listItems as $listItem ) |
|
92 | + foreach ($listItems as $listItem) |
|
93 | 93 | { |
94 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
95 | - $listMap[ $refItem->getContent() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
94 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
95 | + $listMap[$refItem->getContent()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - foreach( $map as $pos => $list ) |
|
99 | + foreach ($map as $pos => $list) |
|
100 | 100 | { |
101 | - if( $this->checkEntry( $list ) === false ) { |
|
101 | + if ($this->checkEntry($list) === false) { |
|
102 | 102 | continue; |
103 | 103 | } |
104 | 104 | |
105 | - $content = trim( $list['text.content'] ); |
|
106 | - $type = trim( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
|
107 | - $typecode = trim( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
105 | + $content = trim($list['text.content']); |
|
106 | + $type = trim(isset($list['text.type']) ? $list['text.type'] : 'name'); |
|
107 | + $typecode = trim(isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
108 | 108 | |
109 | - if( isset( $listMap[$content][$type][$typecode] ) ) |
|
109 | + if (isset($listMap[$content][$type][$typecode])) |
|
110 | 110 | { |
111 | 111 | $listItem = $listMap[$content][$type][$typecode]; |
112 | 112 | $refItem = $listItem->getRefItem(); |
113 | - unset( $listItems[ $listItem->getId() ] ); |
|
113 | + unset($listItems[$listItem->getId()]); |
|
114 | 114 | } |
115 | 115 | else |
116 | 116 | { |
@@ -118,33 +118,33 @@ discard block |
||
118 | 118 | $refItem = $manager->createItem(); |
119 | 119 | } |
120 | 120 | |
121 | - $list['text.typeid'] = $this->getTypeId( 'text/type', 'product', $type ); |
|
121 | + $list['text.typeid'] = $this->getTypeId('text/type', 'product', $type); |
|
122 | 122 | $list['text.domain'] = 'product'; |
123 | 123 | |
124 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
125 | - $refItem = $manager->saveItem( $refItem ); |
|
124 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
125 | + $refItem = $manager->saveItem($refItem); |
|
126 | 126 | |
127 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'text', $typecode ); |
|
127 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'text', $typecode); |
|
128 | 128 | $list['product.lists.parentid'] = $product->getId(); |
129 | 129 | $list['product.lists.refid'] = $refItem->getId(); |
130 | 130 | $list['product.lists.domain'] = 'text'; |
131 | 131 | |
132 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
133 | - $listManager->saveItem( $listItem, false ); |
|
132 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
133 | + $listManager->saveItem($listItem, false); |
|
134 | 134 | } |
135 | 135 | |
136 | - foreach( $listItems as $listItem ) { |
|
136 | + foreach ($listItems as $listItem) { |
|
137 | 137 | $delete[] = $listItem->getRefId(); |
138 | 138 | } |
139 | 139 | |
140 | - $manager->deleteItems( $delete ); |
|
141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
140 | + $manager->deleteItems($delete); |
|
141 | + $listManager->deleteItems(array_keys($listItems)); |
|
142 | 142 | |
143 | - $data = $this->getObject()->process( $product, $data ); |
|
143 | + $data = $this->getObject()->process($product, $data); |
|
144 | 144 | |
145 | 145 | $manager->commit(); |
146 | 146 | } |
147 | - catch( \Exception $e ) |
|
147 | + catch (\Exception $e) |
|
148 | 148 | { |
149 | 149 | $manager->rollback(); |
150 | 150 | throw $e; |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | * @param array $list Associative list of domain item keys and their values, e.g. "text.status" => 1 |
161 | 161 | * @return array Given associative list enriched by default values if they were not already set |
162 | 162 | */ |
163 | - protected function addItemDefaults( array $list ) |
|
163 | + protected function addItemDefaults(array $list) |
|
164 | 164 | { |
165 | - if( !isset( $list['text.label'] ) ) { |
|
166 | - $list['text.label'] = mb_strcut( trim( $list['text.content'] ), 0, 255 ); |
|
165 | + if (!isset($list['text.label'])) { |
|
166 | + $list['text.label'] = mb_strcut(trim($list['text.content']), 0, 255); |
|
167 | 167 | } |
168 | 168 | |
169 | - if( !isset( $list['text.status'] ) ) { |
|
169 | + if (!isset($list['text.status'])) { |
|
170 | 170 | $list['text.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['text.content'] ) || trim( $list['text.content'] ) === '' || isset( $list['product.lists.type'] ) |
|
186 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
185 | + if (!isset($list['text.content']) || trim($list['text.content']) === '' || 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 | } |