Completed
Push — master ( 47a117...268cfa )
by Aimeos
03:32
created
common/src/Controller/Common/Product/Import/Csv/Processor/Base.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@
 block discarded – undo
133 133
 	 *
134 134
 	 * @param array $list Associative list of key/value pairs
135 135
 	 * @param string $key Key for the value to retrieve
136
-	 * @param mixed $default Default value if key isn't found
136
+	 * @param string|null $default Default value if key isn't found
137 137
 	 * @param mixed Value for the key in the list of the default value
138 138
 	 */
139 139
 	protected function getValue( array $list, $key, $default )
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	 * @param array $mapping Associative list of field position in CSV as key and domain item key as value
33 33
 	 * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor
34 34
 	 */
35
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping,
36
-		\Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null )
35
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping,
36
+		\Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null)
37 37
 	{
38 38
 		$this->context = $context;
39 39
 		$this->mapping = $mapping;
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
 	 * @param integer $pos Computed position of the list item in the associated list of items
49 49
 	 * @return array Given associative list enriched by default values if they were not already set
50 50
 	 */
51
-	protected function addListItemDefaults( array $list, $pos )
51
+	protected function addListItemDefaults(array $list, $pos)
52 52
 	{
53
-		if( !isset( $list['product.lists.position'] ) ) {
53
+		if (!isset($list['product.lists.position'])) {
54 54
 			$list['product.lists.position'] = $pos;
55 55
 		}
56 56
 
57
-		if( !isset( $list['product.lists.status'] ) ) {
57
+		if (!isset($list['product.lists.status'])) {
58 58
 			$list['product.lists.status'] = 1;
59 59
 		}
60 60
 
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	protected function getObject()
94 94
 	{
95
-		if( $this->object === null ) {
96
-			throw new \Aimeos\Controller\Jobs\Exception( 'No processor object available' );
95
+		if ($this->object === null) {
96
+			throw new \Aimeos\Controller\Jobs\Exception('No processor object available');
97 97
 		}
98 98
 
99 99
 		return $this->object;
@@ -106,21 +106,21 @@  discard block
 block discarded – undo
106 106
 	 * @param array $data List of CSV fields with position as key and domain item key as value
107 107
 	 * @return array List of associative arrays containing the chunked properties
108 108
 	 */
109
-	protected function getMappedChunk( array &$data )
109
+	protected function getMappedChunk(array &$data)
110 110
 	{
111 111
 		$idx = 0;
112 112
 		$map = array();
113 113
 
114
-		foreach( $this->getMapping() as $pos => $key )
114
+		foreach ($this->getMapping() as $pos => $key)
115 115
 		{
116
-			if( isset( $map[$idx][$key] ) ) {
116
+			if (isset($map[$idx][$key])) {
117 117
 				$idx++;
118 118
 			}
119 119
 
120
-			if( isset( $data[$pos] ) )
120
+			if (isset($data[$pos]))
121 121
 			{
122 122
 				$map[$idx][$key] = $data[$pos];
123
-				unset( $data[$pos] );
123
+				unset($data[$pos]);
124 124
 			}
125 125
 		}
126 126
 
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 	 * @param mixed $default Default value if key isn't found
137 137
 	 * @param mixed Value for the key in the list of the default value
138 138
 	 */
139
-	protected function getValue( array $list, $key, $default )
139
+	protected function getValue(array $list, $key, $default)
140 140
 	{
141
-		return ( isset( $list[$key] ) ? $list[$key] : $default );
141
+		return (isset($list[$key]) ? $list[$key] : $default);
142 142
 	}
143 143
 }
Please login to merge, or discard this patch.
src/Controller/Common/Product/Import/Csv/Processor/Media/Standard.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 	 * @param array $mapping Associative list of field position in CSV as key and domain item key as value
43 43
 	 * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor
44 44
 	 */
45
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping,
46
-			\Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null )
45
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping,
46
+			\Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null)
47 47
 	{
48
-		parent::__construct( $context, $mapping, $object );
48
+		parent::__construct($context, $mapping, $object);
49 49
 
50 50
 		/** controller/common/product/import/csv/processor/media/listtypes
51 51
 		 * Names of the product list types for media that are updated or removed
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		 * @see controller/common/product/import/csv/processor/price/listtypes
67 67
 		 * @see controller/common/product/import/csv/processor/text/listtypes
68 68
 		 */
69
-		$this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/media/listtypes' );
69
+		$this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/media/listtypes');
70 70
 	}
71 71
 
72 72
 
@@ -77,72 +77,72 @@  discard block
 block discarded – undo
77 77
 	 * @param array $data List of CSV fields with position as key and data as value
78 78
 	 * @return array List of data which hasn't been imported
79 79
 	 */
80
-	public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data )
80
+	public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data)
81 81
 	{
82 82
 		$context = $this->getContext();
83
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'media' );
84
-		$listManager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists' );
85
-		$separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" );
83
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'media');
84
+		$listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists');
85
+		$separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n");
86 86
 
87 87
 		$manager->begin();
88 88
 
89 89
 		try
90 90
 		{
91
-			$map = $this->getMappedChunk( $data );
92
-			$listItems = $product->getListItems( 'media' );
91
+			$map = $this->getMappedChunk($data);
92
+			$listItems = $product->getListItems('media');
93 93
 
94
-			foreach( $map as $pos => $list )
94
+			foreach ($map as $pos => $list)
95 95
 			{
96
-				if( $this->checkEntry( $list ) === false ) {
96
+				if ($this->checkEntry($list) === false) {
97 97
 					continue;
98 98
 				}
99 99
 
100
-				$urls = explode( $separator, $list['media.url'] );
101
-				$type = $this->getValue( $list, 'media.type', 'default' );
102
-				$typecode = $this->getValue( $list, 'product.lists.type', 'default' );
100
+				$urls = explode($separator, $list['media.url']);
101
+				$type = $this->getValue($list, 'media.type', 'default');
102
+				$typecode = $this->getValue($list, 'product.lists.type', 'default');
103 103
 
104
-				if( ( $langid = $this->getValue( $list, 'media.languageid', null ) ) === '' ) {
104
+				if (($langid = $this->getValue($list, 'media.languageid', null)) === '') {
105 105
 					$langid = null;
106 106
 				}
107 107
 
108
-				foreach( $urls as $url )
108
+				foreach ($urls as $url)
109 109
 				{
110
-					if( ( $listItem = array_shift( $listItems ) ) !== null ) {
110
+					if (($listItem = array_shift($listItems)) !== null) {
111 111
 						$refItem = $listItem->getRefItem();
112 112
 					} else {
113 113
 						$listItem = $listManager->createItem();
114 114
 						$refItem = $manager->createItem();
115 115
 					}
116 116
 
117
-					$list['media.typeid'] = $this->getTypeId( 'media/type', 'product', $type );
117
+					$list['media.typeid'] = $this->getTypeId('media/type', 'product', $type);
118 118
 					$list['media.languageid'] = $langid;
119 119
 					$list['media.domain'] = 'product';
120 120
 					$list['media.url'] = $url;
121 121
 
122
-					$refItem->fromArray( $this->addItemDefaults( $list ) );
123
-					$manager->saveItem( $refItem );
122
+					$refItem->fromArray($this->addItemDefaults($list));
123
+					$manager->saveItem($refItem);
124 124
 
125
-					$list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'media', $typecode );
125
+					$list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'media', $typecode);
126 126
 					$list['product.lists.parentid'] = $product->getId();
127 127
 					$list['product.lists.refid'] = $refItem->getId();
128 128
 					$list['product.lists.domain'] = 'media';
129 129
 
130
-					$listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) );
131
-					$listManager->saveItem( $listItem );
130
+					$listItem->fromArray($this->addListItemDefaults($list, $pos++));
131
+					$listManager->saveItem($listItem);
132 132
 				}
133 133
 			}
134 134
 
135
-			foreach( $listItems as $listItem )
135
+			foreach ($listItems as $listItem)
136 136
 			{
137
-				$manager->deleteItem( $listItem->getRefItem()->getId() );
138
-				$listManager->deleteItem( $listItem->getId() );
137
+				$manager->deleteItem($listItem->getRefItem()->getId());
138
+				$listManager->deleteItem($listItem->getId());
139 139
 			}
140 140
 
141
-			$remaining = $this->getObject()->process( $product, $data );
141
+			$remaining = $this->getObject()->process($product, $data);
142 142
 
143 143
 			$manager->commit();
144 144
 		}
145
-		catch( \Exception $e )
145
+		catch (\Exception $e)
146 146
 		{
147 147
 			$manager->rollback();
148 148
 			throw $e;
@@ -158,17 +158,17 @@  discard block
 block discarded – undo
158 158
 	 * @param array $list Associative list of domain item keys and their values, e.g. "media.status" => 1
159 159
 	 * @return array Given associative list enriched by default values if they were not already set
160 160
 	 */
161
-	protected function addItemDefaults( array $list )
161
+	protected function addItemDefaults(array $list)
162 162
 	{
163
-		if( !isset( $list['media.label'] ) ) {
163
+		if (!isset($list['media.label'])) {
164 164
 			$list['media.label'] = $list['media.url'];
165 165
 		}
166 166
 
167
-		if( !isset( $list['media.preview'] ) ) {
167
+		if (!isset($list['media.preview'])) {
168 168
 			$list['media.preview'] = $list['media.url'];
169 169
 		}
170 170
 
171
-		if( !isset( $list['media.status'] ) ) {
171
+		if (!isset($list['media.status'])) {
172 172
 			$list['media.status'] = 1;
173 173
 		}
174 174
 
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 	 * @param array $list Associative list of key/value pairs from the mapping
183 183
 	 * @return boolean True if valid, false if not
184 184
 	 */
185
-	protected function checkEntry( array $list )
185
+	protected function checkEntry(array $list)
186 186
 	{
187
-		if( !isset( $list['media.url'] ) || $list['media.url'] === '' || isset( $list['product.lists.type'] )
188
-				&& $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes )
187
+		if (!isset($list['media.url']) || $list['media.url'] === '' || isset($list['product.lists.type'])
188
+				&& $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes)
189 189
 		) {
190 190
 			return false;
191 191
 		}
Please login to merge, or discard this patch.