<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version202410140000000 extends AbstractMigration
{
const pages = [
[
'name' => '商品その他問合せ完了ページ',
'url' => 'other_complete',
'file' => 'Contact/other/complete',
],
[
'name' => 'カタログ問合せ完了ページ',
'url' => 'catalog_complete',
'file' => 'Contact/catalog/complete',
],
[
'name' => 'コーディネイト問合せ完了ページ',
'url' => 'coordinate_complete',
'file' => 'Contact/coordinate/complete',
],
[
'name' => 'ショールーム問合せ完了ページ',
'url' => 'showroom_complete',
'file' => 'Contact/showroom/complete',
],
];
public function up(Schema $schema): void
{
foreach (self::pages as $page) {
$pageExists = $this->connection->fetchOne("SELECT COUNT(*) FROM dtb_page WHERE page_name = '$page[name]'");
if ($pageExists > 0) {
continue;
}
$sql = "INSERT INTO dtb_page SELECT
max(id)+1,
null,
'$page[name]',
'$page[url]',
'$page[file]',
2,
null,
null,
null,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
null,
null,
'page'
FROM dtb_page;";
$this->addSql($sql);
$sql = "INSERT INTO dtb_page_layout SELECT
max(id),
2,
max(id),
'pagelayout'
FROM dtb_page;";
$this->addSql($sql);
}
}
public function down(Schema $schema): void
{
foreach (self::pages as $page) {
$sql = "DELETE pl FROM dtb_page_layout pl
LEFT JOIN dtb_page p
ON pl.page_id = p.id
WHERE p.page_name = '$page[name]';
";
$this->addSql($sql);
$sql = "DELETE FROM dtb_page
WHERE page_name = '$page[name]';
";
$this->addSql($sql);
}
}
}