Skip to content

Commit

Permalink
Merge pull request #1101 from magento-tsg/2.1.8-develop-pr8
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.1 (pr8) (2.1.8)
  • Loading branch information
Volodymyr Klymenko authored May 15, 2017
2 parents 0ccf4c8 + e01c878 commit 0acbc57
Show file tree
Hide file tree
Showing 33 changed files with 883 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
use Magento\Backend\Block\Widget\Form;
use Magento\Backend\Block\Widget\Form\Generic;

/**
* Class Content
*
* @deprecated
* @see \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav
*/
class Content extends Generic
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ protected function processDeletedImages($product, array &$images)
if (!empty($image['removed'])) {
if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) {
$recordsToDelete[] = $image['value_id'];
$filesToDelete[] = ltrim($image['file'], '/');
// only delete physical files if they are not used by any other products
if (!($this->resourceModel->countImageUses($image['file']) > 1)) {
$filesToDelete[] = ltrim($image['file'], '/');
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions app/code/Magento/Catalog/Model/ResourceModel/Product/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,22 @@ public function getProductImages($product, $storeIds)

return $this->getConnection()->fetchAll($select);
}

/**
* Counts uses of this image.
*
* @param string $image
* @return int
*/
public function countImageUses($image)
{
$select = $this->getConnection()->select()
->from(
[$this->getMainTableAlias() => $this->getMainTable()],
'count(*)'
)
->where('value = ?', $image);

return $this->getConnection()->fetchOne($select);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function setUp()
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->connection = $this->getMock(
'Magento\Framework\DB\Adapter\Pdo\Mysql',
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
[],
[],
'',
Expand All @@ -63,7 +63,7 @@ protected function setUp()
->method('setCacheAdapter');

$metadata = $this->getMock(
'Magento\Framework\EntityManager\EntityMetadata',
\Magento\Framework\EntityManager\EntityMetadata::class,
[],
[],
'',
Expand All @@ -77,29 +77,35 @@ protected function setUp()
->willReturn($this->connection);

$metadataPool = $this->getMock(
'Magento\Framework\EntityManager\MetadataPool',
\Magento\Framework\EntityManager\MetadataPool::class,
[],
[],
'',
false
);
$metadataPool->expects($this->once())
->method('getMetadata')
->with('Magento\Catalog\Api\Data\ProductInterface')
->with(\Magento\Catalog\Api\Data\ProductInterface::class)
->willReturn($metadata);

$resource = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
$resource = $this->getMock(\Magento\Framework\App\ResourceConnection::class, [], [], '', false);
$resource->expects($this->any())->method('getTableName')->willReturn('table');
$this->resource = $objectManager->getObject(
'Magento\Catalog\Model\ResourceModel\Product\Gallery',
\Magento\Catalog\Model\ResourceModel\Product\Gallery::class,
[
'metadataPool' => $metadataPool,
'resource' => $resource
]
);
$this->product = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
$this->select = $this->getMock('Magento\Framework\DB\Select', [], [], '', false);
$this->attribute = $this->getMock('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', [], [], '', false);
$this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
$this->select = $this->getMock(\Magento\Framework\DB\Select::class, [], [], '', false);
$this->attribute = $this->getMock(
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,
[],
[],
'',
false
);
}

public function testLoadDataFromTableByValueId()
Expand Down Expand Up @@ -437,4 +443,32 @@ public function testDeleteGalleryValueInStore()

$this->resource->deleteGalleryValueInStore($valueId, $entityId, $storeId);
}

public function testCountImageUses()
{
$results = [
[
'value_id' => '1',
'attribute_id' => 90,
'value' => '/d/o/download_7.jpg',
'media_type' => 'image',
'disabled' => '0',
],
];

$this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
$this->select->expects($this->at(0))
->method('from')
->with(['main' => 'table'], 'count(*)')
->willReturnSelf();
$this->select->expects($this->at(1))
->method('where')
->with('value = ?', 1)
->willReturnSelf();
$this->connection->expects($this->once())
->method('fetchOne')
->with($this->select)
->willReturn(count($results));
$this->assertEquals($this->resource->countImageUses(1), count($results));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,10 @@ private function customizeWysiwyg(ProductAttributeInterface $attribute, array $m
$meta['arguments']['data']['config']['wysiwyg'] = true;
$meta['arguments']['data']['config']['wysiwygConfigData'] = [
'add_variables' => false,
'add_widgets' => false
'add_widgets' => false,
'add_directives' => true,
'use_container' => true,
'container_class' => 'hor-scroll',
];

return $meta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/

define([
'underscore',
'Magento_Ui/js/form/element/textarea'
], function (Textarea) {
], function (_, Textarea) {
'use strict';

return Textarea.extend({
Expand Down Expand Up @@ -123,24 +124,21 @@ define([
* Update field value, if it's allowed
*/
updateValue: function () {
var str = this.mask,
var str = this.mask || '',
nonEmptyValueFlag = false,
placeholder,
property,
tmpElement;

if (!this.allowImport) {
return;
}

for (property in this.values) {
if (this.values.hasOwnProperty(property)) {
placeholder = '';
placeholder = placeholder.concat('{{', property, '}}');
str = str.replace(placeholder, this.values[property]);
nonEmptyValueFlag = nonEmptyValueFlag || !!this.values[property];
}
if (str) {
_.each(this.values, function (propertyValue, propertyName) {
str = str.replace('{{' + propertyName + '}}', propertyValue);
nonEmptyValueFlag = nonEmptyValueFlag || !!propertyValue;
});
}

// strip tags
tmpElement = document.createElement('div');
tmpElement.innerHTML = str;
Expand Down
Loading

0 comments on commit 0acbc57

Please sign in to comment.