From b9732d7d1055c03fb353254b32a30b154234be67 Mon Sep 17 00:00:00 2001 From: Eric COURTIAL Date: Mon, 9 Apr 2018 19:46:39 -0400 Subject: [PATCH 1/3] Added possibility to select PHP input file mode --- lib/internal/Magento/Framework/File/Csv.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/File/Csv.php b/lib/internal/Magento/Framework/File/Csv.php index 3d177f89e2968..67177445a670d 100644 --- a/lib/internal/Magento/Framework/File/Csv.php +++ b/lib/internal/Magento/Framework/File/Csv.php @@ -126,13 +126,17 @@ public function getDataPairs($file, $keyIndex = 0, $valueIndex = 1) /** * Saving data row array into file * - * @param string $file - * @param array $data - * @return $this + * @param string $file + * @param array $data + * @param string $mode + * + * @return $this + * + * @throws \Magento\Framework\Exception\FileSystemException */ - public function saveData($file, $data) + public function saveData($file, $data, $mode = 'w') { - $fh = fopen($file, 'w'); + $fh = fopen($file, $mode); foreach ($data as $dataRow) { $this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure); } From 68e087843fbb17a2c3de1ed4ecd2c380feab8640 Mon Sep 17 00:00:00 2001 From: Eric COURTIAL Date: Wed, 11 Apr 2018 19:11:17 -0400 Subject: [PATCH 2/3] Added a new method to replace the saveData one --- lib/internal/Magento/Framework/File/Csv.php | 34 +++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/internal/Magento/Framework/File/Csv.php b/lib/internal/Magento/Framework/File/Csv.php index 67177445a670d..10ee9b193d543 100644 --- a/lib/internal/Magento/Framework/File/Csv.php +++ b/lib/internal/Magento/Framework/File/Csv.php @@ -126,21 +126,43 @@ public function getDataPairs($file, $keyIndex = 0, $valueIndex = 1) /** * Saving data row array into file * - * @param string $file - * @param array $data + * @param string $file + * @param array $data + * @return $this + * @throws \Magento\Framework\Exception\FileSystemException + * @deprecated + * @see appendData + */ + public function saveData($file, $data) + { + $fh = fopen($file, 'w'); + foreach ($data as $dataRow) { + $this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure); + } + fclose($fh); + return $this; + } + + /** + * Replace the saveData method by + * allowing to select the input mode + * + * @param $file + * @param $data * @param string $mode * * @return $this * * @throws \Magento\Framework\Exception\FileSystemException */ - public function saveData($file, $data, $mode = 'w') + public function appendData($file, $data, $mode = 'w') { - $fh = fopen($file, $mode); + $fileHandler = fopen($file, $mode); foreach ($data as $dataRow) { - $this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure); + $this->file->filePutCsv($fileHandler, $dataRow, $this->_delimiter, $this->_enclosure); } - fclose($fh); + fclose($fileHandler); + return $this; } } From 9e01479c24c8658ed648a12f6bf69a1ccd0a7450 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Thu, 3 May 2018 12:03:09 +0300 Subject: [PATCH 3/3] Refactored code for avoiding copy/paste --- lib/internal/Magento/Framework/File/Csv.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/internal/Magento/Framework/File/Csv.php b/lib/internal/Magento/Framework/File/Csv.php index 10ee9b193d543..571ad6b21efa7 100644 --- a/lib/internal/Magento/Framework/File/Csv.php +++ b/lib/internal/Magento/Framework/File/Csv.php @@ -126,29 +126,23 @@ public function getDataPairs($file, $keyIndex = 0, $valueIndex = 1) /** * Saving data row array into file * - * @param string $file - * @param array $data - * @return $this + * @param string $file + * @param array $data + * @return $this * @throws \Magento\Framework\Exception\FileSystemException * @deprecated * @see appendData */ public function saveData($file, $data) { - $fh = fopen($file, 'w'); - foreach ($data as $dataRow) { - $this->file->filePutCsv($fh, $dataRow, $this->_delimiter, $this->_enclosure); - } - fclose($fh); - return $this; + return $this->appendData($file, $data, 'w'); } /** - * Replace the saveData method by - * allowing to select the input mode + * Replace the saveData method by allowing to select the input mode * - * @param $file - * @param $data + * @param string $file + * @param array $data * @param string $mode * * @return $this