Skip to content

Commit a6ae29a

Browse files
author
Andrey Konosov
committed
Merge commit 'refs/pull/12/head' of https://github.com/magento/magento2ce into epam-4
2 parents 8966164 + e53cfa1 commit a6ae29a

File tree

8 files changed

+95
-6
lines changed

8 files changed

+95
-6
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Product/Plugin/Import.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ protected function cleanOverriddenUrlKey()
289289
return $this;
290290
}
291291
$select = $this->connection->select()
292-
->from($this->urlKeyAttributeBackendTable, 'store_id, entity_id')
292+
->from($this->urlKeyAttributeBackendTable, ['store_id', 'entity_id'])
293293
->where('attribute_id = ?', $this->urlKeyAttributeId)
294294
->where(implode(' OR ', $this->entityStoresToCheckOverridden));
295295
$entityStoresToClean = $this->connection->fetchAll($select);

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/Plugin/ImportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ public function testCleanOverriddenUrlKey()
616616
->method('from')
617617
->with(
618618
$urlKeyAttributeBackendTable,
619-
'store_id, entity_id'
619+
['store_id', 'entity_id']
620620
)
621621
->will($this->returnSelf());
622622
$this->select
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ImportExport\Controller\Adminhtml\Import;
7+
8+
use Magento\ImportExport\Controller\Adminhtml\Import as ImportController;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
11+
/**
12+
* Download sample file controller
13+
*/
14+
class Download extends ImportController
15+
{
16+
const SAMPLE_FILES_DIRECTORY = 'Magento/ImportExport/Files/Sample/';
17+
18+
/**
19+
* @var \Magento\Framework\Controller\Result\RawFactory
20+
*/
21+
protected $resultRawFactory;
22+
23+
/**
24+
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
25+
*/
26+
protected $fileDirectory;
27+
28+
/**
29+
* @param \Magento\Backend\App\Action\Context $context
30+
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
31+
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
32+
* @param \Magento\Framework\Filesystem $filesystem
33+
*/
34+
public function __construct(
35+
\Magento\Backend\App\Action\Context $context,
36+
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
37+
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
38+
\Magento\Framework\Filesystem $filesystem
39+
) {
40+
parent::__construct(
41+
$context
42+
);
43+
$this->fileFactory = $fileFactory;
44+
$this->resultRawFactory = $resultRawFactory;
45+
$this->fileDirectory = $filesystem->getDirectoryWrite(DirectoryList::MODULES);
46+
}
47+
48+
/**
49+
* Download sample file action
50+
*
51+
* @return \Magento\Framework\Controller\Result\Raw
52+
*/
53+
public function execute()
54+
{
55+
$fileName = $this->getRequest()->getParam('filename') . '.csv';
56+
$filePath = self::SAMPLE_FILES_DIRECTORY . $fileName;
57+
58+
if (!$this->fileDirectory->isFile($filePath)) {
59+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
60+
$this->messageManager->addError(__('There is no sample file for this entity.'));
61+
$resultRedirect = $this->resultRedirectFactory->create();
62+
$resultRedirect->setPath('*/import');
63+
return $resultRedirect;
64+
}
65+
66+
$fileSize = isset($this->fileDirectory->stat($filePath)['size'])
67+
? $this->fileDirectory->stat($filePath)['size'] : null;
68+
69+
$this->fileFactory->create(
70+
$fileName,
71+
null,
72+
DirectoryList::VAR_DIR,
73+
'application/octet-stream',
74+
$fileSize
75+
);
76+
77+
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
78+
$resultRaw = $this->resultRawFactory->create();
79+
$resultRaw->setContents($this->fileDirectory->readFile($filePath));
80+
return $resultRaw;
81+
}
82+
}

app/code/Magento/ImportExport/Model/Import.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,18 @@ protected function createHistoryReport($sourceFileRelative, $entity, $extension
712712
$fileName = $result['name'];
713713
} elseif (!is_null($extension)) {
714714
$fileName = $entity . $extension;
715+
} else {
716+
$fileName = basename($sourceFileRelative);
715717
}
716718
$copyName = $this->localeDate->gmtTimestamp() . '_' . $fileName;
717719
$copyFile = self::IMPORT_HISTORY_DIR . $copyName;
718720
try {
719-
$this->_varDirectory->copyFile($sourceFileRelative, $copyFile);
721+
if ($this->_varDirectory->isExist($sourceFileRelative)) {
722+
$this->_varDirectory->copyFile($sourceFileRelative, $copyFile);
723+
} else {
724+
$content = $this->_varDirectory->getDriver()->fileGetContents($sourceFileRelative);
725+
$this->_varDirectory->writeFile($copyFile, $content);
726+
}
720727
} catch (\Magento\Framework\Exception\FileSystemException $e) {
721728
throw new \Magento\Framework\Exception\LocalizedException(__('Source file coping failed'));
722729
}

app/code/Magento/ImportExport/Model/Import/AbstractEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public function isRowAllowedToImport(array $rowData, $rowNumber)
677677
return $this->validateRow($rowData, $rowNumber) && !isset($this->_skippedRows[$rowNumber]);
678678
}
679679

680-
/*
680+
/**
681681
* Is import need to log in history.
682682
*
683683
* @return bool

app/code/Magento/ImportExport/view/adminhtml/templates/import/form/before.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require(['jquery', 'prototype'], function(jQuery){
3535
* Base url
3636
* @type {string}
3737
*/
38-
sampleFilesBaseUrl: '<?php echo $block->getBaseUrl() ?>' + 'pub/',
38+
sampleFilesBaseUrl: '<?php echo $block->getUrl('*/*/download/', ['filename' => 'entity-name']) ?>',
3939

4040
/**
4141
* Reset selected index
@@ -105,7 +105,7 @@ require(['jquery', 'prototype'], function(jQuery){
105105
showSampleFile: function(entityId) {
106106
var sampleFileSpan = jQuery('#sample-file-span');
107107
if (entityId) {
108-
var sampleFileLink = this.sampleFilesBaseUrl + entityId + '.csv';
108+
var sampleFileLink = this.sampleFilesBaseUrl.replace('entity-name', entityId);
109109
jQuery('#sample-file-link').attr('href', sampleFileLink);
110110
if (sampleFileSpan.is(':hidden')) {
111111
sampleFileSpan.show();

0 commit comments

Comments
 (0)