@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 28 | 28 | * @param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor Decorated processor |
| 29 | 29 | */ |
| 30 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 31 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor = null ) |
|
| 30 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 31 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor = null) |
|
| 32 | 32 | { |
| 33 | 33 | } |
| 34 | 34 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param array $data List of CSV fields with position as key and data as value |
| 41 | 41 | * @return array List of data which hasn't been imported |
| 42 | 42 | */ |
| 43 | - public function process( \Aimeos\MShop\Catalog\Item\Iface $catalog, array $data ) |
|
| 43 | + public function process(\Aimeos\MShop\Catalog\Item\Iface $catalog, array $data) |
|
| 44 | 44 | { |
| 45 | 45 | return $data; |
| 46 | 46 | } |
@@ -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,39 +77,39 @@ 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 | - $type = ( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
|
| 106 | - $typecode = ( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
|
| 105 | + $type = (isset($list['text.type']) ? $list['text.type'] : 'name'); |
|
| 106 | + $typecode = (isset($list['catalog.lists.type']) ? $list['catalog.lists.type'] : 'default'); |
|
| 107 | 107 | |
| 108 | - if( isset( $listMap[ $list['text.content'] ][$type][$typecode] ) ) |
|
| 108 | + if (isset($listMap[$list['text.content']][$type][$typecode])) |
|
| 109 | 109 | { |
| 110 | - $listItem = $listMap[ $list['text.content'] ][$type][$typecode]; |
|
| 110 | + $listItem = $listMap[$list['text.content']][$type][$typecode]; |
|
| 111 | 111 | $refItem = $listItem->getRefItem(); |
| 112 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 112 | + unset($listItems[$listItem->getId()]); |
|
| 113 | 113 | } |
| 114 | 114 | else |
| 115 | 115 | { |
@@ -117,33 +117,33 @@ discard block |
||
| 117 | 117 | $refItem = $manager->createItem(); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $list['text.typeid'] = $this->getTypeId( 'text/type', 'catalog', $type ); |
|
| 120 | + $list['text.typeid'] = $this->getTypeId('text/type', 'catalog', $type); |
|
| 121 | 121 | $list['text.domain'] = 'catalog'; |
| 122 | 122 | |
| 123 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 124 | - $refItem = $manager->saveItem( $refItem ); |
|
| 123 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 124 | + $refItem = $manager->saveItem($refItem); |
|
| 125 | 125 | |
| 126 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'text', $typecode ); |
|
| 126 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'text', $typecode); |
|
| 127 | 127 | $list['catalog.lists.parentid'] = $catalog->getId(); |
| 128 | 128 | $list['catalog.lists.refid'] = $refItem->getId(); |
| 129 | 129 | $list['catalog.lists.domain'] = 'text'; |
| 130 | 130 | |
| 131 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 132 | - $listManager->saveItem( $listItem, false ); |
|
| 131 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 132 | + $listManager->saveItem($listItem, false); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - foreach( $listItems as $listItem ) { |
|
| 135 | + foreach ($listItems as $listItem) { |
|
| 136 | 136 | $delete[] = $listItem->getRefId(); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $manager->deleteItems( $delete ); |
|
| 140 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 139 | + $manager->deleteItems($delete); |
|
| 140 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 141 | 141 | |
| 142 | - $data = $this->getObject()->process( $catalog, $data ); |
|
| 142 | + $data = $this->getObject()->process($catalog, $data); |
|
| 143 | 143 | |
| 144 | 144 | $manager->commit(); |
| 145 | 145 | } |
| 146 | - catch( \Exception $e ) |
|
| 146 | + catch (\Exception $e) |
|
| 147 | 147 | { |
| 148 | 148 | $manager->rollback(); |
| 149 | 149 | throw $e; |
@@ -159,17 +159,17 @@ discard block |
||
| 159 | 159 | * @param array $list Associative list of domain item keys and their values, e.g. "text.status" => 1 |
| 160 | 160 | * @return array Given associative list enriched by default values if they were not already set |
| 161 | 161 | */ |
| 162 | - protected function addItemDefaults( array $list ) |
|
| 162 | + protected function addItemDefaults(array $list) |
|
| 163 | 163 | { |
| 164 | - if( !isset( $list['text.label'] ) ) { |
|
| 165 | - $list['text.label'] = mb_strcut( $list['text.content'], 0, 255 ); |
|
| 164 | + if (!isset($list['text.label'])) { |
|
| 165 | + $list['text.label'] = mb_strcut($list['text.content'], 0, 255); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if( !isset( $list['text.languageid'] ) ) { |
|
| 168 | + if (!isset($list['text.languageid'])) { |
|
| 169 | 169 | $list['text.languageid'] = $this->getContext()->getLocale()->getLanguageId(); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if( !isset( $list['text.status'] ) ) { |
|
| 172 | + if (!isset($list['text.status'])) { |
|
| 173 | 173 | $list['text.status'] = 1; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -183,10 +183,10 @@ discard block |
||
| 183 | 183 | * @param array $list Associative list of key/value pairs from the mapping |
| 184 | 184 | * @return boolean True if valid, false if not |
| 185 | 185 | */ |
| 186 | - protected function checkEntry( array $list ) |
|
| 186 | + protected function checkEntry(array $list) |
|
| 187 | 187 | { |
| 188 | - if( !isset( $list['text.content'] ) || $list['text.content'] === '' || isset( $list['catalog.lists.type'] ) |
|
| 189 | - && $this->listTypes !== null && !in_array( $list['catalog.lists.type'], (array) $this->listTypes ) |
|
| 188 | + if (!isset($list['text.content']) || $list['text.content'] === '' || isset($list['catalog.lists.type']) |
|
| 189 | + && $this->listTypes !== null && !in_array($list['catalog.lists.type'], (array) $this->listTypes) |
|
| 190 | 190 | ) { |
| 191 | 191 | return false; |
| 192 | 192 | } |
@@ -110,8 +110,7 @@ discard block |
||
| 110 | 110 | $listItem = $listMap[ $list['text.content'] ][$type][$typecode]; |
| 111 | 111 | $refItem = $listItem->getRefItem(); |
| 112 | 112 | unset( $listItems[ $listItem->getId() ] ); |
| 113 | - } |
|
| 114 | - else |
|
| 113 | + } else |
|
| 115 | 114 | { |
| 116 | 115 | $listItem = $listManager->createItem(); |
| 117 | 116 | $refItem = $manager->createItem(); |
@@ -142,8 +141,7 @@ discard block |
||
| 142 | 141 | $data = $this->getObject()->process( $catalog, $data ); |
| 143 | 142 | |
| 144 | 143 | $manager->commit(); |
| 145 | - } |
|
| 146 | - catch( \Exception $e ) |
|
| 144 | + } catch( \Exception $e ) |
|
| 147 | 145 | { |
| 148 | 146 | $manager->rollback(); |
| 149 | 147 | throw $e; |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 27 | 27 | * @param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor Decorated processor |
| 28 | 28 | */ |
| 29 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 30 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor = null ); |
|
| 29 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 30 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor = null); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -37,5 +37,5 @@ discard block |
||
| 37 | 37 | * @param array $data List of CSV fields with position as key and data as value |
| 38 | 38 | * @return array List of data which hasn't been imported |
| 39 | 39 | */ |
| 40 | - public function process( \Aimeos\MShop\Catalog\Item\Iface $catalog, array $data ); |
|
| 40 | + public function process(\Aimeos\MShop\Catalog\Item\Iface $catalog, array $data); |
|
| 41 | 41 | } |
| 42 | 42 | \ No newline at end of file |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
| 26 | 26 | */ |
| 27 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context ); |
|
| 27 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Returns the item or ID for the given code |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | * @param string|null $type Item type if used and required |
| 34 | 34 | * @return \Aimeos\MShop\Common\Item\Iface|string|null Item object, unique ID or null if not found |
| 35 | 35 | */ |
| 36 | - public function get( $code, $type = null ); |
|
| 36 | + public function get($code, $type = null); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Adds the item or ID to the cache |
| 40 | 40 | * |
| 41 | 41 | * @param \Aimeos\MShop\Common\Item\Iface $item Item object |
| 42 | 42 | */ |
| 43 | - public function set( \Aimeos\MShop\Common\Item\Iface $item ); |
|
| 43 | + public function set(\Aimeos\MShop\Common\Item\Iface $item); |
|
| 44 | 44 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | * |
| 28 | 28 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
| 29 | 29 | */ |
| 30 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
|
| 30 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context) |
|
| 31 | 31 | { |
| 32 | 32 | $this->context = $context; |
| 33 | 33 | } |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | * @param array $data Associative list of catalog codes and lists of CSV field indexes and their data |
| 31 | 31 | * @return array Associative list of CSV field indexes and their converted data |
| 32 | 32 | */ |
| 33 | - protected function convertData( array $convlist, array $data ) |
|
| 33 | + protected function convertData(array $convlist, array $data) |
|
| 34 | 34 | { |
| 35 | - foreach( $convlist as $idx => $converter ) |
|
| 35 | + foreach ($convlist as $idx => $converter) |
|
| 36 | 36 | { |
| 37 | - foreach( $data as $code => $list ) |
|
| 37 | + foreach ($data as $code => $list) |
|
| 38 | 38 | { |
| 39 | - if( isset( $list[$idx] ) ) { |
|
| 40 | - $data[$code][$idx] = $converter->translate( $list[$idx] ); |
|
| 39 | + if (isset($list[$idx])) { |
|
| 40 | + $data[$code][$idx] = $converter->translate($list[$idx]); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -53,38 +53,38 @@ discard block |
||
| 53 | 53 | * @param string|null Name of the cache implementation |
| 54 | 54 | * @return \Aimeos\Controller\Common\Catalog\Import\Csv\Cache\Iface Cache object |
| 55 | 55 | */ |
| 56 | - protected function getCache( $type, $name = null ) |
|
| 56 | + protected function getCache($type, $name = null) |
|
| 57 | 57 | { |
| 58 | 58 | $context = $this->getContext(); |
| 59 | 59 | $config = $context->getConfig(); |
| 60 | 60 | $iface = '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Cache\\Iface'; |
| 61 | 61 | |
| 62 | - if( ctype_alnum( $type ) === false ) |
|
| 62 | + if (ctype_alnum($type) === false) |
|
| 63 | 63 | { |
| 64 | 64 | $classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Cache\\' . $type : '<not a string>'; |
| 65 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
| 65 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if( $name === null ) { |
|
| 69 | - $name = $config->get( 'controller/common/catalog/import/csv/cache/' . $type . '/name', 'Standard' ); |
|
| 68 | + if ($name === null) { |
|
| 69 | + $name = $config->get('controller/common/catalog/import/csv/cache/' . $type . '/name', 'Standard'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if( ctype_alnum( $name ) === false ) |
|
| 72 | + if (ctype_alnum($name) === false) |
|
| 73 | 73 | { |
| 74 | 74 | $classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Cache\\' . $type . '\\' . $name : '<not a string>'; |
| 75 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
| 75 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $classname = '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Cache\\' . ucfirst( $type ) . '\\' . $name; |
|
| 78 | + $classname = '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Cache\\' . ucfirst($type) . '\\' . $name; |
|
| 79 | 79 | |
| 80 | - if( class_exists( $classname ) === false ) { |
|
| 81 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); |
|
| 80 | + if (class_exists($classname) === false) { |
|
| 81 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" not found', $classname)); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $object = new $classname( $context ); |
|
| 84 | + $object = new $classname($context); |
|
| 85 | 85 | |
| 86 | - if( !( $object instanceof $iface ) ) { |
|
| 87 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" does not implement interface "%2$s"', $classname, $iface ) ); |
|
| 86 | + if (!($object instanceof $iface)) { |
|
| 87 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $iface)); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return $object; |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | * @param array $convmap List of converter names for the values at the position in the CSV file |
| 98 | 98 | * @return array Associative list of positions and converter objects |
| 99 | 99 | */ |
| 100 | - protected function getConverterList( array $convmap ) |
|
| 100 | + protected function getConverterList(array $convmap) |
|
| 101 | 101 | { |
| 102 | 102 | $convlist = []; |
| 103 | 103 | |
| 104 | - foreach( $convmap as $idx => $name ) { |
|
| 105 | - $convlist[$idx] = \Aimeos\MW\Convert\Factory::createConverter( $name ); |
|
| 104 | + foreach ($convmap as $idx => $name) { |
|
| 105 | + $convlist[$idx] = \Aimeos\MW\Convert\Factory::createConverter($name); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | return $convlist; |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @param integer $codePos Column position which contains the unique catalog code (starting from 0) |
| 118 | 118 | * @return array List of arrays with catalog codes as keys and list of values from the CSV file |
| 119 | 119 | */ |
| 120 | - protected function getData( \Aimeos\MW\Container\Content\Iface $content, $maxcnt, $codePos ) |
|
| 120 | + protected function getData(\Aimeos\MW\Container\Content\Iface $content, $maxcnt, $codePos) |
|
| 121 | 121 | { |
| 122 | 122 | $count = 0; |
| 123 | 123 | $data = []; |
| 124 | 124 | |
| 125 | - while( $content->valid() && $count++ < $maxcnt ) |
|
| 125 | + while ($content->valid() && $count++ < $maxcnt) |
|
| 126 | 126 | { |
| 127 | 127 | $row = $content->current(); |
| 128 | - $data[ $row[$codePos] ] = $row; |
|
| 128 | + $data[$row[$codePos]] = $row; |
|
| 129 | 129 | $content->next(); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -181,21 +181,21 @@ discard block |
||
| 181 | 181 | * @param array $mapping List of domain item keys with the CSV field position as key |
| 182 | 182 | * @return array List of associative arrays containing the chunked properties |
| 183 | 183 | */ |
| 184 | - protected function getMappedChunk( array &$data, array $mapping ) |
|
| 184 | + protected function getMappedChunk(array &$data, array $mapping) |
|
| 185 | 185 | { |
| 186 | 186 | $idx = 0; |
| 187 | 187 | $map = []; |
| 188 | 188 | |
| 189 | - foreach( $mapping as $pos => $key ) |
|
| 189 | + foreach ($mapping as $pos => $key) |
|
| 190 | 190 | { |
| 191 | - if( isset( $map[$idx][$key] ) ) { |
|
| 191 | + if (isset($map[$idx][$key])) { |
|
| 192 | 192 | $idx++; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if( isset( $data[$pos] ) ) |
|
| 195 | + if (isset($data[$pos])) |
|
| 196 | 196 | { |
| 197 | 197 | $map[$idx][$key] = $data[$pos]; |
| 198 | - unset( $data[$pos] ); |
|
| 198 | + unset($data[$pos]); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
@@ -209,39 +209,39 @@ discard block |
||
| 209 | 209 | * @param array $mappings Associative list of processor types as keys and index/data mappings as values |
| 210 | 210 | * @return \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface Processor object |
| 211 | 211 | */ |
| 212 | - protected function getProcessors( array $mappings ) |
|
| 212 | + protected function getProcessors(array $mappings) |
|
| 213 | 213 | { |
| 214 | 214 | $context = $this->getContext(); |
| 215 | 215 | $config = $context->getConfig(); |
| 216 | 216 | $iface = '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Processor\\Iface'; |
| 217 | - $object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Done( $context, [] ); |
|
| 217 | + $object = new \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Done($context, []); |
|
| 218 | 218 | |
| 219 | - foreach( $mappings as $type => $mapping ) |
|
| 219 | + foreach ($mappings as $type => $mapping) |
|
| 220 | 220 | { |
| 221 | - if( ctype_alnum( $type ) === false ) |
|
| 221 | + if (ctype_alnum($type) === false) |
|
| 222 | 222 | { |
| 223 | 223 | $classname = is_string($type) ? '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Processor\\' . $type : '<not a string>'; |
| 224 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
| 224 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $name = $config->get( 'controller/common/catalog/import/csv/processor/' . $type . '/name', 'Standard' ); |
|
| 227 | + $name = $config->get('controller/common/catalog/import/csv/processor/' . $type . '/name', 'Standard'); |
|
| 228 | 228 | |
| 229 | - if( ctype_alnum( $name ) === false ) |
|
| 229 | + if (ctype_alnum($name) === false) |
|
| 230 | 230 | { |
| 231 | 231 | $classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Processor\\' . $type . '\\' . $name : '<not a string>'; |
| 232 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
| 232 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $classname = '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Processor\\' . ucfirst( $type ) . '\\' . $name; |
|
| 235 | + $classname = '\\Aimeos\\Controller\\Common\\Catalog\\Import\\Csv\\Processor\\' . ucfirst($type) . '\\' . $name; |
|
| 236 | 236 | |
| 237 | - if( class_exists( $classname ) === false ) { |
|
| 238 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); |
|
| 237 | + if (class_exists($classname) === false) { |
|
| 238 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" not found', $classname)); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $object = new $classname( $context, $mapping, $object ); |
|
| 241 | + $object = new $classname($context, $mapping, $object); |
|
| 242 | 242 | |
| 243 | - if( !( $object instanceof $iface ) ) { |
|
| 244 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" does not implement interface "%2$s"', $classname, $iface ) ); |
|
| 243 | + if (!($object instanceof $iface)) { |
|
| 244 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $iface)); |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
@@ -257,23 +257,23 @@ discard block |
||
| 257 | 257 | * @param string $code Unique code of the type item |
| 258 | 258 | * @return string Unique ID of the type item |
| 259 | 259 | */ |
| 260 | - protected function getTypeId( $path, $domain, $code ) |
|
| 260 | + protected function getTypeId($path, $domain, $code) |
|
| 261 | 261 | { |
| 262 | - if( !isset( self::$types[$path][$domain] ) ) |
|
| 262 | + if (!isset(self::$types[$path][$domain])) |
|
| 263 | 263 | { |
| 264 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $path ); |
|
| 265 | - $key = str_replace( '/', '.', $path ); |
|
| 264 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $path); |
|
| 265 | + $key = str_replace('/', '.', $path); |
|
| 266 | 266 | |
| 267 | 267 | $search = $manager->createSearch(); |
| 268 | - $search->setConditions( $search->compare( '==', $key . '.domain', $domain ) ); |
|
| 268 | + $search->setConditions($search->compare('==', $key . '.domain', $domain)); |
|
| 269 | 269 | |
| 270 | - foreach( $manager->searchItems( $search ) as $id => $item ) { |
|
| 271 | - self::$types[$path][$domain][ $item->getCode() ] = $id; |
|
| 270 | + foreach ($manager->searchItems($search) as $id => $item) { |
|
| 271 | + self::$types[$path][$domain][$item->getCode()] = $id; |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if( !isset( self::$types[$path][$domain][$code] ) ) { |
|
| 276 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No type item for "%1$s/%2$s" in "%3$s" found', $domain, $code, $path ) ); |
|
| 275 | + if (!isset(self::$types[$path][$domain][$code])) { |
|
| 276 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No type item for "%1$s/%2$s" in "%3$s" found', $domain, $code, $path)); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | return self::$types[$path][$domain][$code]; |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | $context = \TestHelperJobs::getContext(); |
| 17 | 17 | $aimeos = \TestHelperJobs::getAimeos(); |
| 18 | 18 | |
| 19 | - $obj = \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController( $context, $aimeos ); |
|
| 20 | - $this->assertInstanceOf( '\\Aimeos\\Controller\\Jobs\\Iface', $obj); |
|
| 19 | + $obj = \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController($context, $aimeos); |
|
| 20 | + $this->assertInstanceOf('\\Aimeos\\Controller\\Jobs\\Iface', $obj); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | $context = \TestHelperJobs::getContext(); |
| 27 | 27 | $aimeos = \TestHelperJobs::getAimeos(); |
| 28 | 28 | |
| 29 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
| 30 | - \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController( $context, $aimeos, 'Wrong$$$Name' ); |
|
| 29 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
| 30 | + \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController($context, $aimeos, 'Wrong$$$Name'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | $context = \TestHelperJobs::getContext(); |
| 37 | 37 | $aimeos = \TestHelperJobs::getAimeos(); |
| 38 | 38 | |
| 39 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
| 40 | - \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController( $context, $aimeos, 'WrongClass' ); |
|
| 39 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
| 40 | + \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController($context, $aimeos, 'WrongClass'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $context = \TestHelperJobs::getContext(); |
| 47 | 47 | $aimeos = \TestHelperJobs::getAimeos(); |
| 48 | 48 | |
| 49 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
| 50 | - \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController( $context, $aimeos, 'Factory' ); |
|
| 49 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
| 50 | + \Aimeos\Controller\Jobs\Catalog\Import\Csv\Factory::createController($context, $aimeos, 'Factory'); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -581,12 +581,12 @@ |
||
| 581 | 581 | |
| 582 | 582 | if( isset( $catalogMap[$code] ) ) |
| 583 | 583 | { |
| 584 | - $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
|
| 584 | + $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
|
| 585 | 585 | $catalogItem = $manager->saveItem( $catalogItem ); |
| 586 | 586 | } |
| 587 | 587 | else |
| 588 | 588 | { |
| 589 | - $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
|
| 589 | + $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | $list = $processor->process( $catalogItem, $list ); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function getName() |
| 30 | 30 | { |
| 31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Catalog import CSV' ); |
|
| 31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Catalog import CSV'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function getDescription() |
| 41 | 41 | { |
| 42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Imports new and updates existing categories from CSV files' ); |
|
| 42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing categories from CSV files'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $context = $this->getContext(); |
| 55 | 55 | $config = $context->getConfig(); |
| 56 | 56 | $logger = $context->getLogger(); |
| 57 | - $domains = array( 'media', 'text' ); |
|
| 57 | + $domains = array('media', 'text'); |
|
| 58 | 58 | $mappings = $this->getDefaultMapping(); |
| 59 | 59 | |
| 60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @see controller/common/catalog/import/csv/converter |
| 75 | 75 | * @see controller/common/catalog/import/csv/max-size |
| 76 | 76 | */ |
| 77 | - $domains = $config->get( 'controller/common/catalog/import/csv/domains', $domains ); |
|
| 77 | + $domains = $config->get('controller/common/catalog/import/csv/domains', $domains); |
|
| 78 | 78 | |
| 79 | 79 | /** controller/jobs/catalog/import/csv/domains |
| 80 | 80 | * List of item domain names that should be retrieved along with the catalog items |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @see controller/jobs/catalog/import/csv/backup |
| 95 | 95 | * @see controller/common/catalog/import/csv/max-size |
| 96 | 96 | */ |
| 97 | - $domains = $config->get( 'controller/jobs/catalog/import/csv/domains', $domains ); |
|
| 97 | + $domains = $config->get('controller/jobs/catalog/import/csv/domains', $domains); |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /** controller/common/catalog/import/csv/mapping |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @see controller/common/catalog/import/csv/converter |
| 123 | 123 | * @see controller/common/catalog/import/csv/max-size |
| 124 | 124 | */ |
| 125 | - $mappings = $config->get( 'controller/common/catalog/import/csv/mapping', $mappings ); |
|
| 125 | + $mappings = $config->get('controller/common/catalog/import/csv/mapping', $mappings); |
|
| 126 | 126 | |
| 127 | 127 | /** controller/jobs/catalog/import/csv/mapping |
| 128 | 128 | * List of mappings between the position in the CSV file and item keys |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @see controller/jobs/catalog/import/csv/backup |
| 143 | 143 | * @see controller/common/catalog/import/csv/max-size |
| 144 | 144 | */ |
| 145 | - $mappings = $config->get( 'controller/jobs/catalog/import/csv/mapping', $mappings ); |
|
| 145 | + $mappings = $config->get('controller/jobs/catalog/import/csv/mapping', $mappings); |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | /** controller/common/catalog/import/csv/converter |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @see controller/common/catalog/import/csv/mapping |
| 185 | 185 | * @see controller/common/catalog/import/csv/max-size |
| 186 | 186 | */ |
| 187 | - $converters = $config->get( 'controller/common/catalog/import/csv/converter', [] ); |
|
| 187 | + $converters = $config->get('controller/common/catalog/import/csv/converter', []); |
|
| 188 | 188 | |
| 189 | 189 | /** controller/jobs/catalog/import/csv/converter |
| 190 | 190 | * List of converter names for the values at the position in the CSV file |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @see controller/jobs/catalog/import/csv/backup |
| 205 | 205 | * @see controller/common/catalog/import/csv/max-size |
| 206 | 206 | */ |
| 207 | - $converters = $config->get( 'controller/jobs/catalog/import/csv/converter', $converters ); |
|
| 207 | + $converters = $config->get('controller/jobs/catalog/import/csv/converter', $converters); |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | /** controller/common/catalog/import/csv/max-size |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @see controller/common/catalog/import/csv/mapping |
| 225 | 225 | * @see controller/common/catalog/import/csv/converter |
| 226 | 226 | */ |
| 227 | - $maxcnt = (int) $config->get( 'controller/common/catalog/import/csv/max-size', 1000 ); |
|
| 227 | + $maxcnt = (int) $config->get('controller/common/catalog/import/csv/max-size', 1000); |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | /** controller/jobs/catalog/import/csv/skip-lines |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @see controller/jobs/catalog/import/csv/backup |
| 247 | 247 | * @see controller/common/catalog/import/csv/max-size |
| 248 | 248 | */ |
| 249 | - $skiplines = (int) $config->get( 'controller/jobs/catalog/import/csv/skip-lines', 0 ); |
|
| 249 | + $skiplines = (int) $config->get('controller/jobs/catalog/import/csv/skip-lines', 0); |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | 252 | /** controller/jobs/catalog/import/csv/strict |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @see controller/jobs/catalog/import/csv/backup |
| 271 | 271 | * @see controller/common/catalog/import/csv/max-size |
| 272 | 272 | */ |
| 273 | - $strict = (bool) $config->get( 'controller/jobs/catalog/import/csv/strict', true ); |
|
| 273 | + $strict = (bool) $config->get('controller/jobs/catalog/import/csv/strict', true); |
|
| 274 | 274 | |
| 275 | 275 | |
| 276 | 276 | /** controller/jobs/catalog/import/csv/backup |
@@ -303,75 +303,75 @@ discard block |
||
| 303 | 303 | * @see controller/jobs/catalog/import/csv/strict |
| 304 | 304 | * @see controller/common/catalog/import/csv/max-size |
| 305 | 305 | */ |
| 306 | - $backup = $config->get( 'controller/jobs/catalog/import/csv/backup' ); |
|
| 306 | + $backup = $config->get('controller/jobs/catalog/import/csv/backup'); |
|
| 307 | 307 | |
| 308 | 308 | |
| 309 | - if( !isset( $mappings['item'] ) || !is_array( $mappings['item'] ) ) |
|
| 309 | + if (!isset($mappings['item']) || !is_array($mappings['item'])) |
|
| 310 | 310 | { |
| 311 | - $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
|
| 312 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 311 | + $msg = sprintf('Required mapping key "%1$s" is missing or contains no array', 'item'); |
|
| 312 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | try |
| 316 | 316 | { |
| 317 | 317 | $procMappings = $mappings; |
| 318 | - unset( $procMappings['item'] ); |
|
| 318 | + unset($procMappings['item']); |
|
| 319 | 319 | |
| 320 | - $codePos = $this->getCodePosition( $mappings['item'] ); |
|
| 321 | - $convlist = $this->getConverterList( $converters ); |
|
| 322 | - $processor = $this->getProcessors( $procMappings ); |
|
| 323 | - $catalogMap = $this->getCatalogMap( $domains ); |
|
| 320 | + $codePos = $this->getCodePosition($mappings['item']); |
|
| 321 | + $convlist = $this->getConverterList($converters); |
|
| 322 | + $processor = $this->getProcessors($procMappings); |
|
| 323 | + $catalogMap = $this->getCatalogMap($domains); |
|
| 324 | 324 | $container = $this->getContainer(); |
| 325 | 325 | $path = $container->getName(); |
| 326 | 326 | |
| 327 | 327 | |
| 328 | - $msg = sprintf( 'Started catalog import from "%1$s" (%2$s)', $path, __CLASS__ ); |
|
| 329 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 328 | + $msg = sprintf('Started catalog import from "%1$s" (%2$s)', $path, __CLASS__); |
|
| 329 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
| 330 | 330 | |
| 331 | - foreach( $container as $content ) |
|
| 331 | + foreach ($container as $content) |
|
| 332 | 332 | { |
| 333 | 333 | $name = $content->getName(); |
| 334 | 334 | |
| 335 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
| 335 | + for ($i = 0; $i < $skiplines; $i++) { |
|
| 336 | 336 | $content->next(); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
| 339 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
| 340 | 340 | { |
| 341 | - $data = $this->convertData( $convlist, $data ); |
|
| 342 | - $errcnt = $this->import( $catalogMap, $data, $mappings['item'], $processor, $strict ); |
|
| 343 | - $chunkcnt = count( $data ); |
|
| 341 | + $data = $this->convertData($convlist, $data); |
|
| 342 | + $errcnt = $this->import($catalogMap, $data, $mappings['item'], $processor, $strict); |
|
| 343 | + $chunkcnt = count($data); |
|
| 344 | 344 | |
| 345 | 345 | $msg = 'Imported catalog lines from "%1$s": %2$d/%3$d (%4$s)'; |
| 346 | - $logger->log( sprintf( $msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 346 | + $logger->log(sprintf($msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 347 | 347 | |
| 348 | 348 | $errors += $errcnt; |
| 349 | 349 | $total += $chunkcnt; |
| 350 | - unset( $data ); |
|
| 350 | + unset($data); |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | $container->close(); |
| 355 | 355 | } |
| 356 | - catch( \Exception $e ) |
|
| 356 | + catch (\Exception $e) |
|
| 357 | 357 | { |
| 358 | - $logger->log( 'Catalog import error: ' . $e->getMessage() ); |
|
| 359 | - $logger->log( $e->getTraceAsString() ); |
|
| 358 | + $logger->log('Catalog import error: ' . $e->getMessage()); |
|
| 359 | + $logger->log($e->getTraceAsString()); |
|
| 360 | 360 | |
| 361 | - throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
|
| 361 | + throw new \Aimeos\Controller\Jobs\Exception($e->getMessage()); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | $msg = 'Finished catalog import from "%1$s": %2$d successful, %3$s errors, %4$s total (%5$s)'; |
| 365 | - $logger->log( sprintf( $msg, $path, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 365 | + $logger->log(sprintf($msg, $path, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 366 | 366 | |
| 367 | - if( $errors > 0 ) |
|
| 367 | + if ($errors > 0) |
|
| 368 | 368 | { |
| 369 | - $msg = sprintf( 'Invalid catalog lines in "%1$s": %2$d/%3$d', $path, $errors, $total ); |
|
| 370 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 369 | + $msg = sprintf('Invalid catalog lines in "%1$s": %2$d/%3$d', $path, $errors, $total); |
|
| 370 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if( !empty( $backup ) && @rename( $path, strftime( $backup ) ) === false ) { |
|
| 374 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Unable to move imported file' ) ); |
|
| 373 | + if (!empty($backup) && @rename($path, strftime($backup)) === false) { |
|
| 374 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to move imported file')); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
@@ -383,16 +383,16 @@ discard block |
||
| 383 | 383 | * @return integer Position of the "catalog.code" column |
| 384 | 384 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "catalog.code" is found |
| 385 | 385 | */ |
| 386 | - protected function getCodePosition( array $mapping ) |
|
| 386 | + protected function getCodePosition(array $mapping) |
|
| 387 | 387 | { |
| 388 | - foreach( $mapping as $pos => $key ) |
|
| 388 | + foreach ($mapping as $pos => $key) |
|
| 389 | 389 | { |
| 390 | - if( $key === 'catalog.code' ) { |
|
| 390 | + if ($key === 'catalog.code') { |
|
| 391 | 391 | return $pos; |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "catalog.code" column in CSV mapping found' ) ); |
|
| 395 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "catalog.code" column in CSV mapping found')); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @see controller/jobs/catalog/import/csv/container/content |
| 428 | 428 | * @see controller/jobs/catalog/import/csv/container/options |
| 429 | 429 | */ |
| 430 | - $location = $config->get( 'controller/jobs/catalog/import/csv/location', '.' ); |
|
| 430 | + $location = $config->get('controller/jobs/catalog/import/csv/location', '.'); |
|
| 431 | 431 | |
| 432 | 432 | /** controller/jobs/catalog/import/csv/container/type |
| 433 | 433 | * Nave of the container type to read the data from |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | * @see controller/jobs/catalog/import/csv/container/content |
| 451 | 451 | * @see controller/jobs/catalog/import/csv/container/options |
| 452 | 452 | */ |
| 453 | - $container = $config->get( 'controller/jobs/catalog/import/csv/container/type', 'Directory' ); |
|
| 453 | + $container = $config->get('controller/jobs/catalog/import/csv/container/type', 'Directory'); |
|
| 454 | 454 | |
| 455 | 455 | /** controller/jobs/catalog/import/csv/container/content |
| 456 | 456 | * Name of the content type inside the container to read the data from |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | * @see controller/jobs/catalog/import/csv/container/type |
| 472 | 472 | * @see controller/jobs/catalog/import/csv/container/options |
| 473 | 473 | */ |
| 474 | - $content = $config->get( 'controller/jobs/catalog/import/csv/container/content', 'CSV' ); |
|
| 474 | + $content = $config->get('controller/jobs/catalog/import/csv/container/content', 'CSV'); |
|
| 475 | 475 | |
| 476 | 476 | /** controller/jobs/catalog/import/csv/container/options |
| 477 | 477 | * List of file container options for the catalog import files |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | * @see controller/jobs/catalog/import/csv/container/content |
| 490 | 490 | * @see controller/jobs/catalog/import/csv/container/type |
| 491 | 491 | */ |
| 492 | - $options = $config->get( 'controller/jobs/catalog/import/csv/container/options', [] ); |
|
| 492 | + $options = $config->get('controller/jobs/catalog/import/csv/container/options', []); |
|
| 493 | 493 | |
| 494 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
| 494 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | |
@@ -501,13 +501,13 @@ discard block |
||
| 501 | 501 | * @param array $domains List of domain names whose items should be fetched too |
| 502 | 502 | * @return array Associative list of catalog codes as keys and items implementing \Aimeos\MShop\Catalog\Item\Iface as values |
| 503 | 503 | */ |
| 504 | - protected function getCatalogMap( array $domains ) |
|
| 504 | + protected function getCatalogMap(array $domains) |
|
| 505 | 505 | { |
| 506 | 506 | $map = []; |
| 507 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' ); |
|
| 508 | - $search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
|
| 507 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog'); |
|
| 508 | + $search = $manager->createSearch()->setSlice(0, 0x7fffffff); |
|
| 509 | 509 | |
| 510 | - foreach( $manager->searchItems( $search, $domains ) as $item ) { |
|
| 510 | + foreach ($manager->searchItems($search, $domains) as $item) { |
|
| 511 | 511 | $map[$item->getCode()] = $item; |
| 512 | 512 | } |
| 513 | 513 | |
@@ -523,21 +523,21 @@ discard block |
||
| 523 | 523 | * @param string $code Catalog item code of the parent category |
| 524 | 524 | * @return string|null ID of the parent category or null for top level nodes |
| 525 | 525 | */ |
| 526 | - protected function getParentId( array $catalogMap, array $map, $code ) |
|
| 526 | + protected function getParentId(array $catalogMap, array $map, $code) |
|
| 527 | 527 | { |
| 528 | - if( !isset( $map['catalog.parent'] ) ) |
|
| 528 | + if (!isset($map['catalog.parent'])) |
|
| 529 | 529 | { |
| 530 | - $msg = sprintf( 'Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code ); |
|
| 531 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 530 | + $msg = sprintf('Required column "%1$s" not found for code "%2$s"', 'catalog.parent', $code); |
|
| 531 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - if( $map['catalog.parent'] != '' && !isset( $catalogMap[$map['catalog.parent']] ) ) |
|
| 534 | + if ($map['catalog.parent'] != '' && !isset($catalogMap[$map['catalog.parent']])) |
|
| 535 | 535 | { |
| 536 | - $msg = sprintf( 'Parent node for code "%1$s" not found', $map['catalog.parent'] ); |
|
| 537 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 536 | + $msg = sprintf('Parent node for code "%1$s" not found', $map['catalog.parent']); |
|
| 537 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - return ( $map['catalog.parent'] != '' ? $catalogMap[$map['catalog.parent']]->getId() : null ); |
|
| 540 | + return ($map['catalog.parent'] != '' ? $catalogMap[$map['catalog.parent']]->getId() : null); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | |
@@ -552,61 +552,61 @@ discard block |
||
| 552 | 552 | * @return integer Number of catalogs that couldn't be imported |
| 553 | 553 | * @throws \Aimeos\Controller\Jobs\Exception |
| 554 | 554 | */ |
| 555 | - protected function import( array &$catalogMap, array $data, array $mapping, |
|
| 556 | - \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict ) |
|
| 555 | + protected function import(array &$catalogMap, array $data, array $mapping, |
|
| 556 | + \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict) |
|
| 557 | 557 | { |
| 558 | 558 | $errors = 0; |
| 559 | 559 | $context = $this->getContext(); |
| 560 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
|
| 560 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
| 561 | 561 | |
| 562 | - foreach( $data as $code => $list ) |
|
| 562 | + foreach ($data as $code => $list) |
|
| 563 | 563 | { |
| 564 | 564 | $manager->begin(); |
| 565 | 565 | |
| 566 | 566 | try |
| 567 | 567 | { |
| 568 | - if( isset( $catalogMap[$code] ) ) { |
|
| 568 | + if (isset($catalogMap[$code])) { |
|
| 569 | 569 | $catalogItem = $catalogMap[$code]; |
| 570 | 570 | } else { |
| 571 | 571 | $catalogItem = $manager->createItem(); |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
| 574 | + $map = $this->getMappedChunk($list, $mapping); |
|
| 575 | 575 | |
| 576 | - if( isset( $map[0] ) ) |
|
| 576 | + if (isset($map[0])) |
|
| 577 | 577 | { |
| 578 | 578 | $map = $map[0]; // there can only be one chunk for the base catalog data |
| 579 | - $parentid = $this->getParentId( $catalogMap, $map, $code ); |
|
| 580 | - $catalogItem->fromArray( $this->addItemDefaults( $map ) ); |
|
| 579 | + $parentid = $this->getParentId($catalogMap, $map, $code); |
|
| 580 | + $catalogItem->fromArray($this->addItemDefaults($map)); |
|
| 581 | 581 | |
| 582 | - if( isset( $catalogMap[$code] ) ) |
|
| 582 | + if (isset($catalogMap[$code])) |
|
| 583 | 583 | { |
| 584 | - $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
|
| 585 | - $catalogItem = $manager->saveItem( $catalogItem ); |
|
| 584 | + $manager->moveItem($catalogItem->getId(), $catalogItem->getParentId(), $parentid); |
|
| 585 | + $catalogItem = $manager->saveItem($catalogItem); |
|
| 586 | 586 | } |
| 587 | 587 | else |
| 588 | 588 | { |
| 589 | - $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
|
| 589 | + $catalogItem = $manager->insertItem($catalogItem, $parentid); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - $list = $processor->process( $catalogItem, $list ); |
|
| 592 | + $list = $processor->process($catalogItem, $list); |
|
| 593 | 593 | $catalogMap[$code] = $catalogItem; |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | $manager->commit(); |
| 597 | 597 | } |
| 598 | - catch( \Exception $e ) |
|
| 598 | + catch (\Exception $e) |
|
| 599 | 599 | { |
| 600 | 600 | $manager->rollback(); |
| 601 | 601 | |
| 602 | - $msg = sprintf( 'Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
| 603 | - $context->getLogger()->log( $msg ); |
|
| 602 | + $msg = sprintf('Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage()); |
|
| 603 | + $context->getLogger()->log($msg); |
|
| 604 | 604 | |
| 605 | 605 | $errors++; |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | - if( $strict && !empty( $list ) ) { |
|
| 609 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
| 608 | + if ($strict && !empty($list)) { |
|
| 609 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | 612 | |
@@ -620,9 +620,9 @@ discard block |
||
| 620 | 620 | * @param array $list Associative list of domain item keys and their values, e.g. "catalog.status" => 1 |
| 621 | 621 | * @return array Given associative list enriched by default values if they were not already set |
| 622 | 622 | */ |
| 623 | - protected function addItemDefaults( array $list ) |
|
| 623 | + protected function addItemDefaults(array $list) |
|
| 624 | 624 | { |
| 625 | - if( !isset( $list['catalog.status'] ) ) { |
|
| 625 | + if (!isset($list['catalog.status'])) { |
|
| 626 | 626 | $list['catalog.status'] = 1; |
| 627 | 627 | } |
| 628 | 628 | |
@@ -352,8 +352,7 @@ discard block |
||
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | $container->close(); |
| 355 | - } |
|
| 356 | - catch( \Exception $e ) |
|
| 355 | + } catch( \Exception $e ) |
|
| 357 | 356 | { |
| 358 | 357 | $logger->log( 'Catalog import error: ' . $e->getMessage() ); |
| 359 | 358 | $logger->log( $e->getTraceAsString() ); |
@@ -583,8 +582,7 @@ discard block |
||
| 583 | 582 | { |
| 584 | 583 | $manager->moveItem( $catalogItem->getId(), $catalogItem->getParentId(), $parentid ); |
| 585 | 584 | $catalogItem = $manager->saveItem( $catalogItem ); |
| 586 | - } |
|
| 587 | - else |
|
| 585 | + } else |
|
| 588 | 586 | { |
| 589 | 587 | $catalogItem = $manager->insertItem( $catalogItem, $parentid ); |
| 590 | 588 | } |
@@ -594,8 +592,7 @@ discard block |
||
| 594 | 592 | } |
| 595 | 593 | |
| 596 | 594 | $manager->commit(); |
| 597 | - } |
|
| 598 | - catch( \Exception $e ) |
|
| 595 | + } catch( \Exception $e ) |
|
| 599 | 596 | { |
| 600 | 597 | $manager->rollback(); |
| 601 | 598 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string|null $name Name of the controller or "Standard" if null |
| 30 | 30 | * @return \Aimeos\Controller\Jobs\Iface New controller object |
| 31 | 31 | */ |
| 32 | - public static function createController( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null ) |
|
| 32 | + public static function createController(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null) |
|
| 33 | 33 | { |
| 34 | 34 | /** controller/jobs/catalog/import/csv/name |
| 35 | 35 | * Class name of the used catalog suggestions scheduler controller implementation |
@@ -64,20 +64,20 @@ discard block |
||
| 64 | 64 | * @since 2018.04 |
| 65 | 65 | * @category Developer |
| 66 | 66 | */ |
| 67 | - if ( $name === null ) { |
|
| 67 | + if ($name === null) { |
|
| 68 | 68 | $name = $context->getConfig()->get('controller/jobs/catalog/import/csv/name', 'Standard'); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if ( ctype_alnum($name) === false ) |
|
| 71 | + if (ctype_alnum($name) === false) |
|
| 72 | 72 | { |
| 73 | 73 | $classname = is_string($name) ? '\\Aimeos\\Controller\\Jobs\\Catalog\\Import\\Csv\\' . $name : '<not a string>'; |
| 74 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
| 74 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $iface = '\\Aimeos\\Controller\\Jobs\\Iface'; |
| 78 | 78 | $classname = '\\Aimeos\\Controller\\Jobs\\Catalog\\Import\\Csv\\' . $name; |
| 79 | 79 | |
| 80 | - $controller = self::createControllerBase( $context, $aimeos, $classname, $iface ); |
|
| 80 | + $controller = self::createControllerBase($context, $aimeos, $classname, $iface); |
|
| 81 | 81 | |
| 82 | 82 | /** controller/jobs/catalog/import/csv/decorators/excludes |
| 83 | 83 | * Excludes decorators added by the "common" option from the catalog import CSV job controller |
@@ -154,6 +154,6 @@ discard block |
||
| 154 | 154 | * @see controller/jobs/catalog/import/csv/decorators/excludes |
| 155 | 155 | * @see controller/jobs/catalog/import/csv/decorators/global |
| 156 | 156 | */ |
| 157 | - return self::addControllerDecorators( $context, $aimeos, $controller, 'catalog/import/csv' ); |
|
| 157 | + return self::addControllerDecorators($context, $aimeos, $controller, 'catalog/import/csv'); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | \ No newline at end of file |