Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CSVExport extends ContainerAwareCommand {
- protected function execute(InputInterface $input, OutputInterface $output) {
- $reader = Reader::createFromPath($input->getArgument('localization'));
- $reader->setDelimiter(';');
- $reader->setHeaderOffset(0);
- $results = $reader->getRecords();
- $io->progressStart(iterator_count($results));
- $hour = date('d_m_Y-H_i_s');
- $writer = Writer::createFromPath('%kernel.root_dir%/../src/AppBundle/Rejected/rejected' . $hour . '.csv', 'w+');
- foreach ($results as $row) {
- $year = $row['description'];
- $isValid = false;
- if ($row['qty'] > 0 && $row['price'] > 0 && !empty($row['mpn'])) {
- $isValid = true;
- $year = filter_var($row['description'], FILTER_SANITIZE_NUMBER_INT);
- $product = (new Product())
- ->setMpn($row['mpn'])
- ->setQty($row['qty'])
- ->setYear($rok)
- ->setPrice($row['price']);
- $this->em->persist($product);
- }
- if ($row['qty'] == 0 || $row['price'] == 0 || empty($row['mpn'])) {
- $writer->insertOne([$row['offer_id'],
- $row['mpn'],
- $row['name'],
- $row['producer'],
- $row['price'],
- $row['seller'],
- $row['qty'],
- $row['qty'],
- $row['description']]
- );
- continue;
- }
- }
- $count = count($product);
Add Comment
Please, Sign In to add comment