a-blog cms PHP API Reference

Import
in package
uses ImportTrait

単一 bin → 単一 blog への yaml 投入を実行する。

用途: ACMS_POST_Backup_BlogImport 等、単発でブログをインポートする呼び出し。 (複数 bin の同時投入は MultiBlogImport を使う)

共通処理は ImportTrait に集約。本クラスの責務は:

  • 入力 yaml 1 本から ID マップを採番する prepareIds() の実装
  • 公開メソッド run($bid, $yaml) の薄いラッパー

Table of Contents

Properties

$blogId  : int
$blogIdMap  : array<int, int>
$blogOwnOldId  : array<int, 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 キー。 管理画面のカテゴリー選択カスタム要素(acms-category-select)に紐づくキーが対象。
$importedTables  : array<string|int, string>
executeImport が投入対象とするテーブル一覧。
$mediaIdConfigKeys  : array<string|int, string>
メディアIDを値として保持する config キー。
$selfReferencingBlogIdTables  : array<string|int, string>
`_bid` カラムが「自ブログ自身」を指す多態関連カラムであるテーブル。

Methods

run()  : array<string|int, mixed>
dropData()  : void
投入先 blog の既存データを削除する (破壊リプレース用)。
executeImport()  : array<string|int, mixed>
yaml を実際に投入する。
prepareIds()  : void
単発 import では「入力 yaml 1 本のみ」から ID を採番する。
rewriteBlogIdInYaml()  : string
yaml 内の各テーブルの `<table>_blog_id` を指定 blog_id で書き換える。
categoryFix()  : mixed
clearTable()  : void
columnFix()  : mixed
configFix()  : mixed
convertBlockEditorAuthoringHtml()  : string
本文中の入稿用タグ(`<acms-block-editor-html-block>` / `<acms-block-editor-embed-block>`)を機能タグへ変換する
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
isValidBlogId()  : bool
`_bid` カラムの値が有効なブログIDか(= そのレコードがブログスコープである)を判定する。 null / 空文字 / 0 / "0" は「ブログには属さない(entry/category/user 等スコープ)」を意味する。
layout_gridFix()  : mixed
moduleFix()  : mixed
recordExists()  : bool
yaml レコードが持つ旧 <table>_id を新 ID にマッピングし、 同じ新 ID のレコードが既に DB に存在するか確認する。
registerCategoryNewId()  : void
カテゴリーIDの新規マッピング。同名コードが既存ブログに存在する場合は再利用、 無い場合のみ nextval で新規採番する (旧 setup/lib/import.php と同じセマンティクス)。
registerNewIDsForTable()  : void
resolveModuleBid()  : mixed
module_bid (module_bid_axis が self 以外なら他ブログを指しうる自由記述カラム) を解決する。
ruleFix()  : mixed
selfReferencingBlogIdColumn()  : string|null
`<table>_blog_id` と同様に「自ブログ自身」を指す多態関連カラム名を返す (対象外テーブルは null)。
updateBlogConfigSet()  : void
yaml の各 blog レコードに含まれる config_set / theme_set / editor_set 系 ID を、 対応する blog テーブルレコードに UPDATE で反映する。
updateOneBlogConfigSet()  : void

Properties

$blogIdMap

protected array<int, int> $blogIdMap = []

$blogOwnOldId

protected array<int, int> $blogOwnOldId = []

$errors

protected array<string|int, mixed> $errors

$ids

protected array<string|int, mixed> $ids

$mediaFieldFix

protected array<string|int, mixed> $mediaFieldFix = []

$yaml

protected array<string|int, mixed> $yaml

$categoryIdConfigKeys

カテゴリーIDを値として保持する config キー。 管理画面のカテゴリー選択カスタム要素(acms-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 プロパティで保持する)

$importedTables

executeImport が投入対象とするテーブル一覧。

private static array<string|int, string> $importedTables = ['category', 'form', 'entry', 'tag', 'entry_sub_category', 'module', 'layout_grid', 'rule', 'config', 'column', 'config_set', 'dashboard', 'field', 'media', 'media_tag', 'geo']

$mediaIdConfigKeys

メディアIDを値として保持する config キー。

private static array<string|int, string> $mediaIdConfigKeys = ['media_banner_mid', 'navigation_media']

$selfReferencingBlogIdTables

`_bid` カラムが「自ブログ自身」を指す多態関連カラムであるテーブル。

private static array<string|int, string> $selfReferencingBlogIdTables = ['field', 'geo']

field_bid / geo_bid は FieldFacade::save() / saveGeometry()(ACMS/POST/Blog/Insert.php / Update.php 経由)から常に自ブログ自身の ID として書き込まれるため、投入先 blog_id へ単純に 書き換えてよい。一方 module_bid(axis が self 以外なら他ブログを指せる)や rule_bid(比較条件の値で エンティティ参照ではない)は対象外(CMS-7830)。

Methods

run()

public run(string $yaml, int $blogId, int $userId) : array<string|int, mixed>
Parameters
$yaml : string

投入する yaml 文字列

$blogId : int

投入対象 blog_id

$userId : int

entry_last_update_user_id 等で使う実行者 user_id

Return values
array<string|int, mixed> —

エラーメッセージの一覧

dropData()

投入先 blog の既存データを削除する (破壊リプレース用)。

protected dropData() : void

呼び出し前に $this->blogId を投入先 blog_id にセットしておく必要がある。

executeImport()

yaml を実際に投入する。

protected executeImport(string $yaml, int $blogId, int $userId) : array<string|int, mixed>

前提:

  • yaml 内の _blog_id は呼び出し側が事前に正しい値に書き換え済み
  • 投入先 blog の既存データを破壊リプレースする場合、呼び出し側が事前に dropData() を呼ぶ
  • Parameters
    $yaml : string

    投入する yaml 文字列 (<table>_blog_id は確定済)

    $blogId : int

    投入対象 blog_id (generateFulltext / updateBlogConfigSet で利用)

    $userId : int

    entry_last_update_user_id 等で使う実行者 user_id

    Return values
    array<string|int, mixed> —

    エラーメッセージの一覧 (空なら成功)

    prepareIds()

    単発 import では「入力 yaml 1 本のみ」から ID を採番する。

    protected prepareIds() : void

    rewriteBlogIdInYaml()

    yaml 内の各テーブルの `<table>_blog_id` を指定 blog_id で書き換える。

    protected rewriteBlogIdInYaml(string $yaml, int $blogId) : string

    呼び出し側 (Import::run) が executeImport に渡す前の正規化に使う。 MultiBlogImport は別途 mergeBlogYaml で同等の処理を行うため、これは呼ばない。

    Parameters
    $yaml : string
    $blogId : int
    Return values
    string

    categoryFix()

    private categoryFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    clearTable()

    private clearTable(string $table) : void
    Parameters
    $table : string

    columnFix()

    private columnFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    configFix()

    private configFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    convertBlockEditorAuthoringHtml()

    本文中の入稿用タグ(`<acms-block-editor-html-block>` / `<acms-block-editor-embed-block>`)を機能タグへ変換する

    private convertBlockEditorAuthoringHtml(string $value) : string

    埋め込みを解決できなかった URL は通常リンクの段落へ退避し、インポート自体は失敗させずにログへ残す。

    Parameters
    $value : string
    Return values
    string

    entry_sub_categoryFix()

    This method is called dynamically via call_user_func_array().

    private entry_sub_categoryFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>
    Tags
    phpstan-ignore-next-line

    entryFix()

    private entryFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    existsYaml()

    private existsYaml(string $table) : bool
    Parameters
    $table : string
    Return values
    bool

    fieldFix()

    private fieldFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    fix()

    旧IDを新IDに解決する共通の fix。フィールド名のサフィックスを見て、対応するテーブルの ID マップを引く。

    private fix(string $table, string $field, mixed $value) : mixed
    Parameters
    $table : string
    $field : string
    $value : mixed

    fixBlockEditorMedia()

    private fixBlockEditorMedia(string $value) : string
    Parameters
    $value : string
    Return values
    string

    fulltextFix()

    private fulltextFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    generateFulltext()

    private generateFulltext() : void

    geoFix()

    This method is called dynamically via call_user_func_array().

    private geoFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>
    Tags
    phpstan-ignore-next-line

    getNewID()

    旧IDを新IDに解決する。マッピングが存在しない場合は元の値をそのまま返す。 unit_delimiter で区切られた複数IDのケースにも対応。

    private getNewID(string $table, int|string $id) : int|string

    該当しない値 (テンプレート変数 %{RCID} のようなプレースホルダー文字列等) は 解決対象外として元の値をそのまま返す。

    Parameters
    $table : string
    $id : int|string
    Return values
    int|string

    insertData()

    private insertData(string $table) : void
    Parameters
    $table : string

    isValidBlogId()

    `_bid` カラムの値が有効なブログIDか(= そのレコードがブログスコープである)を判定する。 null / 空文字 / 0 / "0" は「ブログには属さない(entry/category/user 等スコープ)」を意味する。

    private static isValidBlogId(mixed $value) : bool
    Parameters
    $value : mixed
    Return values
    bool

    layout_gridFix()

    private layout_gridFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    moduleFix()

    private moduleFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    recordExists()

    yaml レコードが持つ旧 <table>_id を新 ID にマッピングし、 同じ新 ID のレコードが既に DB に存在するか確認する。

    private recordExists(string $table, array<string|int, mixed> $record) : bool

    自前 ID を持たないテーブル (tag, media_tag, field, geo 等) は対象外で、 常に false を返す (= INSERT を試行する)。

    Parameters
    $table : string
    $record : array<string|int, mixed>
    Return values
    bool

    registerCategoryNewId()

    カテゴリーIDの新規マッピング。同名コードが既存ブログに存在する場合は再利用、 無い場合のみ nextval で新規採番する (旧 setup/lib/import.php と同じセマンティクス)。

    private registerCategoryNewId() : void

    親IDでソートしてから処理することで、子の親参照が必ず解決済みになる。

    registerNewIDsForTable()

    private registerNewIDsForTable(string $table) : void
    Parameters
    $table : string

    resolveModuleBid()

    module_bid (module_bid_axis が self 以外なら他ブログを指しうる自由記述カラム) を解決する。

    private resolveModuleBid(mixed $value, array<string, mixed> $record) : mixed

    参照先は「自ブログ自身」と「他bin (兄弟blog)」の2パターンに分かれ、扱いが異なる。

    • 自己参照: レコード自身の module_blog_id は mergeBlogYaml/rewriteBlogIdInYaml で既に 自ブログの新IDへ書き換え済みなので、$blogOwnOldId (新blog_id→旧blog_id) で逆引きした 値と一致すれば、他binの旧IDと衝突していても常に安全に自分自身へ解決できる。
    • 他bin参照: $blogIdMap (旧blog_id→新blog_id) で解決するが、複数binが同じ旧blog_idを 名乗った場合はどちらを指しているか数値だけからは判別できないため、その旧IDは $blogIdMap から除外済み (どちらのbinの参照も解決せず素通しする)。

    単一値・カンマ区切りの複数値・%{BID} 等の実行時プレースホルダー文字列いずれもあり得るため、 カンマ分割した要素ごとに上記いずれかで解決し、それ以外 (マッピング範囲外の旧ID・曖昧な旧ID・ プレースホルダー文字列) は元の値をそのまま残す (CMS-5855 で導入された「解決不能なら素通し」 フォールバックを維持しつつ、解決可能な分だけ解決する)。

    Parameters
    $value : mixed
    $record : array<string, mixed>

    ruleFix()

    private ruleFix(string $field, mixed $value, array<string, mixed> $record) : mixed
    Parameters
    $field : string
    $value : mixed
    $record : array<string, mixed>

    selfReferencingBlogIdColumn()

    `<table>_blog_id` と同様に「自ブログ自身」を指す多態関連カラム名を返す (対象外テーブルは null)。

    private static selfReferencingBlogIdColumn(string $table) : string|null
    Parameters
    $table : string
    Return values
    string|null

    updateBlogConfigSet()

    yaml の各 blog レコードに含まれる config_set / theme_set / editor_set 系 ID を、 対応する blog テーブルレコードに UPDATE で反映する。

    private updateBlogConfigSet() : void

    単発 Import: yaml の blog レコードは 1 つで $this->blogId に対応する。 MultiBlogImport: yaml に複数 blog (基準 + 子) があり、それぞれの blog_id は mergeBlogYaml で確定 blog_id に書き換え済み。各 blog レコードを個別に UPDATE する。

    updateOneBlogConfigSet()

    private updateOneBlogConfigSet(array<string, mixed> $blog) : void
    Parameters
    $blog : array<string, mixed>

    yaml の 1 つの blog レコード (blog_id は確定済)

    
            
    On this page

    Search results