app/DoctrineMigrations/Version20251126000000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of EC-CUBE
  5.  *
  6.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  7.  *
  8.  * http://www.ec-cube.co.jp/
  9.  *
  10.  * For the full copyright and license information, please view the LICENSE
  11.  * file that was distributed with this source code.
  12.  */
  13. namespace DoctrineMigrations;
  14. use Doctrine\DBAL\Schema\Schema;
  15. use Doctrine\Migrations\AbstractMigration;
  16. /**
  17.  * plg_wysiwyg_editor_settingsにschool/のWYSIWYG設定を追加
  18.  */
  19. final class Version20251126000000 extends AbstractMigration
  20. {
  21.     public function up(Schema $schema): void
  22.     {
  23.         // plg_wysiwyg_editor_settingsテーブルが存在するか確認
  24.         $tableExists $this->connection->fetchOne(
  25.             "SELECT COUNT(*) FROM information_schema.TABLES 
  26.              WHERE TABLE_SCHEMA = DATABASE() 
  27.              AND TABLE_NAME = 'plg_wysiwyg_editor_settings'"
  28.         );
  29.         
  30.         if ($tableExists == 0) {
  31.             // テーブルが存在しない場合は処理をスキップ
  32.             return;
  33.         }
  34.         
  35.         // url_path='school/' and selector='textarea.wysiwyg-area' の組み合わせが存在するか確認
  36.         $recordExists $this->connection->fetchOne(
  37.             "SELECT COUNT(*) FROM plg_wysiwyg_editor_settings 
  38.              WHERE url_path = 'school/' AND selector = 'textarea.wysiwyg-area'"
  39.         );
  40.         
  41.         if ($recordExists == 0) {
  42.             // 現在の最大IDを取得
  43.             $maxId $this->connection->fetchOne(
  44.                 "SELECT COALESCE(MAX(id), 0) FROM plg_wysiwyg_editor_settings"
  45.             );
  46.             
  47.             $nextId $maxId 1;
  48.             
  49.             // レコードを追加
  50.             $this->addSql(
  51.                 "INSERT INTO plg_wysiwyg_editor_settings (id, url_path, selector) VALUES (?, ?, ?)",
  52.                 [$nextId'school/''textarea.wysiwyg-area']
  53.             );
  54.         }
  55.     }
  56.     public function down(Schema $schema): void
  57.     {
  58.         // url_path='school/' and selector='textarea.wysiwyg-area' のレコードを削除
  59.         $this->addSql(
  60.             "DELETE FROM plg_wysiwyg_editor_settings 
  61.              WHERE url_path = 'school/' AND selector = 'textarea.wysiwyg-area'"
  62.         );
  63.     }
  64. }