From 702d76d49beebd6200b1a158db4b39b0a0cbb2da Mon Sep 17 00:00:00 2001 From: Keisuke Mutoh Date: Tue, 6 Oct 2015 13:58:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A9=BA=E3=81=AECSV=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=82=A4=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=88?= =?UTF-8?q?(=E5=95=86=E5=93=81=EF=BC=8F=E3=82=AB=E3=83=86=E3=82=B4?= =?UTF-8?q?=E3=83=AA)=E3=81=AB=E5=AF=BE=E5=BF=9C=20#811?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Product/CsvImportController.php | 16 ++++++++++------ src/Eccube/Service/CsvImportService.php | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Eccube/Controller/Admin/Product/CsvImportController.php b/src/Eccube/Controller/Admin/Product/CsvImportController.php index 9e993e20815..6885008e5a3 100644 --- a/src/Eccube/Controller/Admin/Product/CsvImportController.php +++ b/src/Eccube/Controller/Admin/Product/CsvImportController.php @@ -60,7 +60,6 @@ class CsvImportController */ public function csvProduct(Application $app, Request $request) { - $form = $app['form.factory']->createBuilder('admin_csv_import')->getForm(); $headers = $this->getProductCsvHeader(); @@ -76,10 +75,13 @@ public function csvProduct(Application $app, Request $request) if (!empty($formFile)) { $data = $this->getImportData($app, $formFile); + if($data===false) { + $this->addErrors('CSVのフォーマットが一致しません。'); + return $this->render($app, $form, $headers, $this->productTwig); + } $keys = array_keys($headers); $columnHeaders = $data->getColumnHeaders(); - if ($keys !== $columnHeaders) { $this->addErrors('CSVのフォーマットが一致しません。'); return $this->render($app, $form, $headers, $this->productTwig); @@ -420,10 +422,13 @@ public function csvCategory(Application $app, Request $request) if (!empty($formFile)) { $data = $this->getImportData($app, $formFile); + if($data===false) { + $this->addErrors('CSVのフォーマットが一致しません。'); + return $this->render($app, $form, $headers, $this->categoryTwig); + } $keys = array_keys($headers); $columnHeaders = $data->getColumnHeaders(); - if ($keys !== $columnHeaders) { $this->addErrors('CSVのフォーマットが一致しません。'); return $this->render($app, $form, $headers, $this->categoryTwig); @@ -614,7 +619,6 @@ protected function render($app, $form, $headers, $twig) */ protected function getImportData($app, $formFile) { - // アップロードされたCSVファイルを一時ディレクトリに保存 $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension(); $formFile->move($app['config']['csv_temp_realdir'], $this->fileName); @@ -638,9 +642,9 @@ protected function getImportData($app, $formFile) // アップロードされたCSVファイルを行ごとに取得 $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']); - $data->setHeaderRowNumber(0); + $ret = $data->setHeaderRowNumber(0); - return $data; + return ($ret!==false)?$data:false; } diff --git a/src/Eccube/Service/CsvImportService.php b/src/Eccube/Service/CsvImportService.php index ee753191e68..eb719c364c8 100644 --- a/src/Eccube/Service/CsvImportService.php +++ b/src/Eccube/Service/CsvImportService.php @@ -195,6 +195,7 @@ public function setColumnHeaders(array $columnHeaders) * - CsvReader::DUPLICATE_HEADERS_MERGE; merges * values for duplicate headers into an array * (dup => [value1, value2, value3]) + * @return boolean */ public function setHeaderRowNumber($rowNumber, $duplicates = null) { @@ -202,7 +203,11 @@ public function setHeaderRowNumber($rowNumber, $duplicates = null) $this->headerRowNumber = $rowNumber; $headers = $this->readHeaderRow($rowNumber); + if($headers===false) { + return false; + } $this->setColumnHeaders($headers); + return true; } /** From 06d3267482793fa4274be8eaba33f1ba3753036b Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 6 Oct 2015 16:55:10 +0900 Subject: [PATCH 2/2] fix coding style --- src/Eccube/Controller/Admin/Product/CsvImportController.php | 6 +++--- src/Eccube/Service/CsvImportService.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Eccube/Controller/Admin/Product/CsvImportController.php b/src/Eccube/Controller/Admin/Product/CsvImportController.php index 6885008e5a3..133ded42335 100644 --- a/src/Eccube/Controller/Admin/Product/CsvImportController.php +++ b/src/Eccube/Controller/Admin/Product/CsvImportController.php @@ -75,7 +75,7 @@ public function csvProduct(Application $app, Request $request) if (!empty($formFile)) { $data = $this->getImportData($app, $formFile); - if($data===false) { + if ($data === false) { $this->addErrors('CSVのフォーマットが一致しません。'); return $this->render($app, $form, $headers, $this->productTwig); } @@ -422,7 +422,7 @@ public function csvCategory(Application $app, Request $request) if (!empty($formFile)) { $data = $this->getImportData($app, $formFile); - if($data===false) { + if ($data === false) { $this->addErrors('CSVのフォーマットが一致しません。'); return $this->render($app, $form, $headers, $this->categoryTwig); } @@ -644,7 +644,7 @@ protected function getImportData($app, $formFile) $ret = $data->setHeaderRowNumber(0); - return ($ret!==false)?$data:false; + return ($ret !== false) ? $data : false; } diff --git a/src/Eccube/Service/CsvImportService.php b/src/Eccube/Service/CsvImportService.php index eb719c364c8..27bedd6dc84 100644 --- a/src/Eccube/Service/CsvImportService.php +++ b/src/Eccube/Service/CsvImportService.php @@ -203,7 +203,7 @@ public function setHeaderRowNumber($rowNumber, $duplicates = null) $this->headerRowNumber = $rowNumber; $headers = $this->readHeaderRow($rowNumber); - if($headers===false) { + if ($headers === false) { return false; } $this->setColumnHeaders($headers);