app/DoctrineMigrations/Version20231121123506.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20231121123506 extends AbstractMigration
  10. {
  11.     private $idToInsert 20;
  12.     public function getDescription(): string
  13.     {
  14.         return '';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         // Check if ID already exists or not
  19.         $idExists $this->isIdExists($this->idToInsert);
  20.         
  21.         if (!$idExists) {
  22.             $this->addSql("INSERT INTO `dtb_mail_template` (`id`, `creator_id`, `name`, `file_name`, `mail_subject`, `create_date`, `update_date`, `discriminator_type`) VALUES ($this->idToInsert, NULL, '注文受付メール(宅配レンタル)', 'Mail/order.twig', 'ご注文ありがとうございます(自動返信メール)', '2023-11-21 12:38:34.000000', '2023-11-21 12:38:34.000000', 'mailtemplate')");
  23.         }
  24.     }
  25.     public function down(Schema $schema): void
  26.     {
  27.         $this->addSql("DELETE FROM `dtb_mail_template` where id = $this->idToInsert");
  28.     }
  29.     private function isIdExists(int $id): bool
  30.     {
  31.         try {
  32.             $result $this->connection->fetchOne("SELECT id FROM dtb_mail_template WHERE id = :id", ['id' => $id]);
  33.             return $result !== false;
  34.         } catch (\Exception $e) {
  35.             return false;
  36.         }
  37.     }
  38. }