protected function loadQuotesFromOldDatabase() { $em = $this->getContainer()->get('doctrine')->getManager('default'); $emLegacy = $this->getContainer()->get('doctrine')->getManager('legacy'); $oldQuotes = $emLegacy->getRepository('GaropiLegacyWrapperBundle:AdminQuotations')->findAll(); /** @var AdminQuotations $oldQuote */ foreach ($oldQuotes as $oldQuote) { $content = $oldQuote->getContent(); $authorName = $oldQuote->getAuthor(); $createdAt = new \DateTime($oldQuote->getCreatedAt()); $updatedAt = new \DateTime($oldQuote->getUpdatedAt()); $quote = new Quote(); $quote->setAuthorName($authorName); $quote->setContent($content); $quote->setCreatedAt($createdAt); $quote->setUpdatedAt($updatedAt); $em->persist($quote); $em->flush(); } }
private function loadQuotes(ObjectManager $manager) { for ($i = 1; $i <= 10; $i++) { $quote = new Quote(); $quote->setQuote($this->getRandomQuote()); $quote->setAuthor($this->getRandomQuoteAuthor()); $manager->persist($quote); } $manager->flush(); }