Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Inheritance: implements Iterator, implements SeekableIterator, implements Countable
Exemplo n.º 1
0
 /**
  * アップロードされたCSVファイルの行ごとの処理
  *
  * @param $formFile
  * @return CsvImportService
  */
 protected function getImportData($app, $formFile)
 {
     // アップロードされたCSVファイルを一時ディレクトリに保存
     $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension();
     $formFile->move($app['config']['csv_temp_realdir'], $this->fileName);
     $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName);
     // アップロードされたファイルがUTF-8以外は文字コード変換を行う
     $encode = Str::characterEncoding(substr($file, 0, 6));
     if ($encode != 'UTF-8') {
         $file = mb_convert_encoding($file, 'UTF-8', $encode);
     }
     $file = Str::convertLineFeed($file);
     $tmp = tmpfile();
     fwrite($tmp, $file);
     rewind($tmp);
     $meta = stream_get_meta_data($tmp);
     $file = new \SplFileObject($meta['uri']);
     set_time_limit(0);
     // アップロードされたCSVファイルを行ごとに取得
     $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']);
     $data->setHeaderRowNumber(0);
     return $data;
 }
Exemplo n.º 2
0
 /**
  * タグの登録
  *
  * @param array $row
  * @param Product $Product
  * @param Application $app
  * @param CsvImportService $data
  */
 protected function createProductTag($row, Product $Product, $app, $data)
 {
     // タグの削除
     $ProductTags = $Product->getProductTag();
     foreach ($ProductTags as $ProductTags) {
         $Product->removeProductTag($ProductTags);
         $this->em->remove($ProductTags);
     }
     if ($row['タグ(ID)'] == '') {
         return;
     }
     // タグの登録
     $tags = explode(',', $row['タグ(ID)']);
     foreach ($tags as $tag_id) {
         $Tag = null;
         if (preg_match('/^\\d+$/', $tag_id)) {
             $Tag = $app['eccube.repository.master.tag']->find($tag_id);
             if ($Tag) {
                 $ProductTags = new ProductTag();
                 $ProductTags->setProduct($Product)->setTag($Tag);
                 $Product->addProductTag($ProductTags);
                 $this->em->persist($ProductTags);
             }
         }
         if (!$Tag) {
             $this->addErrors($data->key() + 1 . '行目のタグ(ID)「' . $tag_id . '」が存在しません。');
         }
     }
 }
Exemplo n.º 3
0
 public function testCountDoesNotMoveFilePointer()
 {
     $file = new \SplFileObject(__DIR__ . '/../../../Fixtures/data_column_headers.csv');
     $CsvImportService = new CsvImportService($file);
     $CsvImportService->setHeaderRowNumber(0);
     $key_before_count = $CsvImportService->key();
     $CsvImportService->count();
     $key_after_count = $CsvImportService->key();
     $this->assertEquals($key_after_count, $key_before_count);
 }