ImportTrait
blog 投入処理の共通ロジック。
Import (単発 bin → 単一 blog) と MultiBlogImport (複数 bin → 複数 blog)
の両方で共有される処理を集約する。ID マッピングの採番方式 (prepareIds) は
各クラスが個別に実装する。
役割:
- yaml parse / dropData / insertData / generateFulltext / updateBlogConfigSet
- getNewID による旧ID→新IDの解決
- 各テーブル向けの fix 系コールバック (categoryFix / entryFix / columnFix 等)
取り扱う $this 状態:
- $blogId: 投入対象 blog_id
- $userId: 実行者 user_id (entry_last_update_user_id 等で利用)
- $yaml: 入力 yaml をパースした連想配列
- $ids: 旧ID→新IDのマッピング (各テーブル別)
- $errors: 投入中に発生したエラーメッセージ
- $mediaFieldFix: field 投入後に media id を再リンクする情報
Table of Contents
Properties
- $blogId : int
- $errors : array<string|int, mixed>
- $ids : array<string|int, mixed>
- $mediaFieldFix : array<string|int, mixed>
- $userId : int
- $yaml : array<string|int, mixed>
- $categoryIdConfigKeys : array<string|int, string>
- カテゴリーIDを値として保持する config キー。 管理画面のカテゴリー選択UI(js-admin-category-select)に紐づくキーが対象。
- $mediaIdConfigKeys : array<string|int, string>
- メディアIDを値として保持する config キー。
Methods
- dropData() : void
- 投入先 blog の既存データを削除する (破壊リプレース用)。
- executeImport() : array<string|int, mixed>
- yaml を実際に投入する。
- prepareIds() : void
- `$this->ids` を投入前に整える。
- rewriteBlogIdInYaml() : string
- yaml 内の各テーブルの `<table>_blog_id` を指定 blog_id で書き換える。
- categoryFix() : mixed
- clearTable() : void
- columnFix() : mixed
- configFix() : mixed
- entry_sub_categoryFix() : mixed
- This method is called dynamically via call_user_func_array().
- entryFix() : mixed
- existsYaml() : bool
- fieldFix() : mixed
- fix() : mixed
- 旧IDを新IDに解決する共通の fix。フィールド名のサフィックスを見て、対応するテーブルの ID マップを引く。
- fixBlockEditorMedia() : string
- fulltextFix() : mixed
- generateFulltext() : void
- geoFix() : mixed
- This method is called dynamically via call_user_func_array().
- getNewID() : int|string
- 旧IDを新IDに解決する。マッピングが存在しない場合は元の値をそのまま返す。 unit_delimiter で区切られた複数IDのケースにも対応。
- insertData() : void
- layout_gridFix() : mixed
- moduleFix() : mixed
- recordExists() : bool
- yaml レコードが持つ旧 <table>_id を新 ID にマッピングし、 同じ新 ID のレコードが既に DB に存在するか確認する。
- ruleFix() : mixed
- updateBlogConfigSet() : void
- yaml の各 blog レコードに含まれる config_set / theme_set / editor_set 系 ID を、 対応する blog テーブルレコードに UPDATE で反映する。
- updateOneBlogConfigSet() : void
Properties
$blogId
public
int
$blogId
$errors
public
array<string|int, mixed>
$errors
$ids
public
array<string|int, mixed>
$ids
$mediaFieldFix
public
array<string|int, mixed>
$mediaFieldFix
$userId
public
int
$userId
$yaml
public
array<string|int, mixed>
$yaml
$categoryIdConfigKeys
カテゴリーIDを値として保持する config キー。 管理画面のカテゴリー選択UI(js-admin-category-select)に紐づくキーが対象。
private
static array<string|int, string>
$categoryIdConfigKeys
= ['entry_edit_category_default', 'entry_edit_category_filter', 'entry_edit_sub_category_filter', 'static_page_cid', 'static_archive_cid']
(PHP 8.1 互換維持のため trait const ではなく static プロパティで保持する)
$mediaIdConfigKeys
メディアIDを値として保持する config キー。
private
static array<string|int, string>
$mediaIdConfigKeys
= ['media_banner_mid', 'navigation_media']
Methods
dropData()
投入先 blog の既存データを削除する (破壊リプレース用)。
protected
dropData() : void
呼び出し前に $this->blogId を投入先 blog_id にセットしておく必要がある。
executeImport()
yaml を実際に投入する。
protected
executeImport(string $yaml, int $blogId, int $userId) : array<string|int, mixed>
前提:
- yaml 内の