/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getContainer()->get('doctrine')->getManager(); $parser = $this->getContainer()->get('lke_core.parse_csv'); $rows = $parser->parse(self::FILE); foreach ($rows as $row) { $post = new Post(); $post->setTitle($row[self::TITLE]); $post->setContent($row[self::CONTENT]); $post->setPublishedAt($this->getDateTime($row[self::PUBLISHED_AT])); $post->setAuthor($this->getAuthor($row[self::AUTHOR])); $post->setCategory($this->getCategory($row[self::CATEGORY])); $post->setImage($this->getImage($row[self::IMAGE])); $tagsId = explode(';', $row[self::TAGS]); foreach ($tagsId as $tagId) { $tag = $this->getTag($tagId); if (!is_null($tag)) { $post->addTag($this->getTag($tagId)); } } $em->persist($post); } $em->flush(); $output->writeln("Posts loaded"); }