|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / app / Firebear / ImportExport / Model / Export / Adapter / |
Filename | /home/a/home/dev2.destoffenstraat.com/app/Firebear/ImportExport/Model/Export/Adapter/Csv.php |
Size | 3.38 kb |
Permission | rwxr-xr-x |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 07-Nov-2022 06:44 |
Last accessed | 23-Aug-2025 10:31 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* @copyright: Copyright © 2017 Firebear Studio. All rights reserved.
* @author : Firebear Studio <fbeardev@gmail.com>
*/
namespace Firebear\ImportExport\Model\Export\Adapter;
use Firebear\ImportExport\Api\Data\SeparatorFormatterInterface;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\ValidatorException;
use Magento\Framework\Filesystem;
use Magento\ImportExport\Model\Export\Adapter\Csv as AbstractAdapter;
use Magento\Framework\App\CacheInterface;
use Psr\Log\LoggerInterface;
/**
* Csv Export Adapter
*/
class Csv extends AbstractAdapter
{
/**
* Adapter Data
*
* @var []
*/
protected $_data;
/**
* @var \Magento\Framework\App\CacheInterface
*/
protected $_cache;
/**
* @var LoggerInterface
*/
private $logger;
/**
* Initialize Adapter
*
* @param Filesystem $filesystem
* @param CacheInterface $cache
* @param LoggerInterface $logger
* @param SeparatorFormatterInterface $separatorFormatter
* @param null $destination
* @param array $data
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(
Filesystem $filesystem,
CacheInterface $cache,
LoggerInterface $logger,
SeparatorFormatterInterface $separatorFormatter,
$destination = null,
array $data = []
) {
$this->_data = $data;
$this->_cache = $cache;
if (isset($data['behavior_data'])) {
$data = $data['behavior_data'];
$this->_enclosure = $data['enclosure'] ?? $this->_enclosure;
$this->_delimiter = $data['separator'] ?? $this->_delimiter;
$this->_delimiter = $separatorFormatter->format($this->_delimiter);
}
parent::__construct(
$filesystem,
$destination
);
$this->logger = $logger;
}
/**
* Write row data to source file.
*
* @param array $rowData
* @throws \Exception
* @return $this
*/
public function writeRow(array $rowData)
{
$jobId = $this->_data['job_id'] ?? '';
$exportByPage = $this->_cache->load('export_by_page' . $jobId);
if ((null === $this->_headerCols) && ($exportByPage == 0)) {
$this->setHeaderCols(array_keys($rowData));
}
if (null === $this->_headerCols) {
$headerColumns = array_keys($rowData);
foreach ($headerColumns as $columnName) {
$this->_headerCols[$columnName] = false;
}
}
if (isset($rowData['behavior_data'])) {
$enclosure = '\"';
$rowData['behavior_data'] = str_replace($enclosure, "", $rowData['behavior_data']);
}
$this->_fileHandler->writeCsv(
array_merge($this->_headerCols, array_intersect_key($rowData, $this->_headerCols)),
$this->_delimiter,
$this->_enclosure
);
return $this;
}
/**
* Remove temp file after export
*/
public function __destruct()
{
try {
$this->_directoryHandle->delete($this->_destination);
} catch (FileSystemException $exception) {
$this->logger->warning($exception->getMessage());
} catch (ValidatorException $exception) {
$this->logger->warning($exception->getMessage());
}
}
}
/**
* @copyright: Copyright © 2017 Firebear Studio. All rights reserved.
* @author : Firebear Studio <fbeardev@gmail.com>
*/
namespace Firebear\ImportExport\Model\Export\Adapter;
use Firebear\ImportExport\Api\Data\SeparatorFormatterInterface;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\ValidatorException;
use Magento\Framework\Filesystem;
use Magento\ImportExport\Model\Export\Adapter\Csv as AbstractAdapter;
use Magento\Framework\App\CacheInterface;
use Psr\Log\LoggerInterface;
/**
* Csv Export Adapter
*/
class Csv extends AbstractAdapter
{
/**
* Adapter Data
*
* @var []
*/
protected $_data;
/**
* @var \Magento\Framework\App\CacheInterface
*/
protected $_cache;
/**
* @var LoggerInterface
*/
private $logger;
/**
* Initialize Adapter
*
* @param Filesystem $filesystem
* @param CacheInterface $cache
* @param LoggerInterface $logger
* @param SeparatorFormatterInterface $separatorFormatter
* @param null $destination
* @param array $data
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(
Filesystem $filesystem,
CacheInterface $cache,
LoggerInterface $logger,
SeparatorFormatterInterface $separatorFormatter,
$destination = null,
array $data = []
) {
$this->_data = $data;
$this->_cache = $cache;
if (isset($data['behavior_data'])) {
$data = $data['behavior_data'];
$this->_enclosure = $data['enclosure'] ?? $this->_enclosure;
$this->_delimiter = $data['separator'] ?? $this->_delimiter;
$this->_delimiter = $separatorFormatter->format($this->_delimiter);
}
parent::__construct(
$filesystem,
$destination
);
$this->logger = $logger;
}
/**
* Write row data to source file.
*
* @param array $rowData
* @throws \Exception
* @return $this
*/
public function writeRow(array $rowData)
{
$jobId = $this->_data['job_id'] ?? '';
$exportByPage = $this->_cache->load('export_by_page' . $jobId);
if ((null === $this->_headerCols) && ($exportByPage == 0)) {
$this->setHeaderCols(array_keys($rowData));
}
if (null === $this->_headerCols) {
$headerColumns = array_keys($rowData);
foreach ($headerColumns as $columnName) {
$this->_headerCols[$columnName] = false;
}
}
if (isset($rowData['behavior_data'])) {
$enclosure = '\"';
$rowData['behavior_data'] = str_replace($enclosure, "", $rowData['behavior_data']);
}
$this->_fileHandler->writeCsv(
array_merge($this->_headerCols, array_intersect_key($rowData, $this->_headerCols)),
$this->_delimiter,
$this->_enclosure
);
return $this;
}
/**
* Remove temp file after export
*/
public function __destruct()
{
try {
$this->_directoryHandle->delete($this->_destination);
} catch (FileSystemException $exception) {
$this->logger->warning($exception->getMessage());
} catch (ValidatorException $exception) {
$this->logger->warning($exception->getMessage());
}
}
}