app/DoctrineMigrations/Version20240702100030.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 Version20240702100030 extends AbstractMigration
  10. {
  11.     const pages = [
  12.         [
  13.             'name' => 'ご利用ガイド詳細',
  14.             'url' => 'guide_detail',
  15.             'file' => 'guide_detail',
  16.         ],
  17.     ];
  18.     public function up(Schema $schema): void
  19.     {
  20.         foreach (self::pages as $page) {
  21.             $pageExists $this->connection->fetchOne("SELECT COUNT(*) FROM dtb_page WHERE page_name = '$page[name]'");
  22.             if ($pageExists 0) {
  23.                 continue;
  24.             }
  25.             $sql "INSERT INTO dtb_page SELECT
  26.                 max(id)+1,
  27.                 null,
  28.                 '$page[name]',
  29.                 '$page[url]',
  30.                 '$page[file]',
  31.                 0,
  32.                 null,
  33.                 null,
  34.                 null,
  35.                 CURRENT_TIMESTAMP,
  36.                 CURRENT_TIMESTAMP,
  37.                 null,
  38.                 null,
  39.                 'page'
  40.             FROM dtb_page;";
  41.             $this->addSql($sql);
  42.             $sql "INSERT INTO dtb_page_layout SELECT
  43.                 max(id),
  44.                 2,
  45.                 max(id),
  46.                 'pagelayout'
  47.             FROM dtb_page;";
  48.             $this->addSql($sql);
  49.         }
  50.     }
  51.     public function down(Schema $schema): void
  52.     {
  53.         foreach (self::pages as $page) {
  54.             $sql "DELETE pl FROM dtb_page_layout pl
  55.             LEFT JOIN dtb_page p
  56.             ON pl.page_id = p.id
  57.             WHERE p.page_name = '$page[name]';
  58.             ";
  59.             $this->addSql($sql);
  60.             $sql "DELETE FROM dtb_page
  61.             WHERE page_name = '$page[name]';
  62.             ";
  63.             $this->addSql($sql);
  64.         }
  65.     }
  66. }