migrations/Version20240924191959.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\SeoBundle\Entity\Seo;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. use PN\SeoBundle\Entity\SeoBaseRoute;
  8. use PN\SeoBundle\Entity\SeoPage;
  9. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  10. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  11. /**
  12. * Auto-generated Migration: Please modify to your needs!
  13. */
  14. final class Version20240924191959 extends AbstractMigration implements ContainerAwareInterface
  15. {
  16. use ContainerAwareTrait;
  17. public function getDescription(): string
  18. {
  19. return '';
  20. }
  21. public function up(Schema $schema): void
  22. {
  23. // this up() migration is auto-generated, please modify it to your needs
  24. }
  25. public function postUp(Schema $schema): void
  26. {
  27. $this->newSeo('Brands', 'Brands', 'brands', 'brands');
  28. }
  29. private function newSeo($seoPageTitle, $seoTitle, $seoPageType, $seoSlug): void
  30. {
  31. //getting entity manager
  32. $em = $this->container->get('doctrine.orm.entity_manager');
  33. $seoPage = new SeoPage();
  34. $seoPage->setTitle($seoPageTitle);
  35. $seoPage->setType($seoPageType);
  36. $seoPage->setCreated(new \DateTime());
  37. $seoPage->setCreator('System');
  38. $seoPage->setModified(new \DateTime());
  39. $seoPage->setModifiedBy('System');
  40. $seo = new Seo();
  41. $seo->setSeoBaseRoute($em->getRepository(SeoBaseRoute::class)->findByEntity($seoPage));
  42. $seo->setTitle($seoTitle);
  43. $seo->setSlug($seoSlug);
  44. $seo->setState(1);
  45. $seo->setLastModified(new \DateTime());
  46. $seoPage->setSeo($seo);
  47. $em->persist($seoPage);
  48. $em->persist($seo);
  49. $em->flush();
  50. }
  51. public function down(Schema $schema): void
  52. {
  53. // this down() migration is auto-generated, please modify it to your needs
  54. }
  55. }