app/DoctrineMigrations/Version20241105023843.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 Version20241105023843 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $idLayout $this->connection->fetchOne("SELECT id from dtb_layout WHERE layout_name = :layout_name ", [
  19.             'layout_name' => 'layout previews new',
  20.         ]);
  21.         if(!$idLayout){
  22.             $maxIdPage $this->connection->fetchOne("SELECT MAX(id) AS max_id FROM dtb_page;");
  23.             $maxSortno$this->connection->fetchOne("SELECT MAX(sort_no) AS max_sort_no FROM dtb_page_layout;");
  24.             $newPageId = ++$maxIdPage;
  25.             $newMaxSortno = ++$maxSortno;
  26.             $this->addSql("INSERT INTO `dtb_layout`(`device_type_id`, `layout_name`, `create_date`, `update_date`, `discriminator_type`) VALUES (10, 'layout previews new', NOW(), NOW(), 'layout')");
  27.             $this->addSql("SET @layoutId := (SELECT `id` FROM `dtb_layout` WHERE `layout_name` = 'layout previews new' LIMIT 1)");
  28.             $this->addSql("
  29.                     INSERT INTO dtb_block_position (section, block_id, layout_id, block_row, discriminator_type)
  30.                     VALUES
  31.                         (3, 11, @layoutId, 0, 'blockposition'),
  32.                         (7, 39, @layoutId, 1, 'blockposition'),
  33.                         (7, 43, @layoutId, 2, 'blockposition'),
  34.                         (10, 7, @layoutId, 1, 'blockposition')
  35.                 ");
  36.             $this->addSql(
  37.             "INSERT INTO `dtb_page` (`id`,`master_page_id`, `page_name`, `url`, `file_name`, `edit_type`, `author`, `description`, `keyword`, `create_date`, `update_date`, `meta_robots`, `meta_tags`, `discriminator_type`)
  38.                 VALUES ($newPageId, NULL, 'レンタルしたい着物を無料で確認できる!オンライン下見サービス ', 'online_previews', 'online_previews', 0, null, null, null, NOW() , NOW(), NULL, NULL, 'page') "
  39.             );
  40.             $this->addSql(
  41.             "INSERT INTO `dtb_page_layout` (`page_id`,`layout_id`, `sort_no`, `discriminator_type`)
  42.                 VALUES ($maxIdPage,@layoutId,$newMaxSortno,'pagelayout')"
  43.             );
  44.         }
  45.     }
  46.     public function down(Schema $schema): void
  47.     {
  48.         $idNewPage $this->connection->fetchOne("SELECT id FROM dtb_page WHERE file_name = :file_name", [
  49.             'file_name' => 'online_previews',
  50.         ]);
  51.         if ($idNewPage) {
  52.             $this->addSql("DELETE FROM dtb_page_layout WHERE page_id = :page_id", [
  53.                 'page_id' => $idNewPage,
  54.             ]);
  55.             $this->addSql("DELETE FROM dtb_page WHERE id = :id", [
  56.                 'id' => $idNewPage,
  57.             ]);
  58.         }
  59.         $idLayout $this->connection->fetchOne("SELECT id from dtb_layout WHERE layout_name = :layout_name ", [
  60.             'layout_name' => 'layout previews new',
  61.         ]);
  62.         if($idLayout){
  63.             $this->addSql("DELETE FROM dtb_block_position WHERE layout_id = :layout_id", [
  64.                 'layout_id' => $idLayout,
  65.             ]);
  66.             $this->addSql("DELETE FROM dtb_layout WHERE id = :layout_id", [
  67.                 'layout_id' => $idLayout,
  68.             ]);
  69.         }
  70.     }
  71. }