<?php
declare(strict_types=1);
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* plg_wysiwyg_editor_settingsにschool/のWYSIWYG設定を追加
*/
final class Version20251126000000 extends AbstractMigration
{
public function up(Schema $schema): void
{
// plg_wysiwyg_editor_settingsテーブルが存在するか確認
$tableExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'plg_wysiwyg_editor_settings'"
);
if ($tableExists == 0) {
// テーブルが存在しない場合は処理をスキップ
return;
}
// url_path='school/' and selector='textarea.wysiwyg-area' の組み合わせが存在するか確認
$recordExists = $this->connection->fetchOne(
"SELECT COUNT(*) FROM plg_wysiwyg_editor_settings
WHERE url_path = 'school/' AND selector = 'textarea.wysiwyg-area'"
);
if ($recordExists == 0) {
// 現在の最大IDを取得
$maxId = $this->connection->fetchOne(
"SELECT COALESCE(MAX(id), 0) FROM plg_wysiwyg_editor_settings"
);
$nextId = $maxId + 1;
// レコードを追加
$this->addSql(
"INSERT INTO plg_wysiwyg_editor_settings (id, url_path, selector) VALUES (?, ?, ?)",
[$nextId, 'school/', 'textarea.wysiwyg-area']
);
}
}
public function down(Schema $schema): void
{
// url_path='school/' and selector='textarea.wysiwyg-area' のレコードを削除
$this->addSql(
"DELETE FROM plg_wysiwyg_editor_settings
WHERE url_path = 'school/' AND selector = 'textarea.wysiwyg-area'"
);
}
}