Skip to content

Product CSV import error report file missing #28460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public function destruct()
{
if (is_object($this->_fileHandler)) {
$this->_fileHandler->close();
$this->resolveDestination();
}
}

/**
* Remove temporary destination
*
* @return void
*/
private function resolveDestination(): void
{
// only temporary file located directly in var folder
if (strpos($this->_destination, '/') === false) {
$this->_directoryHandle->delete($this->_destination);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\ImportExport\Model\Import;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
Expand All @@ -28,43 +29,53 @@ class CsvTest extends TestCase
*/
private $objectManager;

/**
* @var Csv
*/
private $csv;

/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();

$this->objectManager = Bootstrap::getObjectManager();
$this->csv = $this->objectManager->create(
Csv::class,
['destination' => $this->destination]
);
}

/**
* Test to destruct export adapter
*
* @dataProvider destructDataProvider
*
* @param string $destination
* @param bool $shouldBeDeleted
* @return void
*/
public function testDestruct(): void
public function testDestruct(string $destination, bool $shouldBeDeleted): void
{
$csv = $this->objectManager->create(Csv::class, ['destination' => $destination]);
/** @var Filesystem $fileSystem */
$fileSystem = $this->objectManager->get(Filesystem::class);
$directoryHandle = $fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);
/** Assert that the destination file is present after construct */
$this->assertFileExists(
$directoryHandle->getAbsolutePath($this->destination),
$directoryHandle->getAbsolutePath($destination),
'The destination file was\'t created after construct'
);
/** Assert that the destination file was removed after destruct */
$this->csv = null;
$this->assertFileNotExists(
$directoryHandle->getAbsolutePath($this->destination),
'The destination file was\'t removed after destruct'
);
unset($csv);

if ($shouldBeDeleted) {
$this->assertFileDoesNotExist($directoryHandle->getAbsolutePath($destination));
} else {
$this->assertFileExists($directoryHandle->getAbsolutePath($destination));
}
}

/**
* DataProvider for testDestruct
*
* @return array
*/
public function destructDataProvider(): array
{
return [
'temporary file' => [$this->destination, true],
'import history file' => [Import::IMPORT_HISTORY_DIR . $this->destination, false],
];
}
}