Skip to content

Commit d403ec9

Browse files
Merge pull request #583 from magento-falcons/MAGETWO-60647
Fixed issues: - MAGETWO-60647: Delivery of bug fixes for Sample Data and Import/Export - MAGETWO-56787: [GITHUB][PR] Added call to action to compile command error #4134 - MAGETWO-56786: [GITHUB][PR] Ensure composer.json exists #4121 - MAGETWO-57799: cannot upgrade 2.0 => 2.1 with auto_increment > 1 - MAGETWO-59715: Impossible to import additional_images with labels which have a comma separator - MAGETWO-60633: [Github] .htaccess deny code execution not working for Apache + php-fpm #6766 - MAGETWO-46636: Nginx doesn't redirect to setup page when using port
2 parents bbd4b4c + fa9ae9e commit d403ec9

File tree

20 files changed

+433
-94
lines changed

20 files changed

+433
-94
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 115 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ protected function initMediaGalleryResources()
14161416
}
14171417

14181418
/**
1419-
* Get existing images for current bucnh
1419+
* Get existing images for current bunch
14201420
*
14211421
* @param array $bunch
14221422
* @return array
@@ -1436,7 +1436,21 @@ protected function getExistingImages($bunch)
14361436
)->joinInner(
14371437
['mgvte' => $this->mediaGalleryEntityToValueTableName],
14381438
'(mg.value_id = mgvte.value_id)',
1439-
[$this->getProductEntityLinkField() => 'mgvte.' . $this->getProductEntityLinkField()]
1439+
[
1440+
$this->getProductEntityLinkField() => 'mgvte.' . $this->getProductEntityLinkField(),
1441+
'value_id' => 'mgvte.value_id'
1442+
]
1443+
)->joinLeft(
1444+
['mgv' => $this->mediaGalleryValueTableName],
1445+
sprintf(
1446+
'(mg.value_id = mgv.value_id AND mgv.%s = mgvte.%s AND mgv.store_id = %d)',
1447+
$this->getProductEntityLinkField(),
1448+
$this->getProductEntityLinkField(),
1449+
\Magento\Store\Model\Store::DEFAULT_STORE_ID
1450+
),
1451+
[
1452+
'label' => 'mgv.label'
1453+
]
14401454
)->joinInner(
14411455
['pe' => $this->productEntityTableName],
14421456
"(mgvte.{$this->getProductEntityLinkField()} = pe.{$this->getProductEntityLinkField()})",
@@ -1447,7 +1461,7 @@ protected function getExistingImages($bunch)
14471461
);
14481462

14491463
foreach ($this->_connection->fetchAll($select) as $image) {
1450-
$result[$image['sku']][$image['value']] = true;
1464+
$result[$image['sku']][$image['value']] = $image;
14511465
}
14521466

14531467
return $result;
@@ -1462,22 +1476,21 @@ public function getImagesFromRow(array $rowData)
14621476
$images = [];
14631477
$labels = [];
14641478
foreach ($this->_imagesArrayKeys as $column) {
1465-
$images[$column] = [];
1466-
$labels[$column] = [];
14671479
if (!empty($rowData[$column])) {
14681480
$images[$column] = array_unique(
1469-
explode($this->getMultipleValueSeparator(), $rowData[$column])
1481+
array_map(
1482+
'trim',
1483+
explode($this->getMultipleValueSeparator(), $rowData[$column])
1484+
)
14701485
);
1471-
}
14721486

1473-
if (!empty($rowData[$column . '_label'])) {
1474-
$labels[$column] = explode($this->getMultipleValueSeparator(), $rowData[$column . '_label']);
1475-
}
1487+
if (!empty($rowData[$column . '_label'])) {
1488+
$labels[$column] = $this->parseMultipleValues($rowData[$column . '_label']);
14761489

1477-
if (count($labels[$column]) > count($images[$column])) {
1478-
$labels[$column] = array_slice($labels[$column], 0, count($images[$column]));
1479-
} elseif (count($labels[$column]) < count($images[$column])) {
1480-
$labels[$column] = array_pad($labels[$column], count($images[$column]), '');
1490+
if (count($labels[$column]) > count($images[$column])) {
1491+
$labels[$column] = array_slice($labels[$column], 0, count($images[$column]));
1492+
}
1493+
}
14811494
}
14821495
}
14831496

@@ -1507,6 +1520,7 @@ protected function _saveProducts()
15071520
$this->categoriesCache = [];
15081521
$tierPrices = [];
15091522
$mediaGallery = [];
1523+
$labelsForUpdate = [];
15101524
$uploadedImages = [];
15111525
$previousType = null;
15121526
$prevAttributeSet = null;
@@ -1616,7 +1630,7 @@ protected function _saveProducts()
16161630
foreach ($rowImages as $column => $columnImages) {
16171631
foreach ($columnImages as $position => $columnImage) {
16181632
if (!isset($uploadedImages[$columnImage])) {
1619-
$uploadedFile = $this->uploadMediaFiles(trim($columnImage), true);
1633+
$uploadedFile = $this->uploadMediaFiles($columnImage, true);
16201634
if ($uploadedFile) {
16211635
$uploadedImages[$columnImage] = $uploadedFile;
16221636
} else {
@@ -1636,20 +1650,28 @@ protected function _saveProducts()
16361650
$rowData[$column] = $uploadedFile;
16371651
}
16381652

1639-
$imageNotAssigned = !isset($existingImages[$rowSku][$uploadedFile]);
1640-
1641-
if ($uploadedFile && $imageNotAssigned) {
1642-
if ($column == self::COL_MEDIA_IMAGE) {
1643-
$rowData[$column][] = $uploadedFile;
1653+
if ($uploadedFile && !isset($mediaGallery[$rowSku][$uploadedFile])) {
1654+
if (isset($existingImages[$rowSku][$uploadedFile])) {
1655+
if (isset($rowLabels[$column][$position])
1656+
&& $rowLabels[$column][$position] != $existingImages[$rowSku][$uploadedFile]['label']
1657+
) {
1658+
$labelsForUpdate[] = [
1659+
'label' => $rowLabels[$column][$position],
1660+
'imageData' => $existingImages[$rowSku][$uploadedFile]
1661+
];
1662+
}
1663+
} else {
1664+
if ($column == self::COL_MEDIA_IMAGE) {
1665+
$rowData[$column][] = $uploadedFile;
1666+
}
1667+
$mediaGallery[$rowSku][$uploadedFile] = [
1668+
'attribute_id' => $this->getMediaGalleryAttributeId(),
1669+
'label' => isset($rowLabels[$column][$position]) ? $rowLabels[$column][$position] : '',
1670+
'position' => $position + 1,
1671+
'disabled' => isset($disabledImages[$columnImage]) ? '1' : '0',
1672+
'value' => $uploadedFile,
1673+
];
16441674
}
1645-
$mediaGallery[$rowSku][] = [
1646-
'attribute_id' => $this->getMediaGalleryAttributeId(),
1647-
'label' => isset($rowLabels[$column][$position]) ? $rowLabels[$column][$position] : '',
1648-
'position' => $position + 1,
1649-
'disabled' => isset($disabledImages[$columnImage]) ? '1' : '0',
1650-
'value' => $uploadedFile,
1651-
];
1652-
$existingImages[$rowSku][$uploadedFile] = true;
16531675
}
16541676
}
16551677
}
@@ -1767,6 +1789,8 @@ protected function _saveProducts()
17671789
$mediaGallery
17681790
)->_saveProductAttributes(
17691791
$attributes
1792+
)->updateMediaGalleryLabels(
1793+
$labelsForUpdate
17701794
);
17711795

17721796
$this->_eventManager->dispatch(
@@ -2535,12 +2559,13 @@ private function parseAttributesWithWrappedValues($attributesData)
25352559
* Parse values of multiselect attributes depends on "Fields Enclosure" parameter
25362560
*
25372561
* @param string $values
2562+
* @param string $delimiter
25382563
* @return array
25392564
*/
2540-
public function parseMultiselectValues($values)
2565+
public function parseMultiselectValues($values, $delimiter = self::PSEUDO_MULTI_LINE_SEPARATOR)
25412566
{
25422567
if (empty($this->_parameters[Import::FIELDS_ENCLOSURE])) {
2543-
return explode(self::PSEUDO_MULTI_LINE_SEPARATOR, $values);
2568+
return explode($delimiter, $values);
25442569
}
25452570
if (preg_match_all('~"((?:[^"]|"")*)"~', $values, $matches)) {
25462571
return $values = array_map(function ($value) {
@@ -2752,4 +2777,64 @@ private function getProductIdentifierField()
27522777
}
27532778
return $this->productEntityIdentifierField;
27542779
}
2780+
2781+
/**
2782+
* Update media gallery labels
2783+
*
2784+
* @param array $labels
2785+
* @return void
2786+
*/
2787+
private function updateMediaGalleryLabels(array $labels)
2788+
{
2789+
if (empty($labels)) {
2790+
return;
2791+
}
2792+
2793+
$insertData = [];
2794+
foreach ($labels as $label) {
2795+
$imageData = $label['imageData'];
2796+
2797+
if ($imageData['label'] === null) {
2798+
$insertData[] = [
2799+
'label' => $label['label'],
2800+
$this->getProductEntityLinkField() => $imageData[$this->getProductEntityLinkField()],
2801+
'value_id' => $imageData['value_id'],
2802+
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
2803+
];
2804+
} else {
2805+
$this->_connection->update(
2806+
$this->mediaGalleryValueTableName,
2807+
[
2808+
'label' => $label['label']
2809+
],
2810+
[
2811+
$this->getProductEntityLinkField() . ' = ?' => $imageData[$this->getProductEntityLinkField()],
2812+
'value_id = ?' => $imageData['value_id'],
2813+
'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
2814+
]
2815+
);
2816+
}
2817+
}
2818+
2819+
if (!empty($insertData)) {
2820+
$this->_connection->insertMultiple(
2821+
$this->mediaGalleryValueTableName,
2822+
$insertData
2823+
);
2824+
}
2825+
}
2826+
2827+
/**
2828+
* Parse values from multiple attributes fields
2829+
*
2830+
* @param string $labelRow
2831+
* @return array
2832+
*/
2833+
private function parseMultipleValues($labelRow)
2834+
{
2835+
return $this->parseMultiselectValues(
2836+
$labelRow,
2837+
$this->getMultipleValueSeparator()
2838+
);
2839+
}
27552840
}

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Media.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Import\Product\Validator;
77

8-
use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator;
98
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
109

1110
class Media extends AbstractImportValidator implements RowValidatorInterface
@@ -16,19 +15,15 @@ class Media extends AbstractImportValidator implements RowValidatorInterface
1615

1716
const ADDITIONAL_IMAGES = 'additional_images';
1817

18+
/**
19+
* @deprecated
20+
* @see \Magento\CatalogImportExport\Model\Import\Product::getMultipleValueSeparator()
21+
*/
1922
const ADDITIONAL_IMAGES_DELIMITER = ',';
2023

2124
/** @var array */
2225
protected $mediaAttributes = ['image', 'small_image', 'thumbnail'];
2326

24-
/**
25-
* {@inheritdoc}
26-
*/
27-
public function init($context)
28-
{
29-
return parent::init($context);
30-
}
31-
3227
/**
3328
* @param string $string
3429
* @return bool
@@ -83,7 +78,7 @@ public function isValid($value)
8378
}
8479
}
8580
if (isset($value[self::ADDITIONAL_IMAGES]) && strlen($value[self::ADDITIONAL_IMAGES])) {
86-
foreach (explode(self::ADDITIONAL_IMAGES_DELIMITER, $value[self::ADDITIONAL_IMAGES]) as $image) {
81+
foreach (explode($this->context->getMultipleValueSeparator(), $value[self::ADDITIONAL_IMAGES]) as $image) {
8782
if (!$this->checkPath($image) && !$this->checkValidUrl($image)) {
8883
$this->_addMessages(
8984
[

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/MediaTest.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
namespace Magento\CatalogImportExport\Test\Unit\Model\Import\Product\Validator;
88

9+
use Magento\CatalogImportExport\Model\Import\Product;
10+
use Magento\CatalogImportExport\Model\Import\Product\Validator\Media;
911
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
12+
use Magento\ImportExport\Model\Import;
1013

1114
class MediaTest extends \PHPUnit_Framework_TestCase
1215
{
13-
/** @var \Magento\CatalogImportExport\Model\Import\Product\Validator\Media */
16+
/** @var Media */
1417
protected $media;
1518

1619
/** @var ObjectManagerHelper */
@@ -21,7 +24,7 @@ protected function setUp()
2124

2225
$this->objectManagerHelper = new ObjectManagerHelper($this);
2326
$this->media = $this->objectManagerHelper->getObject(
24-
\Magento\CatalogImportExport\Model\Import\Product\Validator\Media::class,
27+
Media::class,
2528
[
2629

2730
]
@@ -41,6 +44,18 @@ public function testInit()
4144
*/
4245
public function testIsValid($data, $expected)
4346
{
47+
$contextMock = $this->getMockBuilder(Product::class)
48+
->disableOriginalConstructor()
49+
->getMock();
50+
$contextMock->expects($this->any())
51+
->method('getMultipleValueSeparator')
52+
->willReturn(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR);
53+
$contextMock->expects($this->any())
54+
->method('retrieveMessageTemplate')
55+
->with(Media::ERROR_INVALID_MEDIA_URL_OR_PATH)
56+
->willReturn('%s');
57+
$this->media->init($contextMock);
58+
4459
$result = $this->media->isValid($data);
4560
$this->assertEquals($expected['result'], $result);
4661
$messages = $this->media->getMessages();
@@ -50,7 +65,7 @@ public function testIsValid($data, $expected)
5065
public function testIsValidClearMessagesCall()
5166
{
5267
$media = $this->getMock(
53-
\Magento\CatalogImportExport\Model\Import\Product\Validator\Media::class,
68+
Media::class,
5469
['_clearMessages'],
5570
[],
5671
'',
@@ -78,6 +93,14 @@ public function isMediaValidDataProvider()
7893
'invalid' => [
7994
['_media_image' => 1],
8095
['result' => true,'messages' => []],
96+
],
97+
'additional_images' => [
98+
['additional_images' => 'image1.png,image2.jpg'],
99+
['result' => true, 'messages' => []]
100+
],
101+
'additional_images_fail' => [
102+
['additional_images' => 'image1.png|image2.jpg|image3.gif'],
103+
['result' => false, 'messages' => [0 => 'additional_images']]
81104
]
82105
];
83106
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,43 @@ public function testValidateValidateOptionEntity()
12801280
$importProduct->validateRow($rowData, $rowNum);
12811281
}
12821282

1283+
/**
1284+
* @dataProvider getImagesFromRowDataProvider
1285+
*/
1286+
public function testGetImagesFromRow($rowData, $expectedResult)
1287+
{
1288+
$this->assertEquals(
1289+
$this->importProduct->getImagesFromRow($rowData),
1290+
$expectedResult
1291+
);
1292+
}
1293+
1294+
public function getImagesFromRowDataProvider()
1295+
{
1296+
return [
1297+
[
1298+
[],
1299+
[[], []]
1300+
],
1301+
[
1302+
[
1303+
'image' => 'image3.jpg',
1304+
'_media_image' => 'image1.jpg,image2.png',
1305+
'_media_image_label' => 'label1,label2'
1306+
],
1307+
[
1308+
[
1309+
'image' => ['image3.jpg'],
1310+
'_media_image' => ['image1.jpg', 'image2.png']
1311+
],
1312+
[
1313+
'_media_image' => ['label1', 'label2']
1314+
],
1315+
]
1316+
]
1317+
];
1318+
}
1319+
12831320
public function validateRowValidateNewProductTypeAddRowErrorCallDataProvider()
12841321
{
12851322
return [

app/code/Magento/Cms/Setup/UpgradeData.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class UpgradeData implements UpgradeDataInterface
1515
{
16+
/**
17+
* @deprecated
18+
*/
1619
const PRIVACY_COOKIE_PAGE_ID = 4;
1720

1821
/**
@@ -234,7 +237,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
234237
</table>
235238
</div>
236239
EOD;
237-
$privacyAndCookiePolicyPage = $this->createPage()->load(self::PRIVACY_COOKIE_PAGE_ID);
240+
$privacyAndCookiePolicyPage = $this->createPage()->load(
241+
'privacy-policy-cookie-restriction-mode',
242+
'identifier'
243+
);
238244
$privacyAndCookiePolicyPageId = $privacyAndCookiePolicyPage->getId();
239245
if ($privacyAndCookiePolicyPageId) {
240246
$privacyAndCookiePolicyPage->setContent($newPageContent);

0 commit comments

Comments
 (0)