From 770d64a2f881c1f4b68398e8e9b7deafd4aa9cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 28 Jul 2023 13:21:33 +0200 Subject: [PATCH] DX: fix loading of current professions for third parties --- .../migrations/Version20230215175150.php | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/Bundle/ChillThirdPartyBundle/migrations/Version20230215175150.php b/src/Bundle/ChillThirdPartyBundle/migrations/Version20230215175150.php index 2f0765cc9..18b7915f8 100644 --- a/src/Bundle/ChillThirdPartyBundle/migrations/Version20230215175150.php +++ b/src/Bundle/ChillThirdPartyBundle/migrations/Version20230215175150.php @@ -18,18 +18,11 @@ use Doctrine\Migrations\AbstractMigration; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -final class Version20230215175150 extends AbstractMigration implements ContainerAwareInterface +final class Version20230215175150 extends AbstractMigration { - public ContainerInterface $container; - public function __construct(\Doctrine\DBAL\Connection $connection, \Psr\Log\LoggerInterface $logger, private readonly \Doctrine\ORM\EntityManager $entityManager) - { - parent::__construct($connection, $logger); - } - public function down(Schema $schema): void { $this->addSql('ALTER TABLE chill_3party.third_party DROP profession'); - // $this->addSql('ALTER TABLE chill_3party.third_party ADD profession_id INT DEFAULT NULL'); } public function getDescription(): string @@ -37,31 +30,10 @@ final class Version20230215175150 extends AbstractMigration implements Container return 'Change profession to a string field and transfer values'; } - /** - * @return mixed - */ - public function setContainer(?ContainerInterface $container = null) - { - $this->container = $container; - } public function up(Schema $schema): void { $this->addSql('ALTER TABLE chill_3party.third_party ADD profession TEXT DEFAULT \'\' NOT NULL'); - - $em = $this->entityManager; - $professions = $em->getRepository(ThirdPartyProfession::class)->findAll(); - - foreach ($professions as $p) { - $id = $p->getId(); - $name = $p->getName()['fr']; - - $this->addSql( - 'UPDATE chill_3party.third_party SET profession = :profession - WHERE chill_3party.third_party.profession_id = :id;', - ['profession' => $name, 'id' => $id], - ['profession' => Types::STRING, 'id' => Types::INTEGER] - ); - } + $this->addSql('UPDATE chill_3party.third_party SET profession = party_profession.name->>\'fr\' FROM chill_3party.party_profession WHERE party_profession.id = third_party.profession_id') ; } }