Skip to content

Commit 3213f94

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-46014
2 parents 66e6ad6 + a54767e commit 3213f94

File tree

26 files changed

+614
-166
lines changed

26 files changed

+614
-166
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ public function afterDelete()
824824
*/
825825
public function __sleep()
826826
{
827+
$this->unsetData('entity_type');
827828
return array_diff(
828829
parent::__sleep(),
829830
['_indexerEavProcessor', '_productFlatIndexerProcessor', '_productFlatIndexerHelper', 'attrLockValidator']

app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Magento\Catalog\Test\Unit\Model\Entity;
1010

1111
use Magento\Catalog\Model\Entity\Attribute;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1213

1314
/**
1415
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -196,25 +197,32 @@ protected function setUp()
196197
->method('getEventDispatcher')
197198
->willReturn($this->eventDispatcher);
198199

199-
$this->attribute = new Attribute(
200-
$this->contextMock,
201-
$this->registryMock,
202-
$this->extensionAttributesFactory,
203-
$this->attributeValueFactoryMock,
204-
$this->configMock,
205-
$this->typeFactoryMock,
206-
$this->storeManagerMock,
207-
$this->helperMock,
208-
$this->universalFactoryMock,
209-
$this->attributeOptionFactoryMock,
210-
$this->dataObjectProcessorMock,
211-
$this->dataObjectHelperMock,
212-
$this->timezoneMock,
213-
$this->reservedAttributeListMock,
214-
$this->resolverMock,
215-
$this->dateTimeFormatter,
216-
$this->lockValidatorMock,
217-
$this->resourceMock
200+
$attributeCacheMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeCache::class)
201+
->disableOriginalConstructor()
202+
->getMock();
203+
$objectManagerHelper = new ObjectManagerHelper($this);
204+
$this->attribute = $objectManagerHelper->getObject(
205+
Attribute::class,
206+
[
207+
'context' => $this->contextMock,
208+
'registry' => $this->registryMock,
209+
'extensionFactory' => $this->extensionAttributesFactory,
210+
'attributeValueFactory' => $this->attributeValueFactoryMock,
211+
'eavConfig' => $this->configMock,
212+
'typeFactory' => $this->typeFactoryMock,
213+
'storeManager' => $this->storeManagerMock,
214+
'helper' => $this->helperMock,
215+
'universalFactory' => $this->universalFactoryMock,
216+
'attributeOptionFactory' => $this->attributeOptionFactoryMock,
217+
'dataObjectProcessor' => $this->dataObjectProcessorMock,
218+
'dataObjectHelper' => $this->dataObjectHelperMock,
219+
'timezone' => $this->timezoneMock,
220+
'reservedAttributeList' => $this->reservedAttributeListMock,
221+
'resolver' => $this->resolverMock,
222+
'dateTimeFormatter' => $this->dateTimeFormatter,
223+
'resource' => $this->resourceMock,
224+
'attributeCache' => $attributeCacheMock
225+
]
218226
);
219227
}
220228

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Eav/AttributeTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ protected function setUp()
101101
->method('getConnection')
102102
->will($this->returnValue($dbAdapterMock));
103103

104+
$attributeCacheMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeCache::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
104108
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
105109
$this->_model = $objectManager->getObject(
106110
'Magento\Catalog\Model\ResourceModel\Eav\Attribute',
@@ -110,7 +114,8 @@ protected function setUp()
110114
'indexerEavProcessor' => $this->_eavProcessor,
111115
'resource' => $this->resourceMock,
112116
'data' => ['id' => 1],
113-
'eavConfig' => $this->eavConfigMock
117+
'eavConfig' => $this->eavConfigMock,
118+
'attributeCache' => $attributeCacheMock
114119
]
115120
);
116121
}

app/code/Magento/Customer/Model/Attribute.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,26 @@ public function canBeFilterableInGrid()
181181
return $this->getData('is_filterable_in_grid')
182182
&& in_array($this->getFrontendInput(), ['text', 'date', 'select', 'boolean']);
183183
}
184+
185+
/**
186+
* @inheritdoc
187+
*/
188+
public function __sleep()
189+
{
190+
$this->unsetData('entity_type');
191+
return array_diff(
192+
parent::__sleep(),
193+
['indexerRegistry', '_website']
194+
);
195+
}
196+
197+
/**
198+
* @inheritdoc
199+
*/
200+
public function __wakeup()
201+
{
202+
parent::__wakeup();
203+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
204+
$this->indexerRegistry = $objectManager->get(\Magento\Framework\Indexer\IndexerRegistry::class);
205+
}
184206
}

app/code/Magento/Customer/Model/Metadata/AddressCachedMetadata.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
class AddressCachedMetadata extends CachedMetadata implements AddressMetadataInterface
1515
{
16+
/**
17+
* @var string
18+
*/
19+
protected $entityType = 'customer_address';
20+
1621
/**
1722
* Initialize dependencies.
1823
*

app/code/Magento/Customer/Model/Metadata/CachedMetadata.php

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Customer\Model\Metadata;
88

99
use Magento\Customer\Api\MetadataInterface;
10+
use Magento\Eav\Model\Entity\AttributeCache;
11+
use Magento\Framework\App\ObjectManager;
1012

1113
/**
1214
* Cached attribute metadata service
@@ -16,29 +18,19 @@ class CachedMetadata implements MetadataInterface
1618
const CACHE_SEPARATOR = ';';
1719

1820
/**
19-
* @var MetadataInterface
20-
*/
21-
protected $metadata;
22-
23-
/**
24-
* @var array
21+
* @var string
2522
*/
26-
protected $attributeMetadataCache = [];
23+
protected $entityType = 'none';
2724

2825
/**
29-
* @var array
26+
* @var AttributeCache
3027
*/
31-
protected $attributesCache = [];
28+
private $cache;
3229

3330
/**
34-
* @var \Magento\Customer\Api\Data\AttributeMetadataInterface[]
35-
*/
36-
protected $allAttributeMetadataCache = null;
37-
38-
/**
39-
* @var \Magento\Customer\Api\Data\AttributeMetadataInterface[]
31+
* @var MetadataInterface
4032
*/
41-
protected $customAttributesMetadataCache = null;
33+
protected $metadata;
4234

4335
/**
4436
* Initialize dependencies.
@@ -55,56 +47,67 @@ public function __construct(MetadataInterface $metadata)
5547
*/
5648
public function getAttributes($formCode)
5749
{
58-
$key = $formCode;
59-
if (isset($this->attributesCache[$key])) {
60-
return $this->attributesCache[$key];
50+
$attributes = $this->getCache()->getAttributes($this->entityType, $formCode);
51+
if ($attributes !== false) {
52+
return $attributes;
6153
}
62-
63-
$value = $this->metadata->getAttributes($formCode);
64-
$this->attributesCache[$key] = $value;
65-
66-
return $value;
54+
$attributes = $this->metadata->getAttributes($formCode);
55+
$this->getCache()->saveAttributes($this->entityType, $attributes, $formCode);
56+
return $attributes;
6757
}
6858

6959
/**
7060
* {@inheritdoc}
7161
*/
7262
public function getAttributeMetadata($attributeCode)
7363
{
74-
$key = $attributeCode;
75-
if (isset($this->attributeMetadataCache[$key])) {
76-
return $this->attributeMetadataCache[$key];
64+
$metadata = $this->getCache()->getAttributes($this->entityType, $attributeCode);
65+
if ($metadata) {
66+
return $metadata;
7767
}
78-
79-
$value = $this->metadata->getAttributeMetadata($attributeCode);
80-
$this->attributeMetadataCache[$key] = $value;
81-
82-
return $value;
68+
$metadata = $this->metadata->getAttributeMetadata($attributeCode);
69+
$this->getCache()->saveAttributes($this->entityType, $metadata, $attributeCode);
70+
return $metadata;
8371
}
8472

8573
/**
8674
* {@inheritdoc}
8775
*/
8876
public function getAllAttributesMetadata()
8977
{
90-
if ($this->allAttributeMetadataCache !== null) {
91-
return $this->allAttributeMetadataCache;
78+
$attributes = $this->getCache()->getAttributes($this->entityType, 'all');
79+
if ($attributes !== false) {
80+
return $attributes;
9281
}
93-
94-
$this->allAttributeMetadataCache = $this->metadata->getAllAttributesMetadata();
95-
return $this->allAttributeMetadataCache;
82+
$attributes = $this->metadata->getAllAttributesMetadata();
83+
$this->getCache()->saveAttributes($this->entityType, $attributes, 'all');
84+
return $attributes;
9685
}
9786

9887
/**
9988
* {@inheritdoc}
10089
*/
10190
public function getCustomAttributesMetadata($dataObjectClassName = null)
10291
{
103-
if ($this->customAttributesMetadataCache !== null) {
104-
return $this->customAttributesMetadataCache;
92+
$attributes = $this->getCache()->getAttributes($this->entityType, 'custom');
93+
if ($attributes !== false) {
94+
return $attributes;
10595
}
96+
$attributes = $this->metadata->getCustomAttributesMetadata();
97+
$this->getCache()->saveAttributes($this->entityType, $attributes, 'custom');
98+
return $attributes;
99+
}
106100

107-
$this->customAttributesMetadataCache = $this->metadata->getCustomAttributesMetadata();
108-
return $this->customAttributesMetadataCache;
101+
/**
102+
* @return AttributeCache
103+
* @deprecated
104+
*/
105+
private function getCache()
106+
{
107+
if (!$this->cache) {
108+
$this->cache = ObjectManager::getInstance()->get(AttributeCache::class);
109+
}
110+
111+
return $this->cache;
109112
}
110113
}

app/code/Magento/Customer/Model/Metadata/CustomerCachedMetadata.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
class CustomerCachedMetadata extends CachedMetadata implements CustomerMetadataInterface
1515
{
16+
/**
17+
* @var string
18+
*/
19+
protected $entityType = 'customer';
20+
1621
/**
1722
* Initialize dependencies.
1823
*

app/code/Magento/Customer/Test/Unit/Model/AttributeTest.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Customer\Model\Customer;
1313
use Magento\Eav\Api\Data\AttributeInterface;
1414
use Magento\Framework\Indexer\IndexerInterface;
15-
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1616
/**
1717
* @SuppressWarnings(PHPMD.TooManyFields)
1818
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -124,6 +124,11 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
124124
*/
125125
private $dateTimeFormatter;
126126

127+
/**
128+
* @var \PHPUnit_Framework_MockObject_MockObject
129+
*/
130+
private $attributeCacheMock;
131+
127132
/**
128133
* Test method
129134
*/
@@ -193,26 +198,33 @@ protected function setUp()
193198
$this->indexerRegistryMock = $this->getMockBuilder('Magento\Framework\Indexer\IndexerRegistry')
194199
->disableOriginalConstructor()
195200
->getMock();
196-
197-
$this->attribute = new Attribute(
198-
$this->contextMock,
199-
$this->registryMock,
200-
$this->extensionAttributesFactory,
201-
$this->attributeValueFactoryMock,
202-
$this->configMock,
203-
$this->typeFactoryMock,
204-
$this->storeManagerMock,
205-
$this->helperMock,
206-
$this->universalFactoryMock,
207-
$this->attributeOptionFactoryMock,
208-
$this->dataObjectProcessorMock,
209-
$this->dataObjectHelperMock,
210-
$this->timezoneMock,
211-
$this->reservedAttributeListMock,
212-
$this->resolverMock,
213-
$this->dateTimeFormatter,
214-
$this->indexerRegistryMock,
215-
$this->resourceMock
201+
$this->attributeCacheMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeCache::class)
202+
->disableOriginalConstructor()
203+
->getMock();
204+
$objectManagerHelper = new ObjectManagerHelper($this);
205+
$this->attribute = $objectManagerHelper->getObject(
206+
Attribute::class,
207+
[
208+
'context' => $this->contextMock,
209+
'registry' => $this->registryMock,
210+
'extensionFactory' => $this->extensionAttributesFactory,
211+
'attributeValueFactory' => $this->attributeValueFactoryMock,
212+
'eavConfig' => $this->configMock,
213+
'typeFactory' => $this->typeFactoryMock,
214+
'storeManager' => $this->storeManagerMock,
215+
'helper' => $this->helperMock,
216+
'universalFactory' => $this->universalFactoryMock,
217+
'attributeOptionFactory' => $this->attributeOptionFactoryMock,
218+
'dataObjectProcessor' => $this->dataObjectProcessorMock,
219+
'dataObjectHelper' => $this->dataObjectHelperMock,
220+
'timezone' => $this->timezoneMock,
221+
'reservedAttributeList' => $this->reservedAttributeListMock,
222+
'resolver' => $this->resolverMock,
223+
'dateTimeFormatter' => $this->dateTimeFormatter,
224+
'indexerRegistry' => $this->indexerRegistryMock,
225+
'resource' => $this->resourceMock,
226+
'attributeCache' => $this->attributeCacheMock,
227+
]
216228
);
217229
}
218230

app/code/Magento/Directory/Model/Currency/Import/YahooFinance.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ class YahooFinance extends \Magento\Directory\Model\Currency\Import\AbstractImpo
1515
*
1616
* @var string
1717
*/
18-
private $currencyConverterUrl = 'http://query.yahooapis.com/v1/public/yql?format=json&q={{YQL_STRING}}'
19-
.'&env=store://datatables.org/alltableswithkeys';
18+
// @codingStandardsIgnoreStart
19+
private $currencyConverterUrl = 'http://query.yahooapis.com/v1/public/yql?format=json&q={{YQL_STRING}}&env=store://datatables.org/alltableswithkeys';
20+
// @codingStandardsIgnoreEnd
2021

2122
/**
2223
* Config path for service timeout

0 commit comments

Comments
 (0)