mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
DX: fix loading of current professions for third parties
This commit is contained in:
parent
34c46f23e3
commit
770d64a2f8
@ -18,18 +18,11 @@ use Doctrine\Migrations\AbstractMigration;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
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
|
public function down(Schema $schema): void
|
||||||
{
|
{
|
||||||
$this->addSql('ALTER TABLE chill_3party.third_party DROP profession');
|
$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
|
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 '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
|
public function up(Schema $schema): void
|
||||||
{
|
{
|
||||||
$this->addSql('ALTER TABLE chill_3party.third_party ADD profession TEXT DEFAULT \'\' NOT NULL');
|
$this->addSql('ALTER TABLE chill_3party.third_party ADD profession TEXT DEFAULT \'\' NOT NULL');
|
||||||
|
$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') ;
|
||||||
$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]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user