app/DoctrineMigrations/Version202410140000000.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 Version202410140000000 extends AbstractMigration
  10. {
  11.     const pages = [
  12.         [
  13.             'name' => '商品その他問合せ完了ページ',
  14.             'url' => 'other_complete',
  15.             'file' => 'Contact/other/complete',
  16.         ],
  17.         [
  18.             'name' => 'カタログ問合せ完了ページ',
  19.             'url' => 'catalog_complete',
  20.             'file' => 'Contact/catalog/complete',
  21.         ],
  22.         [
  23.             'name' => 'コーディネイト問合せ完了ページ',
  24.             'url' => 'coordinate_complete',
  25.             'file' => 'Contact/coordinate/complete',
  26.         ],
  27.         [
  28.             'name' => 'ショールーム問合せ完了ページ',
  29.             'url' => 'showroom_complete',
  30.             'file' => 'Contact/showroom/complete',
  31.         ],
  32.     ];
  33.     public function up(Schema $schema): void
  34.     {
  35.         foreach (self::pages as $page) {
  36.             $pageExists $this->connection->fetchOne("SELECT COUNT(*) FROM dtb_page WHERE page_name = '$page[name]'");
  37.             if ($pageExists 0) {
  38.                 continue;
  39.             }
  40.             $sql "INSERT INTO dtb_page SELECT
  41.                 max(id)+1,
  42.                 null,
  43.                 '$page[name]',
  44.                 '$page[url]',
  45.                 '$page[file]',
  46.                 2,
  47.                 null,
  48.                 null,
  49.                 null,
  50.                 CURRENT_TIMESTAMP,
  51.                 CURRENT_TIMESTAMP,
  52.                 null,
  53.                 null,
  54.                 'page'
  55.             FROM dtb_page;";
  56.             $this->addSql($sql);
  57.             $sql "INSERT INTO dtb_page_layout SELECT
  58.                 max(id),
  59.                 2,
  60.                 max(id),
  61.                 'pagelayout'
  62.             FROM dtb_page;";
  63.             $this->addSql($sql);
  64.         }
  65.     }
  66.     public function down(Schema $schema): void
  67.     {
  68.         foreach (self::pages as $page) {
  69.             $sql "DELETE pl FROM dtb_page_layout pl
  70.             LEFT JOIN dtb_page p
  71.             ON pl.page_id = p.id
  72.             WHERE p.page_name = '$page[name]';
  73.             ";
  74.             $this->addSql($sql);
  75.             $sql "DELETE FROM dtb_page
  76.             WHERE page_name = '$page[name]';
  77.             ";
  78.             $this->addSql($sql);
  79.         }
  80.     }
  81. }