<?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 Version20240624204253 extends AbstractMigration
{
const pages = [
[
'name' => '海洋散骨',
'url' => 'sea_burial',
'file' => 'sea_burial',
]
];
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);
}
}
}