Skip to content

Commit 0acbc57

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #1101 from magento-tsg/2.1.8-develop-pr8
[TSG] Backporting for 2.1 (pr8) (2.1.8)
2 parents 0ccf4c8 + e01c878 commit 0acbc57

File tree

33 files changed

+883
-273
lines changed

33 files changed

+883
-273
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Helper/Form/Wysiwyg/Content.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
use Magento\Backend\Block\Widget\Form;
1515
use Magento\Backend\Block\Widget\Form\Generic;
1616

17+
/**
18+
* Class Content
19+
*
20+
* @deprecated
21+
* @see \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav
22+
*/
1723
class Content extends Generic
1824
{
1925
/**

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ protected function processDeletedImages($product, array &$images)
2929
if (!empty($image['removed'])) {
3030
if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) {
3131
$recordsToDelete[] = $image['value_id'];
32-
$filesToDelete[] = ltrim($image['file'], '/');
32+
// only delete physical files if they are not used by any other products
33+
if (!($this->resourceModel->countImageUses($image['file']) > 1)) {
34+
$filesToDelete[] = ltrim($image['file'], '/');
35+
}
3336
}
3437
}
3538
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,4 +449,22 @@ public function getProductImages($product, $storeIds)
449449

450450
return $this->getConnection()->fetchAll($select);
451451
}
452+
453+
/**
454+
* Counts uses of this image.
455+
*
456+
* @param string $image
457+
* @return int
458+
*/
459+
public function countImageUses($image)
460+
{
461+
$select = $this->getConnection()->select()
462+
->from(
463+
[$this->getMainTableAlias() => $this->getMainTable()],
464+
'count(*)'
465+
)
466+
->where('value = ?', $image);
467+
468+
return $this->getConnection()->fetchOne($select);
469+
}
452470
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/GalleryTest.php

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function setUp()
5353
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
5454

5555
$this->connection = $this->getMock(
56-
'Magento\Framework\DB\Adapter\Pdo\Mysql',
56+
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
5757
[],
5858
[],
5959
'',
@@ -63,7 +63,7 @@ protected function setUp()
6363
->method('setCacheAdapter');
6464

6565
$metadata = $this->getMock(
66-
'Magento\Framework\EntityManager\EntityMetadata',
66+
\Magento\Framework\EntityManager\EntityMetadata::class,
6767
[],
6868
[],
6969
'',
@@ -77,29 +77,35 @@ protected function setUp()
7777
->willReturn($this->connection);
7878

7979
$metadataPool = $this->getMock(
80-
'Magento\Framework\EntityManager\MetadataPool',
80+
\Magento\Framework\EntityManager\MetadataPool::class,
8181
[],
8282
[],
8383
'',
8484
false
8585
);
8686
$metadataPool->expects($this->once())
8787
->method('getMetadata')
88-
->with('Magento\Catalog\Api\Data\ProductInterface')
88+
->with(\Magento\Catalog\Api\Data\ProductInterface::class)
8989
->willReturn($metadata);
9090

91-
$resource = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
91+
$resource = $this->getMock(\Magento\Framework\App\ResourceConnection::class, [], [], '', false);
9292
$resource->expects($this->any())->method('getTableName')->willReturn('table');
9393
$this->resource = $objectManager->getObject(
94-
'Magento\Catalog\Model\ResourceModel\Product\Gallery',
94+
\Magento\Catalog\Model\ResourceModel\Product\Gallery::class,
9595
[
9696
'metadataPool' => $metadataPool,
9797
'resource' => $resource
9898
]
9999
);
100-
$this->product = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
101-
$this->select = $this->getMock('Magento\Framework\DB\Select', [], [], '', false);
102-
$this->attribute = $this->getMock('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', [], [], '', false);
100+
$this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
101+
$this->select = $this->getMock(\Magento\Framework\DB\Select::class, [], [], '', false);
102+
$this->attribute = $this->getMock(
103+
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,
104+
[],
105+
[],
106+
'',
107+
false
108+
);
103109
}
104110

105111
public function testLoadDataFromTableByValueId()
@@ -437,4 +443,32 @@ public function testDeleteGalleryValueInStore()
437443

438444
$this->resource->deleteGalleryValueInStore($valueId, $entityId, $storeId);
439445
}
446+
447+
public function testCountImageUses()
448+
{
449+
$results = [
450+
[
451+
'value_id' => '1',
452+
'attribute_id' => 90,
453+
'value' => '/d/o/download_7.jpg',
454+
'media_type' => 'image',
455+
'disabled' => '0',
456+
],
457+
];
458+
459+
$this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
460+
$this->select->expects($this->at(0))
461+
->method('from')
462+
->with(['main' => 'table'], 'count(*)')
463+
->willReturnSelf();
464+
$this->select->expects($this->at(1))
465+
->method('where')
466+
->with('value = ?', 1)
467+
->willReturnSelf();
468+
$this->connection->expects($this->once())
469+
->method('fetchOne')
470+
->with($this->select)
471+
->willReturn(count($results));
472+
$this->assertEquals($this->resource->countImageUses(1), count($results));
473+
}
440474
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,10 @@ private function customizeWysiwyg(ProductAttributeInterface $attribute, array $m
745745
$meta['arguments']['data']['config']['wysiwyg'] = true;
746746
$meta['arguments']['data']['config']['wysiwygConfigData'] = [
747747
'add_variables' => false,
748-
'add_widgets' => false
748+
'add_widgets' => false,
749+
'add_directives' => true,
750+
'use_container' => true,
751+
'container_class' => 'hor-scroll',
749752
];
750753

751754
return $meta;

app/code/Magento/Catalog/view/adminhtml/web/js/components/import-handler.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*/
55

66
define([
7+
'underscore',
78
'Magento_Ui/js/form/element/textarea'
8-
], function (Textarea) {
9+
], function (_, Textarea) {
910
'use strict';
1011

1112
return Textarea.extend({
@@ -123,24 +124,21 @@ define([
123124
* Update field value, if it's allowed
124125
*/
125126
updateValue: function () {
126-
var str = this.mask,
127+
var str = this.mask || '',
127128
nonEmptyValueFlag = false,
128-
placeholder,
129-
property,
130129
tmpElement;
131130

132131
if (!this.allowImport) {
133132
return;
134133
}
135134

136-
for (property in this.values) {
137-
if (this.values.hasOwnProperty(property)) {
138-
placeholder = '';
139-
placeholder = placeholder.concat('{{', property, '}}');
140-
str = str.replace(placeholder, this.values[property]);
141-
nonEmptyValueFlag = nonEmptyValueFlag || !!this.values[property];
142-
}
135+
if (str) {
136+
_.each(this.values, function (propertyValue, propertyName) {
137+
str = str.replace('{{' + propertyName + '}}', propertyValue);
138+
nonEmptyValueFlag = nonEmptyValueFlag || !!propertyValue;
139+
});
143140
}
141+
144142
// strip tags
145143
tmpElement = document.createElement('div');
146144
tmpElement.innerHTML = str;

0 commit comments

Comments
 (0)