Skip to content

Commit 6ae22a2

Browse files
author
Bomko, Alex(abomko)
committed
Merge pull request #330 from magento-nord/MAGETWO-37985
[MX][Virtual Team] Public GitHub Issues, Bug Fixes
2 parents 02223fb + bc816a7 commit 6ae22a2

File tree

10 files changed

+127
-44
lines changed

10 files changed

+127
-44
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Setup;
7+
8+
use Magento\Framework\Setup\UpgradeDataInterface;
9+
use Magento\Framework\Setup\ModuleContextInterface;
10+
use Magento\Framework\Setup\ModuleDataSetupInterface;
11+
use Magento\Catalog\Model\Category;
12+
13+
/**
14+
* @codeCoverageIgnore
15+
*/
16+
class UpgradeData implements UpgradeDataInterface
17+
{
18+
/**
19+
* @var Category
20+
*/
21+
protected $category;
22+
23+
/**
24+
* @param Category $category
25+
*/
26+
public function __construct(Category $category)
27+
{
28+
$this->category = $category;
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
35+
{
36+
if (version_compare($context->getVersion(), '2.0.0.2') < 0) {
37+
$newBackendModel = 'Magento\Catalog\Model\Attribute\Backend\Startdate';
38+
$connection = $setup->getConnection();
39+
$connection->startSetup();
40+
$connection->update(
41+
$setup->getTable('eav_attribute'),
42+
['backend_model' => $newBackendModel],
43+
['backend_model = ?' => 'Magento\Catalog\Model\Product\Attribute\Backend\Startdate']
44+
);
45+
/** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attribute */
46+
foreach ($this->category->getAttributes() as $attribute) {
47+
if ($attribute->getAttributeCode() == 'custom_design_from') {
48+
$attribute->setBackendModel($newBackendModel);
49+
$attribute->save();
50+
break;
51+
}
52+
}
53+
$connection->endSetup();
54+
}
55+
}
56+
}

app/code/Magento/Catalog/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
9-
<module name="Magento_Catalog" setup_version="2.0.0.1">
9+
<module name="Magento_Catalog" setup_version="2.0.0.2">
1010
<sequence>
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Cms"/>

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
123123
*/
124124
protected $_attributeTypes = [];
125125

126+
/**
127+
* Product collection
128+
*
129+
* @var \Magento\Catalog\Model\Resource\Product\CollectionFactory
130+
*/
131+
protected $_entityCollectionFactory;
132+
126133
/**
127134
* Product collection
128135
*
@@ -231,7 +238,7 @@ public function __construct(
231238
\Magento\Framework\App\Resource $resource,
232239
\Magento\Store\Model\StoreManagerInterface $storeManager,
233240
\Psr\Log\LoggerInterface $logger,
234-
\Magento\Catalog\Model\Resource\Product\Collection $collection,
241+
\Magento\Catalog\Model\Resource\Product\CollectionFactory $collectionFactory,
235242
\Magento\ImportExport\Model\Export\ConfigInterface $exportConfig,
236243
\Magento\Catalog\Model\Resource\ProductFactory $productFactory,
237244
\Magento\Eav\Model\Resource\Entity\Attribute\Set\CollectionFactory $attrSetColFactory,
@@ -243,7 +250,7 @@ public function __construct(
243250
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
244251
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
245252
) {
246-
$this->_entityCollection = $collection;
253+
$this->_entityCollectionFactory = $collectionFactory;
247254
$this->_exportConfig = $exportConfig;
248255
$this->_logger = $logger;
249256
$this->_productFactory = $productFactory;
@@ -669,12 +676,13 @@ protected function setHeaderColumns($customOptionsData, $stockItemRows)
669676
}
670677

671678
/**
672-
* Get product collection
673-
*
674-
* @return \Magento\Catalog\Model\Resource\Product\Collection
679+
* {@inheritdoc}
675680
*/
676-
protected function _getEntityCollection()
681+
protected function _getEntityCollection($resetCollection = false)
677682
{
683+
if ($resetCollection || empty($this->_entityCollection)) {
684+
$this->_entityCollection = $this->_entityCollectionFactory->create();
685+
}
678686
return $this->_entityCollection;
679687
}
680688

@@ -735,23 +743,23 @@ protected function paginateCollection($page, $pageSize)
735743
/**
736744
* Export process
737745
*
738-
* @see https://jira.corp.x.com/browse/MAGETWO-7894
739746
* @return string
740747
*/
741748
public function export()
742749
{
743750
//Execution time may be very long
744751
set_time_limit(0);
745752

746-
$this->_prepareEntityCollection($this->_getEntityCollection());
747-
$this->_getEntityCollection()->setOrder('has_options', 'asc');
748-
$this->_getEntityCollection()->setStoreId(Store::DEFAULT_STORE_ID);
749753
$writer = $this->getWriter();
750754
$page = 0;
751755
while (true) {
752756
++$page;
757+
$entityCollection = $this->_getEntityCollection(true);
758+
$entityCollection->setOrder('has_options', 'asc');
759+
$entityCollection->setStoreId(Store::DEFAULT_STORE_ID);
760+
$this->_prepareEntityCollection($entityCollection);
753761
$this->paginateCollection($page, $this->getItemsPerPage());
754-
if ($this->_getEntityCollection()->count() == 0) {
762+
if ($entityCollection->count() == 0) {
755763
break;
756764
}
757765
$exportData = $this->getExportData();
@@ -761,7 +769,7 @@ public function export()
761769
foreach ($exportData as $dataRow) {
762770
$writer->writeRow($dataRow);
763771
}
764-
if ($this->_getEntityCollection()->getCurPage() >= $this->_getEntityCollection()->getLastPageNumber()) {
772+
if ($entityCollection->getCurPage() >= $entityCollection->getLastPageNumber()) {
765773
break;
766774
}
767775
}

app/code/Magento/ImportExport/Model/Export/Entity/AbstractEntity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ abstract protected function _getHeaderColumns();
190190
/**
191191
* Get entity collection
192192
*
193+
* @param bool $resetCollection
193194
* @return \Magento\Framework\Data\Collection\Db
194195
*/
195-
abstract protected function _getEntityCollection();
196+
abstract protected function _getEntityCollection($resetCollection = false);
196197

197198
/**
198199
* Get attributes codes which are appropriate for export.

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,22 @@ public function testExport()
7070
*/
7171
public function testExportStockItemAttributesAreFilled()
7272
{
73-
$filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
73+
$fileWrite = $this->getMock('Magento\Framework\Filesystem\File\Write', [], [], '', false);
7474
$directoryMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
75-
76-
$filesystemMock->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directoryMock));
77-
7875
$directoryMock->expects($this->any())->method('getParentDirectory')->will($this->returnValue('some#path'));
79-
8076
$directoryMock->expects($this->any())->method('isWritable')->will($this->returnValue(true));
81-
8277
$directoryMock->expects($this->any())->method('isFile')->will($this->returnValue(true));
83-
8478
$directoryMock->expects(
8579
$this->any()
8680
)->method(
8781
'readFile'
8882
)->will(
8983
$this->returnValue('some string read from file')
9084
);
85+
$directoryMock->expects($this->once())->method('openFile')->will($this->returnValue($fileWrite));
86+
87+
$filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
88+
$filesystemMock->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directoryMock));
9189

9290
$exportAdapter = new \Magento\ImportExport\Model\Export\Adapter\Csv($filesystemMock);
9391

dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/WriteTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function writeProvider()
8181
['new1.csv', 'w', 'write check', 11],
8282
['new3.csv', 'a', 'write check', 11],
8383
['new5.csv', 'x', 'write check', 11],
84-
['new7.csv', 'c', 'write check', 11]
84+
['new7.csv', 'c', 'write check', 11],
8585
];
8686
}
8787

@@ -117,40 +117,42 @@ public function writeAndReadProvider()
117117
['new2.csv', 'w+', 'write check', 11],
118118
['new4.csv', 'a+', 'write check', 11],
119119
['new6.csv', 'x+', 'write check', 11],
120-
['new8.csv', 'c+', 'write check', 11]
120+
['new8.csv', 'c+', 'write check', 11],
121121
];
122122
}
123123

124124
/**
125125
* Writes one CSV row to the file.
126126
*
127-
* @dataProvider csvProvider
127+
* @dataProvider csvDataProvider
128+
* @param array $expectedData
128129
* @param string $path
129130
* @param array $data
130131
* @param string $delimiter
131132
* @param string $enclosure
132133
*/
133-
public function testWriteCsv($path, array $data, $delimiter = ',', $enclosure = '"')
134+
public function testWriteCsv($expectedData, $path, array $data, $delimiter = ',', $enclosure = '"')
134135
{
135136
$file = $this->getFileInstance($path, 'w+');
136137
$result = $file->writeCsv($data, $delimiter, $enclosure);
137138
$file->seek(0);
138139
$read = $file->readCsv($result, $delimiter, $enclosure);
139140
$file->close();
140141
$this->removeCurrentFile();
141-
$this->assertEquals($data, $read);
142+
$this->assertEquals($expectedData, $read);
142143
}
143144

144145
/**
145146
* Data provider for testWriteCsv
146147
*
147148
* @return array
148149
*/
149-
public function csvProvider()
150+
public function csvDataProvider()
150151
{
151152
return [
152-
['newcsv1.csv', ['field1', 'field2'], ',', '"'],
153-
['newcsv1.csv', ['field1', 'field2'], '%', '@']
153+
[['field1', 'field2'], 'newcsv1.csv', ['field1', 'field2'], ',', '"'],
154+
[['field1', 'field2'], 'newcsv1.csv', ['field1', 'field2'], '%', '@'],
155+
[[' =field1', 'field2'], 'newcsv1.csv', ['=field1', 'field2'], '%', '@'],
154156
];
155157
}
156158

@@ -201,7 +203,7 @@ private function getFileInstance($path, $mode)
201203
[
202204
'path' => $this->currentFilePath,
203205
'driver' => new \Magento\Framework\Filesystem\Driver\File(),
204-
'mode' => $mode
206+
'mode' => $mode,
205207
]
206208
);
207209
}

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
namespace Magento\Framework\Filesystem\Driver;
99

10-
use Magento\Framework\Filesystem\DriverInterface;
1110
use Magento\Framework\Exception\FileSystemException;
11+
use Magento\Framework\Filesystem\DriverInterface;
1212

1313
class File implements DriverInterface
1414
{
@@ -299,7 +299,7 @@ public function copy($source, $destination, DriverInterface $targetDriver = null
299299
[
300300
$source,
301301
$destination,
302-
$this->getWarningMessage()
302+
$this->getWarningMessage(),
303303
]
304304
)
305305
);
@@ -329,7 +329,7 @@ public function symlink($source, $destination, DriverInterface $targetDriver = n
329329
[
330330
$source,
331331
$destination,
332-
$this->getWarningMessage()
332+
$this->getWarningMessage(),
333333
]
334334
)
335335
);
@@ -644,6 +644,16 @@ public function fileWrite($resource, $data)
644644
*/
645645
public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure = '"')
646646
{
647+
/**
648+
* Security enhancement for CSV data processing by Excel-like applications.
649+
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1054702
650+
*/
651+
foreach ($data as $key => $value) {
652+
if (isset($value[0]) && $value[0] === '=') {
653+
$data[$key] = ' ' . $value;
654+
}
655+
}
656+
647657
$result = @fputcsv($resource, $data, $delimiter, $enclosure);
648658
if (!$result) {
649659
throw new FileSystemException(

lib/internal/Magento/Framework/Filesystem/Io/File.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ public function streamWriteCsv(array $row, $delimiter = ',', $enclosure = '"')
177177
if (!$this->_streamHandler) {
178178
return false;
179179
}
180+
/**
181+
* Security enhancement for CSV data processing by Excel-like applications.
182+
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1054702
183+
*/
184+
foreach ($row as $key => $value) {
185+
if (isset($value[0]) && $value[0] === '=') {
186+
$row[$key] = ' ' . $value;
187+
}
188+
}
180189
return @fputcsv($this->_streamHandler, $row, $delimiter, $enclosure);
181190
}
182191

lib/internal/Magento/Framework/Locale/TranslatedLists.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public function getTranslatedOptionLocales()
6767
protected function _getOptionLocales($translatedName = false)
6868
{
6969
$currentLocale = $this->localeResolver->getLocale();
70-
$locales = \ResourceBundle::getLocales(null);
70+
$locales = \ResourceBundle::getLocales('') ?: [];
7171
$languages = (new LanguageBundle())->get($currentLocale)['Languages'];
7272
$countries = (new RegionBundle())->get($currentLocale)['Countries'];
7373

7474
$options = [];
7575
$allowedLocales = $this->_config->getAllowedLocales();
76-
foreach ((array)$locales as $locale) {
76+
foreach ($locales as $locale) {
7777
if (!in_array($locale, $allowedLocales)) {
7878
continue;
7979
}
@@ -103,7 +103,7 @@ public function getOptionTimezones()
103103
{
104104
$options = [];
105105
$locale = $this->localeResolver->getLocale();
106-
$zones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL);
106+
$zones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL) ?: [];
107107
foreach ($zones as $code) {
108108
$options[] = [
109109
'label' => \IntlTimeZone::createTimeZone($code)->getDisplayName(
@@ -123,9 +123,8 @@ public function getOptionTimezones()
123123
public function getOptionWeekdays($preserveCodes = false, $ucFirstCode = false)
124124
{
125125
$options = [];
126-
$days = (new DataBundle())->get(
127-
$this->localeResolver->getLocale()
128-
)['calendar']['gregorian']['dayNames']['format']['wide'];
126+
$days = (new DataBundle())
127+
->get($this->localeResolver->getLocale())['calendar']['gregorian']['dayNames']['format']['wide'] ?: [];
129128
$englishDays = (new DataBundle())->get('en_US')['calendar']['gregorian']['dayNames']['format']['abbreviated'];
130129
foreach ($days as $code => $name) {
131130
$code = $preserveCodes ? $englishDays[$code] : $code;
@@ -140,7 +139,7 @@ public function getOptionWeekdays($preserveCodes = false, $ucFirstCode = false)
140139
public function getOptionCountries()
141140
{
142141
$options = [];
143-
$countries = (new RegionBundle())->get($this->localeResolver->getLocale())['Countries'];
142+
$countries = (new RegionBundle())->get($this->localeResolver->getLocale())['Countries'] ?: [];
144143
foreach ($countries as $code => $name) {
145144
$options[] = ['label' => $name, 'value' => $code];
146145
}
@@ -152,7 +151,7 @@ public function getOptionCountries()
152151
*/
153152
public function getOptionCurrencies()
154153
{
155-
$currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies'];
154+
$currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies'] ?: [];
156155
$options = [];
157156
$allowed = $this->_config->getAllowedCurrencies();
158157
foreach ($currencies as $code => $data) {
@@ -169,7 +168,7 @@ public function getOptionCurrencies()
169168
*/
170169
public function getOptionAllCurrencies()
171170
{
172-
$currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies'];
171+
$currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies'] ?: [];
173172
$options = [];
174173
foreach ($currencies as $code => $data) {
175174
$options[] = ['label' => $data[1], 'value' => $code];

0 commit comments

Comments
 (0)