Files
myep-team/migrations/Version20240716063200.php
T

62 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use App\Entity\Assignment;
use App\Repository\AssignmentRepository;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240716063200 extends AbstractMigration implements ContainerAwareInterface
{
private ContainerInterface $container;
public function getDescription(): string
{
return '';
}
public function setContainer(?ContainerInterface $container): void
{
$this->container = $container;
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE assignment ADD staffing_status VARCHAR(64) NOT NULL');
}
public function postUp(Schema $schema): void
{
$entityManager = $this->container->get('doctrine.orm.entity_manager');
$assignmentRepository = $entityManager->getRepository(Assignment::class);
$assignments = $assignmentRepository->findAll();
foreach ($assignments as $assignment) {
if (Assignment::STATUS_DRAFT === $assignment->getStatus() || null !== $assignment->getDeletedAt()) {
continue;
}
$assignment->updateStaffingStatus();
}
$entityManager->flush();
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE assignment DROP staffing_status');
}
}