Guest User

Untitled

a guest
Jan 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. class CSVExport extends ContainerAwareCommand {
  2.  
  3. protected function execute(InputInterface $input, OutputInterface $output) {
  4.  
  5. $reader = Reader::createFromPath($input->getArgument('localization'));
  6. $reader->setDelimiter(';');
  7. $reader->setHeaderOffset(0);
  8.  
  9. $results = $reader->getRecords();
  10.  
  11. $io->progressStart(iterator_count($results));
  12.  
  13. $hour = date('d_m_Y-H_i_s');
  14.  
  15. $writer = Writer::createFromPath('%kernel.root_dir%/../src/AppBundle/Rejected/rejected' . $hour . '.csv', 'w+');
  16.  
  17. foreach ($results as $row) {
  18.  
  19. $year = $row['description'];
  20.  
  21. $isValid = false;
  22.  
  23. if ($row['qty'] > 0 && $row['price'] > 0 && !empty($row['mpn'])) {
  24.  
  25. $isValid = true;
  26.  
  27. $year = filter_var($row['description'], FILTER_SANITIZE_NUMBER_INT);
  28.  
  29. $product = (new Product())
  30. ->setMpn($row['mpn'])
  31. ->setQty($row['qty'])
  32. ->setYear($rok)
  33. ->setPrice($row['price']);
  34.  
  35. $this->em->persist($product);
  36. }
  37. if ($row['qty'] == 0 || $row['price'] == 0 || empty($row['mpn'])) {
  38.  
  39. $writer->insertOne([$row['offer_id'],
  40. $row['mpn'],
  41. $row['name'],
  42. $row['producer'],
  43. $row['price'],
  44. $row['seller'],
  45. $row['qty'],
  46. $row['qty'],
  47. $row['description']]
  48. );
  49. continue;
  50. }
  51. }
  52.  
  53. $count = count($product);
Add Comment
Please, Sign In to add comment