<?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 Version20240514064352 extends AbstractMigration
{
const csv_types = [
[
'id' => 6,
'name' => '商品特徴CSV',
],
[
'id' => 7,
'name' => '商品仕様(詳細)CSV',
],
[
'id' => 8,
'name' => '商品よくあるご質問CSV',
],
[
'id' => 9,
'name' => '商品関連特集CSV',
],
];
const csvs = [
// 商品特徴CSV
[
'csv_type_id' => 6,
'entity_name' => 'Customize\\\Entity\\\ProductFeature',
'field_name' => 'id',
'disp_name' => '商品特徴ID',
'sort_no' => 1,
'enabled' => true,
],
[
'csv_type_id' => 6,
'entity_name' => 'Customize\\\Entity\\\ProductFeature',
'field_name' => 'Product',
'reference_field_name' => 'id',
'disp_name' => '商品ID',
'enabled' => true,
],
[
'csv_type_id' => 6,
'entity_name' => 'Customize\\\Entity\\\ProductFeature',
'field_name' => 'Product',
'reference_field_name' => 'name',
'disp_name' => '商品名',
'enabled' => true,
],
[
'csv_type_id' => 6,
'entity_name' => 'Customize\\\Entity\\\ProductFeature',
'field_name' => 'file_name',
'disp_name' => '画像',
'enabled' => true,
],
[
'csv_type_id' => 6,
'entity_name' => 'Customize\\\Entity\\\ProductFeature',
'field_name' => 'caption',
'disp_name' => '見出し',
'enabled' => true,
],
[
'csv_type_id' => 6,
'entity_name' => 'Customize\\\Entity\\\ProductFeature',
'field_name' => 'content',
'disp_name' => '内容',
'enabled' => true,
],
// 商品仕様(詳細)CSV
[
'csv_type_id' => 7,
'entity_name' => 'Customize\\\Entity\\\ProductSpec',
'field_name' => 'id',
'disp_name' => '商品仕様(詳細)ID',
'sort_no' => 1,
'enabled' => true,
],
[
'csv_type_id' => 7,
'entity_name' => 'Customize\\\Entity\\\ProductSpec',
'field_name' => 'Product',
'reference_field_name' => 'id',
'disp_name' => '商品ID',
'enabled' => true,
],
[
'csv_type_id' => 7,
'entity_name' => 'Customize\\\Entity\\\ProductSpec',
'field_name' => 'Product',
'reference_field_name' => 'name',
'disp_name' => '商品名',
'enabled' => true,
],
[
'csv_type_id' => 7,
'entity_name' => 'Customize\\\Entity\\\ProductSpec',
'field_name' => 'title',
'disp_name' => 'タイトル',
'enabled' => true,
],
[
'csv_type_id' => 7,
'entity_name' => 'Customize\\\Entity\\\ProductSpec',
'field_name' => 'content',
'disp_name' => 'スペック詳細',
'enabled' => true,
],
// 商品よくあるご質問CSV
[
'csv_type_id' => 8,
'entity_name' => 'Customize\\\Entity\\\ProductFaq',
'field_name' => 'id',
'disp_name' => '商品よくあるご質問ID',
'sort_no' => 1,
'enabled' => true,
],
[
'csv_type_id' => 8,
'entity_name' => 'Customize\\\Entity\\\ProductFaq',
'field_name' => 'Product',
'reference_field_name' => 'id',
'disp_name' => '商品ID',
'enabled' => true,
],
[
'csv_type_id' => 8,
'entity_name' => 'Customize\\\Entity\\\ProductFaq',
'field_name' => 'Product',
'reference_field_name' => 'name',
'disp_name' => '商品名',
'enabled' => true,
],
[
'csv_type_id' => 8,
'entity_name' => 'Customize\\\Entity\\\ProductFaq',
'field_name' => 'question',
'disp_name' => '質問',
'enabled' => true,
],
[
'csv_type_id' => 8,
'entity_name' => 'Customize\\\Entity\\\ProductFaq',
'field_name' => 'answer',
'disp_name' => '答え',
'enabled' => true,
],
// 商品関連特集CSV
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'id',
'disp_name' => '商品関連特集ID',
'sort_no' => 1,
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'Product',
'reference_field_name' => 'id',
'disp_name' => '商品ID',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'Product',
'reference_field_name' => 'name',
'disp_name' => '商品名',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'file_name',
'disp_name' => '画像',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'alt_text',
'disp_name' => '画像altテキスト',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'category_name',
'disp_name' => 'カテゴリーネーム',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'date',
'disp_name' => '日付',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'title',
'disp_name' => 'タイトル',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'thumb_content',
'disp_name' => '本文サムネイル',
'enabled' => true,
],
[
'csv_type_id' => 9,
'entity_name' => 'Customize\\\Entity\\\ProductRelateFeature',
'field_name' => 'url',
'disp_name' => 'URL',
'enabled' => true,
],
];
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
foreach (self::csv_types as $csv_type) {
$this->addSql(
"INSERT INTO mtb_csv_type (id, name, sort_no, discriminator_type) VALUES (
{$csv_type['id']},
'{$csv_type['name']}',
(SELECT MAX(sort_no) + 1 FROM mtb_csv_type as ct),
'csvtype'
)"
);
}
foreach (self::csvs as $csv) {
$reference_field_name = $csv['reference_field_name'] ?? null;
$sort_no = $csv['sort_no'] ?? "(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";
$this->addSql(
"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 (
{$csv['csv_type_id']},
null,
'{$csv['entity_name']}',
'{$csv['field_name']}',
'{$reference_field_name}',
'{$csv['disp_name']}',
{$sort_no},
1,
NOW(),
NOW(),
'csv'
)"
);
}
}
public function down(Schema $schema): void
{
foreach (self::csvs as $csv) {
$this->addSql(
"DELETE FROM dtb_csv WHERE entity_name = '{$csv['entity_name']}' AND field_name = '{$csv['field_name']}'"
);
}
foreach (self::csv_types as $csv_type) {
$this->addSql(
"DELETE FROM mtb_csv_type WHERE id = {$csv_type['id']}"
);
}
}
}