Skip to content

Commit fc05202

Browse files
author
Tulika,Eugene(etulika)
committed
Merge pull request #161 from magento-api/MAGETWO-35266-Update-fails-trying-to-recreate-tables
[API] MAGETWO-35266: Update fails trying to recreate tables
2 parents b456cd1 + 28cf7e4 commit fc05202

File tree

8 files changed

+225
-140
lines changed

8 files changed

+225
-140
lines changed

app/code/Magento/Eav/Model/EavCustomAttributeTypeLocator.php

+36
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\Framework\Exception\NoSuchEntityException;
1111
use Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface;
1212

13+
/**
14+
* Class to locate types for Eav custom attributes
15+
*/
1316
class EavCustomAttributeTypeLocator implements CustomAttributeTypeLocatorInterface
1417
{
1518
/**
@@ -32,7 +35,22 @@ class EavCustomAttributeTypeLocator implements CustomAttributeTypeLocatorInterfa
3235
*
3336
* @param AttributeRepositoryInterface $attributeRepository
3437
* @param array $serviceEntityTypeMap
38+
* <pre>
39+
* [
40+
* 'ServiceInterfaceA' => 'EavEntityType1',
41+
* 'ServiceInterfaceB' => 'EavEntityType2'
42+
* ]
43+
* </pre>
3544
* @param array $serviceBackendModelDataInterfaceMap
45+
* <pre>
46+
* [
47+
* 'ServiceInterfaceA' => ['BackendType1' => 'ServiceDataInterface1'],
48+
* 'ServiceInterfaceB' => [
49+
* 'BackendType2' => 'ServiceDataInterface2',
50+
* 'BackendType3' => 'ServiceDataInterface3'
51+
* ]
52+
* ]
53+
* </pre>
3654
*/
3755
public function __construct(
3856
AttributeRepositoryInterface $attributeRepository,
@@ -69,4 +87,22 @@ public function getType($attributeCode, $serviceClass)
6987

7088
return $dataInterface;
7189
}
90+
91+
/**
92+
* {@inheritdoc}
93+
*/
94+
public function getAllServiceDataInterfaces()
95+
{
96+
$dataInterfaceArray = [];
97+
if (!$this->serviceBackendModelDataInterfaceMap) {
98+
return [];
99+
} else {
100+
foreach ($this->serviceBackendModelDataInterfaceMap as $serviceArray) {
101+
foreach ($serviceArray as $dataInterface) {
102+
$dataInterfaceArray[] = $dataInterface;
103+
}
104+
}
105+
}
106+
return $dataInterfaceArray;
107+
}
72108
}

app/code/Magento/Eav/Test/Unit/Model/EavCustomAttributeTypeLocatorTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,26 @@ public function getTypeDataProvider()
147147
]
148148
];
149149
}
150+
151+
public function testGetAllServiceDataInterfaceEmpty()
152+
{
153+
$this->eavCustomAttributeTypeLocator = new EavCustomAttributeTypeLocator($this->attributeRepository);
154+
$this->assertEmpty($this->eavCustomAttributeTypeLocator->getAllServiceDataInterfaces());
155+
}
156+
157+
public function testGetAllServiceDataInterface()
158+
{
159+
$serviceBackendModelDataInterfaceMapData = [
160+
'ServiceA' => ['BackendA' => 'ServiceDataInterfaceA'],
161+
'ServiceB' => ['BackendB' => 'ServiceDataInterfaceB', 'BackendC' => 'ServiceDataInterfaceC'],
162+
'ServiceC' => ['BackendD' => 'ServiceDataInterfaceD']
163+
];
164+
$this->eavCustomAttributeTypeLocator = new EavCustomAttributeTypeLocator(
165+
$this->attributeRepository, [], $serviceBackendModelDataInterfaceMapData
166+
);
167+
$this->assertEquals(
168+
['ServiceDataInterfaceA', 'ServiceDataInterfaceB', 'ServiceDataInterfaceC', 'ServiceDataInterfaceD'],
169+
$this->eavCustomAttributeTypeLocator->getAllServiceDataInterfaces()
170+
);
171+
}
150172
}

app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class Generator
5050
protected $storeManager;
5151

5252
/**
53-
* @var array
53+
* @var \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface
5454
*/
55-
protected $customAttributeMapArray = null;
55+
protected $customAttributeTypeLocator = null;
5656

5757
/**
5858
* Initialize dependencies.
@@ -62,22 +62,22 @@ class Generator
6262
* @param \Magento\Framework\App\Cache\Type\Webapi $cache
6363
* @param \Magento\Framework\Reflection\TypeProcessor $typeProcessor
6464
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
65-
* @param \Magento\Framework\Object $customAttributeMap
65+
* @param \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface $customAttributeTypeLocator
6666
*/
6767
public function __construct(
6868
\Magento\Webapi\Model\Soap\Config $apiConfig,
6969
WsdlFactory $wsdlFactory,
7070
\Magento\Framework\App\Cache\Type\Webapi $cache,
7171
\Magento\Framework\Reflection\TypeProcessor $typeProcessor,
7272
\Magento\Store\Model\StoreManagerInterface $storeManager,
73-
\Magento\Framework\Object $customAttributeMap
73+
\Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface $customAttributeTypeLocator
7474
) {
7575
$this->_apiConfig = $apiConfig;
7676
$this->_wsdlFactory = $wsdlFactory;
7777
$this->_cache = $cache;
7878
$this->_typeProcessor = $typeProcessor;
7979
$this->storeManager = $storeManager;
80-
$this->customAttributeMapArray = array_values($customAttributeMap->getData());
80+
$this->customAttributeTypeLocator = $customAttributeTypeLocator;
8181
}
8282

8383
/**
@@ -178,7 +178,7 @@ protected function _generate($requestedServices, $endPointUrl)
178178
*/
179179
protected function addCustomAttributeTypes($wsdl)
180180
{
181-
foreach ($this->customAttributeMapArray as $customAttributeClass) {
181+
foreach ($this->customAttributeTypeLocator->getAllServiceDataInterfaces() as $customAttributeClass) {
182182
$typeName = $this->_typeProcessor->register($customAttributeClass);
183183
$wsdl->addComplexType($typeName);
184184
}

app/code/Magento/Webapi/Test/Unit/Model/Soap/Wsdl/GeneratorTest.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase
1212
/** @var \Magento\Webapi\Model\Soap\Wsdl\Generator */
1313
protected $_wsdlGenerator;
1414

15-
/** @var \Magento\Framework\Object */
16-
protected $customAttributeMap;
15+
/**
16+
* @var \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $customAttributeTypeLocator = null;
1719

1820
/** @var \Magento\Webapi\Model\Soap\Config|\PHPUnit_Framework_MockObject_MockObject */
1921
protected $_soapConfigMock;
@@ -93,7 +95,9 @@ protected function setUp()
9395

9496
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
9597

96-
$this->customAttributeMap = $objectManager->getObject('Magento\Framework\Object');
98+
$this->customAttributeTypeLocator = $objectManager
99+
->getObject('Magento\Eav\Model\EavCustomAttributeTypeLocator');
100+
97101
$this->_wsdlGenerator = $objectManager->getObject(
98102
'Magento\Webapi\Model\Soap\Wsdl\Generator',
99103
[
@@ -102,7 +106,7 @@ protected function setUp()
102106
'cache' => $this->_cacheMock,
103107
'typeProcessor' => $this->_typeProcessor,
104108
'storeManagerMock' => $this->storeManagerMock,
105-
'customAttributeMap' => $this->customAttributeMap
109+
'customAttributeTypeLocator' => $this->customAttributeTypeLocator
106110
]
107111
);
108112

@@ -196,7 +200,7 @@ public function testHandleWithException()
196200
$this->_cacheMock,
197201
$this->_typeProcessor,
198202
$this->storeManagerMock,
199-
$this->customAttributeMap
203+
$this->customAttributeTypeLocator
200204
]
201205
)->getMock();
202206

app/code/Magento/Webapi/etc/di.xml

-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Webapi</argument>
2828
</arguments>
2929
</type>
30-
<type name="Magento\Webapi\Model\Soap\Wsdl\Generator">
31-
<arguments>
32-
<argument name="customAttributeMap" xsi:type="object">CustomAttributeMap</argument>
33-
</arguments>
34-
</type>
3530
<type name="Magento\Integration\Model\ConfigBasedIntegrationManager">
3631
<plugin name="webapiSetup" type="Magento\Webapi\Model\Plugin\Manager" />
3732
</type>

dev/tests/api-functional/_files/Magento/TestModuleMSC/etc/di.xml

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,25 @@
3030
<argument name="resource" xsi:type="object">Magento\TestModuleMSC\Model\Resource\Item</argument>
3131
</arguments>
3232
</type>
33-
<virtualType name="CustomAttributeMap" type="Magento\Framework\Object">
33+
<virtualType name="CustomAttributeMap" type="Magento\Framework\Object">
3434
<arguments>
3535
<argument name="data" xsi:type="array">
3636
<item name="customAttributeDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
3737
<item name="customAttributeNestedDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
3838
</argument>
3939
</arguments>
4040
</virtualType>
41+
<type name="Magento\Eav\Model\EavCustomAttributeTypeLocator">
42+
<arguments>
43+
<argument name="serviceEntityTypeMap" xsi:type="array">
44+
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="string">1</item>
45+
</argument>
46+
<argument name="serviceBackendModelDataInterfaceMap" xsi:type="array">
47+
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="array">
48+
<item name="Magento\Sample\BackendType1" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
49+
<item name="Magento\Sample\BackendType2" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
50+
</item>
51+
</argument>
52+
</arguments>
53+
</type>
4154
</config>

lib/internal/Magento/Framework/Webapi/CustomAttributeTypeLocatorInterface.php

+7
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ interface CustomAttributeTypeLocatorInterface
1919
* @return string|null
2020
*/
2121
public function getType($attributeCode, $serviceClass);
22+
23+
/**
24+
* Get list of all Data Interface corresponding to complex custom attribute types
25+
*
26+
* @return string[] array of Data Interface class names
27+
*/
28+
public function getAllServiceDataInterfaces();
2229
}

0 commit comments

Comments
 (0)