migrations/Version20240404132642DataUpdate.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\Entity\Workflow\Action;
  5. use App\Entity\Workflow\Trigger;
  6. use Doctrine\DBAL\Schema\Schema;
  7. use Doctrine\Migrations\AbstractMigration;
  8. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  9. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  10. /**
  11.  * Auto-generated Migration: Please modify to your needs!
  12.  */
  13. final class Version20240404132642DataUpdate extends AbstractMigration implements ContainerAwareInterface
  14. {
  15.     use ContainerAwareTrait;
  16.     private $triggers = [
  17.         [
  18.             'name' => Trigger::TRIGGER_PROJECT_STATUS_REACHED,
  19.             'visibleName' => 'Project status reached',
  20.             'operation' => 'Run actions when project reched status',
  21.             'description' => 'Description about project status reached.',
  22.         ],
  23.         [
  24.             'name' => Trigger::TRIGGER_PROJECT_STATUS_FINISHED,
  25.             'visibleName' => 'Project status finished',
  26.             'operation' => 'Run actions when project finished status',
  27.             'description' => 'Description about project status finished.',
  28.         ],
  29.         [
  30.             'name' => Trigger::TRIGGER_BEFORE_DEADLINE,
  31.             'visibleName' => 'Before deadline',
  32.             'operation' => 'Run actions X time before deadline',
  33.             'description' => 'Description about before deadline.',
  34.         ],
  35.         [
  36.             'name' => Trigger::TRIGGER_DEADLINE_REACHED,
  37.             'visibleName' => 'Deadline reached',
  38.             'operation' => 'Run actions when project reached deadline.',
  39.             'description' => 'Description about before deadline.',
  40.         ],
  41.         [
  42.             'name' => Trigger::TRIGGER_AFTER_DEADLINE,
  43.             'visibleName' => 'After deadline',
  44.             'operation' => 'Run actions X time after deadline',
  45.             'description' => 'Description about after deadline.',
  46.         ],
  47.     ];
  48.     private $actions = [
  49.         [
  50.             'name' => Action::ACTION_EMAIL_TO_CLIENT,
  51.             'visibleName' => 'Email to client',
  52.             'operation' => 'Send an e-mail to the specified client X time after triggering',
  53.             'description' => 'Description about ACTION_EMAIL_TO_CLIENT.',
  54.         ],
  55.         [
  56.             'name' => Action::ACTION_EMAIL_TO_EXTERNAL_PARTY,
  57.             'visibleName' => 'Email to external party',
  58.             'operation' => 'Send an e-mail to the external party X time after triggering',
  59.             'description' => 'Description about ACTION_EMAIL_TO_EXTERNAL_PARTY.',
  60.         ],
  61.         [
  62.             'name' => Action::ACTION_EMAIL_TO_PROJECT_MANAGER,
  63.             'visibleName' => 'Email to project manager',
  64.             'operation' => 'Send an e-mail to the project manager X time after triggering',
  65.             'description' => 'Description about ACTION_EMAIL_TO_PROJECT_MANAGER.',
  66.         ],
  67.         [
  68.             'name' => Action::ACTION_EMAIL_TO_ADMIN,
  69.             'visibleName' => 'Email to admin',
  70.             'operation' => 'Send an e-mail to the admins X time after triggering',
  71.             'description' => 'Description about ACTION_EMAIL_TO_ADMIN.',
  72.         ],
  73.         [
  74.             'name' => Action::ACTION_CHANGE_PROJECT_STATUS,
  75.             'visibleName' => 'Change project status',
  76.             'operation' => 'Change project from X status to Y status',
  77.             'description' => 'Description about ACTION_CHANGE_PROJECT_STATUS.',
  78.         ],
  79.     ];
  80.     public function getDescription(): string
  81.     {
  82.         return '';
  83.     }
  84.     public function up(Schema $schema): void
  85.     {
  86.         // this up() migration is auto-generated, please modify it to your needs
  87.         $entityManager $this->container->get('doctrine.orm.entity_manager');
  88.         foreach ($this->triggers as $trigger) {
  89.             $newTrigger = new Trigger();
  90.             $newTrigger->setName($trigger['name']);
  91.             $newTrigger->setVisibleName($trigger['visibleName']);
  92.             $newTrigger->setOperation($trigger['operation']);
  93.             $newTrigger->setDescription($trigger['description']);
  94.             $entityManager->persist($newTrigger);
  95.         }
  96.         foreach ($this->actions as $action) {
  97.             $newAction = new Action();
  98.             $newAction->setName($action['name']);
  99.             $newAction->setVisibleName($action['visibleName']);
  100.             $newAction->setOperation($action['operation']);
  101.             $newAction->setDescription($action['description']);
  102.             $entityManager->persist($newAction);
  103.         }
  104.         $entityManager->flush();
  105.     }
  106.     public function down(Schema $schema): void
  107.     {
  108.     }
  109. }