Skip to content

Commit df0b57f

Browse files
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-45775
2 parents 6b2d339 + dbcb0cd commit df0b57f

File tree

73 files changed

+11182
-8831
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+11182
-8831
lines changed

app/code/Magento/Catalog/Block/Product/View.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public function getWishlistOptions()
127127
*/
128128
protected function _prepareLayout()
129129
{
130-
$this->getLayout()->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);
131130
$product = $this->getProduct();
132131
if (!$product) {
133132
return parent::_prepareLayout();

app/code/Magento/Catalog/Model/Category.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,15 +1135,19 @@ public function afterDeleteCommit()
11351135
*/
11361136
public function getIdentities()
11371137
{
1138-
$identities = [
1139-
self::CACHE_TAG . '_' . $this->getId(),
1140-
];
1141-
if (!$this->getId() || $this->hasDataChanges()
1142-
|| $this->isDeleted() || $this->dataHasChangedFor(self::KEY_INCLUDE_IN_MENU)
1143-
) {
1144-
$identities[] = self::CACHE_TAG;
1145-
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
1138+
$identities = [];
1139+
if ($this->getId()) {
1140+
$identities[] = self::CACHE_TAG . '_' . $this->getId();
1141+
1142+
if ($this->hasDataChanges() || $this->isDeleted() || $this->dataHasChangedFor(self::KEY_INCLUDE_IN_MENU)) {
1143+
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
1144+
}
1145+
1146+
if ($this->isObjectNew()) {
1147+
$identities[] = self::CACHE_TAG;
1148+
}
11461149
}
1150+
11471151
return $identities;
11481152
}
11491153

app/code/Magento/Catalog/Model/Product.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,12 @@ protected function _afterLoad()
10651065
*/
10661066
public function cleanCache()
10671067
{
1068-
$this->_cacheManager->clean('catalog_product_' . $this->getId());
1068+
if ($this->getId()) {
1069+
$this->_cacheManager->clean(
1070+
self::CACHE_TAG . '_' . $this->getId()
1071+
);
1072+
}
1073+
10691074
return $this;
10701075
}
10711076

@@ -2287,7 +2292,12 @@ public function getImage()
22872292
*/
22882293
public function getIdentities()
22892294
{
2290-
$identities = [self::CACHE_TAG . '_' . $this->getId()];
2295+
$identities = [];
2296+
2297+
if ($this->getId()) {
2298+
$identities[] = self::CACHE_TAG . '_' . $this->getId();
2299+
}
2300+
22912301
if ($this->getIsChangedCategories()) {
22922302
foreach ($this->getAffectedCategoryIds() as $categoryId) {
22932303
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
@@ -2299,6 +2309,7 @@ public function getIdentities()
22992309
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
23002310
}
23012311
}
2312+
23022313
if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
23032314
$identities[] = self::CACHE_TAG;
23042315
}
@@ -2718,4 +2729,18 @@ public function setStockData($stockData)
27182729
$this->setData('stock_data', $stockData);
27192730
return $this;
27202731
}
2732+
2733+
/**
2734+
* {@inheritDoc}
2735+
*/
2736+
public function getCacheTags()
2737+
{
2738+
//Preferring individual tags over broad ones.
2739+
$individualTags = $this->getIdentities();
2740+
if ($individualTags) {
2741+
return $individualTags;
2742+
}
2743+
2744+
return parent::getCacheTags();
2745+
}
27212746
}

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,13 @@ protected function processNewAndExistingImages($product, array &$images)
241241
if (empty($image['removed'])) {
242242
$data = $this->processNewImage($product, $image);
243243

244-
$this->resourceModel->deleteGalleryValueInStore(
245-
$image['value_id'],
246-
$product->getData($this->metadata->getLinkField()),
247-
$product->getStoreId()
248-
);
249-
244+
if (!$product->isObjectNew()) {
245+
$this->resourceModel->deleteGalleryValueInStore(
246+
$image['value_id'],
247+
$product->getData($this->metadata->getLinkField()),
248+
$product->getStoreId()
249+
);
250+
}
250251
// Add per store labels, position, disabled
251252
$data['value_id'] = $image['value_id'];
252253
$data['label'] = isset($image['label']) ? $image['label'] : '';

app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ protected function _prepareLoadSelect(array $selects)
177177
protected function _saveAttributeValue($object, $attribute, $value)
178178
{
179179
$connection = $this->getConnection();
180-
$storeId = (int) $this->_storeManager->getStore($object->getStoreId())->getId();
180+
$hasSingleStore = $this->_storeManager->hasSingleStore();
181+
$storeId = $hasSingleStore
182+
? $this->getDefaultStoreId()
183+
: (int) $this->_storeManager->getStore($object->getStoreId())->getId();
181184
$table = $attribute->getBackend()->getTable();
182185

183186
/**
@@ -186,15 +189,18 @@ protected function _saveAttributeValue($object, $attribute, $value)
186189
* In this case we clear all not default values
187190
*/
188191
$entityIdField = $this->getLinkField();
189-
if ($this->_storeManager->hasSingleStore()) {
190-
$storeId = $this->getDefaultStoreId();
192+
$conditions = [
193+
'attribute_id = ?' => $attribute->getAttributeId(),
194+
"{$entityIdField} = ?" => $object->getData($entityIdField),
195+
'store_id <> ?' => $storeId
196+
];
197+
if ($hasSingleStore
198+
&& !$object->isObjectNew()
199+
&& $this->isAttributePresentForNonDefaultStore($attribute, $conditions)
200+
) {
191201
$connection->delete(
192202
$table,
193-
[
194-
'attribute_id = ?' => $attribute->getAttributeId(),
195-
"{$entityIdField} = ?" => $object->getData($entityIdField),
196-
'store_id <> ?' => $storeId
197-
]
203+
$conditions
198204
);
199205
}
200206

@@ -233,6 +239,27 @@ protected function _saveAttributeValue($object, $attribute, $value)
233239
return $this;
234240
}
235241

242+
/**
243+
* Check if attribute present for non default Store View.
244+
* Prevent "delete" query locking in a case when nothing to delete
245+
*
246+
* @param AbstractAttribute $attribute
247+
* @param array $conditions
248+
*
249+
* @return boolean
250+
*/
251+
private function isAttributePresentForNonDefaultStore($attribute, $conditions)
252+
{
253+
$connection = $this->getConnection();
254+
$select = $connection->select()->from($attribute->getBackend()->getTable());
255+
foreach ($conditions as $condition => $conditionValue) {
256+
$select->where($condition, $conditionValue);
257+
}
258+
$select->limit(1);
259+
260+
return !empty($connection->fetchRow($select));
261+
}
262+
236263
/**
237264
* Insert entity attribute value
238265
*

app/code/Magento/Catalog/Model/ResourceModel/Product/CategoryLink.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ public function saveCategoryLinks(ProductInterface $product, array $categoryLink
8383
$insertUpdate = $this->processCategoryLinks($categoryLinks, $oldCategoryLinks);
8484
$deleteUpdate = $this->processCategoryLinks($oldCategoryLinks, $categoryLinks);
8585

86-
list($delete, $insert) = $this->analyseUpdatedLinks($deleteUpdate, $insertUpdate);
86+
list($delete, $insert, $update) = $this->analyseUpdatedLinks($deleteUpdate, $insertUpdate);
8787

8888
return array_merge(
89-
$this->updateCategoryLinks($product, $insert),
90-
$this->deleteCategoryLinks($product, $delete)
89+
$this->deleteCategoryLinks($product, $delete),
90+
$this->updateCategoryLinks($product, $insert, true),
91+
$this->updateCategoryLinks($product, $update)
9192
);
9293
}
9394

@@ -133,16 +134,15 @@ private function processCategoryLinks($newCategoryPositions, &$oldCategoryPositi
133134
/**
134135
* @param ProductInterface $product
135136
* @param array $insertLinks
137+
* @param bool $insert
136138
* @return array
137139
*/
138-
private function updateCategoryLinks(ProductInterface $product, array $insertLinks)
140+
private function updateCategoryLinks(ProductInterface $product, array $insertLinks, $insert = false)
139141
{
140142
if (empty($insertLinks)) {
141143
return [];
142144
}
143145

144-
$connection = $this->resourceConnection->getConnection();
145-
146146
$data = [];
147147
foreach ($insertLinks as $categoryLink) {
148148
$data[] = [
@@ -153,11 +153,22 @@ private function updateCategoryLinks(ProductInterface $product, array $insertLin
153153
}
154154

155155
if ($data) {
156-
$connection->insertOnDuplicate(
157-
$this->getCategoryLinkMetadata()->getEntityTable(),
158-
$data,
159-
['position']
160-
);
156+
$connection = $this->resourceConnection->getConnection();
157+
if ($insert) {
158+
$connection->insertArray(
159+
$this->getCategoryLinkMetadata()->getEntityTable(),
160+
array_keys($data[0]),
161+
$data,
162+
\Magento\Framework\DB\Adapter\AdapterInterface::INSERT_IGNORE
163+
);
164+
} else {
165+
// for mass update category links with constraint by unique key use insert on duplicate statement
166+
$connection->insertOnDuplicate(
167+
$this->getCategoryLinkMetadata()->getEntityTable(),
168+
$data,
169+
['position']
170+
);
171+
}
161172
}
162173

163174
return array_column($insertLinks, 'category_id');
@@ -215,7 +226,7 @@ private function verifyCategoryLinks(array $links)
215226
}
216227

217228
/**
218-
* Analyse category links for update or/and delete
229+
* Analyse category links for update or/and delete. Return array of links for delete, insert and update
219230
*
220231
* @param array $deleteUpdate
221232
* @param array $insertUpdate
@@ -226,8 +237,7 @@ private function analyseUpdatedLinks($deleteUpdate, $insertUpdate)
226237
$delete = $deleteUpdate['changed'] ?: [];
227238
$insert = $insertUpdate['changed'] ?: [];
228239
$insert = array_merge_recursive($insert, $deleteUpdate['updated']);
229-
$insert = array_merge_recursive($insert, $insertUpdate['updated']);
230240

231-
return [$delete, $insert];
241+
return [$delete, $insert, $insertUpdate['updated']];
232242
}
233243
}

0 commit comments

Comments
 (0)