Skip to content

Commit

Permalink
Merge pull request #161 from magento-api/MAGETWO-35266-Update-fails-t…
Browse files Browse the repository at this point in the history
…rying-to-recreate-tables

[API] MAGETWO-35266: Update fails trying to recreate tables
  • Loading branch information
Tulika,Eugene(etulika) committed Mar 18, 2015
2 parents b456cd1 + 28cf7e4 commit fc05202
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 140 deletions.
36 changes: 36 additions & 0 deletions app/code/Magento/Eav/Model/EavCustomAttributeTypeLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface;

/**
* Class to locate types for Eav custom attributes
*/
class EavCustomAttributeTypeLocator implements CustomAttributeTypeLocatorInterface
{
/**
Expand All @@ -32,7 +35,22 @@ class EavCustomAttributeTypeLocator implements CustomAttributeTypeLocatorInterfa
*
* @param AttributeRepositoryInterface $attributeRepository
* @param array $serviceEntityTypeMap
* <pre>
* [
* 'ServiceInterfaceA' => 'EavEntityType1',
* 'ServiceInterfaceB' => 'EavEntityType2'
* ]
* </pre>
* @param array $serviceBackendModelDataInterfaceMap
* <pre>
* [
* 'ServiceInterfaceA' => ['BackendType1' => 'ServiceDataInterface1'],
* 'ServiceInterfaceB' => [
* 'BackendType2' => 'ServiceDataInterface2',
* 'BackendType3' => 'ServiceDataInterface3'
* ]
* ]
* </pre>
*/
public function __construct(
AttributeRepositoryInterface $attributeRepository,
Expand Down Expand Up @@ -69,4 +87,22 @@ public function getType($attributeCode, $serviceClass)

return $dataInterface;
}

/**
* {@inheritdoc}
*/
public function getAllServiceDataInterfaces()
{
$dataInterfaceArray = [];
if (!$this->serviceBackendModelDataInterfaceMap) {
return [];
} else {
foreach ($this->serviceBackendModelDataInterfaceMap as $serviceArray) {
foreach ($serviceArray as $dataInterface) {
$dataInterfaceArray[] = $dataInterface;
}
}
}
return $dataInterfaceArray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,26 @@ public function getTypeDataProvider()
]
];
}

public function testGetAllServiceDataInterfaceEmpty()
{
$this->eavCustomAttributeTypeLocator = new EavCustomAttributeTypeLocator($this->attributeRepository);
$this->assertEmpty($this->eavCustomAttributeTypeLocator->getAllServiceDataInterfaces());
}

public function testGetAllServiceDataInterface()
{
$serviceBackendModelDataInterfaceMapData = [
'ServiceA' => ['BackendA' => 'ServiceDataInterfaceA'],
'ServiceB' => ['BackendB' => 'ServiceDataInterfaceB', 'BackendC' => 'ServiceDataInterfaceC'],
'ServiceC' => ['BackendD' => 'ServiceDataInterfaceD']
];
$this->eavCustomAttributeTypeLocator = new EavCustomAttributeTypeLocator(
$this->attributeRepository, [], $serviceBackendModelDataInterfaceMapData
);
$this->assertEquals(
['ServiceDataInterfaceA', 'ServiceDataInterfaceB', 'ServiceDataInterfaceC', 'ServiceDataInterfaceD'],
$this->eavCustomAttributeTypeLocator->getAllServiceDataInterfaces()
);
}
}
12 changes: 6 additions & 6 deletions app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class Generator
protected $storeManager;

/**
* @var array
* @var \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface
*/
protected $customAttributeMapArray = null;
protected $customAttributeTypeLocator = null;

/**
* Initialize dependencies.
Expand All @@ -62,22 +62,22 @@ class Generator
* @param \Magento\Framework\App\Cache\Type\Webapi $cache
* @param \Magento\Framework\Reflection\TypeProcessor $typeProcessor
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Object $customAttributeMap
* @param \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface $customAttributeTypeLocator
*/
public function __construct(
\Magento\Webapi\Model\Soap\Config $apiConfig,
WsdlFactory $wsdlFactory,
\Magento\Framework\App\Cache\Type\Webapi $cache,
\Magento\Framework\Reflection\TypeProcessor $typeProcessor,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Object $customAttributeMap
\Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface $customAttributeTypeLocator
) {
$this->_apiConfig = $apiConfig;
$this->_wsdlFactory = $wsdlFactory;
$this->_cache = $cache;
$this->_typeProcessor = $typeProcessor;
$this->storeManager = $storeManager;
$this->customAttributeMapArray = array_values($customAttributeMap->getData());
$this->customAttributeTypeLocator = $customAttributeTypeLocator;
}

/**
Expand Down Expand Up @@ -178,7 +178,7 @@ protected function _generate($requestedServices, $endPointUrl)
*/
protected function addCustomAttributeTypes($wsdl)
{
foreach ($this->customAttributeMapArray as $customAttributeClass) {
foreach ($this->customAttributeTypeLocator->getAllServiceDataInterfaces() as $customAttributeClass) {
$typeName = $this->_typeProcessor->register($customAttributeClass);
$wsdl->addComplexType($typeName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Webapi\Model\Soap\Wsdl\Generator */
protected $_wsdlGenerator;

/** @var \Magento\Framework\Object */
protected $customAttributeMap;
/**
* @var \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $customAttributeTypeLocator = null;

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

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

$this->customAttributeMap = $objectManager->getObject('Magento\Framework\Object');
$this->customAttributeTypeLocator = $objectManager
->getObject('Magento\Eav\Model\EavCustomAttributeTypeLocator');

$this->_wsdlGenerator = $objectManager->getObject(
'Magento\Webapi\Model\Soap\Wsdl\Generator',
[
Expand All @@ -102,7 +106,7 @@ protected function setUp()
'cache' => $this->_cacheMock,
'typeProcessor' => $this->_typeProcessor,
'storeManagerMock' => $this->storeManagerMock,
'customAttributeMap' => $this->customAttributeMap
'customAttributeTypeLocator' => $this->customAttributeTypeLocator
]
);

Expand Down Expand Up @@ -196,7 +200,7 @@ public function testHandleWithException()
$this->_cacheMock,
$this->_typeProcessor,
$this->storeManagerMock,
$this->customAttributeMap
$this->customAttributeTypeLocator
]
)->getMock();

Expand Down
5 changes: 0 additions & 5 deletions app/code/Magento/Webapi/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Webapi</argument>
</arguments>
</type>
<type name="Magento\Webapi\Model\Soap\Wsdl\Generator">
<arguments>
<argument name="customAttributeMap" xsi:type="object">CustomAttributeMap</argument>
</arguments>
</type>
<type name="Magento\Integration\Model\ConfigBasedIntegrationManager">
<plugin name="webapiSetup" type="Magento\Webapi\Model\Plugin\Manager" />
</type>
Expand Down
15 changes: 14 additions & 1 deletion dev/tests/api-functional/_files/Magento/TestModuleMSC/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@
<argument name="resource" xsi:type="object">Magento\TestModuleMSC\Model\Resource\Item</argument>
</arguments>
</type>
<virtualType name="CustomAttributeMap" type="Magento\Framework\Object">
<virtualType name="CustomAttributeMap" type="Magento\Framework\Object">
<arguments>
<argument name="data" xsi:type="array">
<item name="customAttributeDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
<item name="customAttributeNestedDataObjectInterface" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\Eav\Model\EavCustomAttributeTypeLocator">
<arguments>
<argument name="serviceEntityTypeMap" xsi:type="array">
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="string">1</item>
</argument>
<argument name="serviceBackendModelDataInterfaceMap" xsi:type="array">
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="array">
<item name="Magento\Sample\BackendType1" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface</item>
<item name="Magento\Sample\BackendType2" xsi:type="string">Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface</item>
</item>
</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ interface CustomAttributeTypeLocatorInterface
* @return string|null
*/
public function getType($attributeCode, $serviceClass);

/**
* Get list of all Data Interface corresponding to complex custom attribute types
*
* @return string[] array of Data Interface class names
*/
public function getAllServiceDataInterfaces();
}
Loading

0 comments on commit fc05202

Please sign in to comment.