app/DoctrineMigrations/Version20240525000900.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 Version20240525000900 extends AbstractMigration
  10. {
  11.     const csvs = [
  12.         [
  13.             'csv_type_id' => 1,
  14.             'entity_name' => 'Eccube\\\Entity\\\Product',
  15.             'field_name' => 'ProductImage',
  16.             'reference_field_name' => 'alt_text',
  17.             'disp_name' => '商品画像altテキスト',
  18.             'enabled' => true,
  19.         ],
  20.     ];
  21.     public function getDescription(): string
  22.     {
  23.         return '';
  24.     }
  25.     public function up(Schema $schema): void
  26.     {
  27.         foreach (self::csvs as $csv) {
  28.             $reference_field_name $csv['reference_field_name'] ?? null;
  29.             $this->addSql(
  30.                 "INSERT INTO dtb_csv (csv_type_id, creator_id, entity_name, field_name, reference_field_name, disp_name, sort_no, enabled, create_date, update_date, discriminator_type) VALUES (
  31.                     {$csv['csv_type_id']},
  32.                     null,
  33.                     '{$csv['entity_name']}',
  34.                     '{$csv['field_name']}',
  35.                     '{$reference_field_name}',
  36.                     '{$csv['disp_name']}',
  37.                     (SELECT c.sort_no FROM dtb_csv as c WHERE c.csv_type_id = {$csv['csv_type_id']} ORDER BY c.sort_no DESC LIMIT 1) + 1,
  38.                     1,
  39.                     NOW(),
  40.                     NOW(),
  41.                     'csv'
  42.                 )"
  43.             );
  44.         }
  45.     }
  46.     public function down(Schema $schema): void
  47.     {
  48.         foreach (self::csvs as $csv) {
  49.             $this->addSql(
  50.                 "DELETE FROM dtb_csv WHERE entity_name = '{$csv['entity_name']}' AND field_name = '{$csv['field_name']}' AND reference_field_name = '{$csv['reference_field_name']}'"
  51.             );
  52.         }
  53.     }
  54. }