Skip to content

Commit

Permalink
Merge pull request #1 from chihiro-adachi/pull-886
Browse files Browse the repository at this point in the history
fix coding style
  • Loading branch information
casek committed Oct 6, 2015
2 parents 3581c89 + 06d3267 commit f75924d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Eccube/Controller/Admin/Product/CsvImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}


Expand Down
5 changes: 5 additions & 0 deletions src/Eccube/Service/CsvImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,19 @@ 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)
{
$this->duplicateHeadersFlag = $duplicates;
$this->headerRowNumber = $rowNumber;
$headers = $this->readHeaderRow($rowNumber);

if ($headers === false) {
return false;
}
$this->setColumnHeaders($headers);
return true;
}

/**
Expand Down

0 comments on commit f75924d

Please sign in to comment.