a-blog cms PHP API Reference

SiteSeeder
in package

SiteSeed メインオーケストレーター

state-less。seed() 呼び出しごとに以下を実行する:

  1. bin パス解決 (yaml / archives / media / storage / themes)
  2. 冪等性チェック (asChild=true なら親 blog 存在 / asChild=false なら対象 blog 存在)
  3. asChild=true なら新規子 blog を作成、false なら targetBlogId をそのまま使う
  4. yaml 内の "001/" 等のアーカイブパスを新 blog_id に書き換え
  5. Acms\Services\Blog\Import::run() に DB 投入を委譲
  6. bin のファイル群 (archives/media/storage/themes) を SCRIPT_DIR 配下にコピー
  7. キャッシュ全クリア

旧 setup/lib/import.php への依存は持たない。setup/ ディレクトリが 削除された本番環境でもクラスのロード自体は可能 (実際の投入には setup/bin/ のデータが必要なので、そちらが無ければエラーになる)。

Table of Contents

Properties

$blogRepository  : BlogRepository
$destination  : SiteSeedDestination|null
$paths  : SiteSeedPathResolver

Methods

__construct()  : mixed
copyBinFiles()  : void
bin の archives/media/storage/themes を destination 配下にコピーする。
paths()  : SiteSeedPathResolver
seed()  : SiteSeedResult
assertBlogExists()  : void
assertIdempotency()  : void
copyDir()  : void
createBlog()  : int
子 blog を作成し、`blog_id` を返す。
destination()  : SiteSeedDestination
コピー先ディレクトリを解決する。 コンストラクタで指定されなければ SCRIPT_DIR 配下を使う。
ensureTargetBlog()  : int
findSmallestUserId()  : int|null
lookupParentDomain()  : string
readYaml()  : string
resolveUserId()  : int
`entry_last_update_user_id` 等に挿入する user_id を確定する。
rewriteArchivesPrefix()  : string
yaml 内の "DDD/..." 形式 (media/storage の blog_id プレフィックス) を新 blog_id で書き換え
summariseCounts()  : array<string, int>
userExists()  : bool

Properties

Methods

copyBinFiles()

bin の archives/media/storage/themes を destination 配下にコピーする。

public copyBinFiles(SiteSeedPath $path, int $targetBlogId, SiteSeedLogger $logger, array<int, string> &$warnings) : void

Installer (複数 bin 投入) でも同じ処理が必要なため public で公開している。

Parameters
$path : SiteSeedPath
$targetBlogId : int
$logger : SiteSeedLogger
$warnings : array<int, string>

assertBlogExists()

private assertBlogExists(int $blogId, string $label) : void
Parameters
$blogId : int
$label : string

copyDir()

private copyDir(string $from, string $to, string $label, SiteSeedLogger $logger, array<int, string> &$warnings) : void
Parameters
$from : string
$to : string
$label : string
$logger : SiteSeedLogger
$warnings : array<int, string>

createBlog()

子 blog を作成し、`blog_id` を返す。

private createBlog(int $parentBlogId, SiteSeedOptions $options, SiteSeedLogger $logger) : int

nested-set の予約と INSERT は BlogRepository のプリミティブ(findLastChildInParent / findBoundary / shiftLeftRightAfter / nextBlogId / insert)を合成して行う(管理画面 ACMS_POST_Blog_Insert と同じ作法。生 SQL は BlogRepository に集約済み)。

Parameters
$parentBlogId : int
$options : SiteSeedOptions
$logger : SiteSeedLogger
Return values
int

findSmallestUserId()

private findSmallestUserId() : int|null
Return values
int|null

lookupParentDomain()

private lookupParentDomain(int $parentBlogId) : string
Parameters
$parentBlogId : int
Return values
string

readYaml()

private readYaml(string $path) : string
Parameters
$path : string
Return values
string

resolveUserId()

`entry_last_update_user_id` 等に挿入する user_id を確定する。

private resolveUserId(SiteSeedOptions $options, SiteSeedLogger $logger) : int

優先順位:

  1. $options->userId が指定されていれば、その値を検証して採用 (正の整数 + DB に存在)
  2. 未指定なら、DB 内の最小 user_id を fallback として採用
  3. DB に user が 1 件も存在しない場合はエラー

旧実装では未指定時に固定で 1 を使っていたが、存在しない user を 参照する孤児行を作る危険があったため廃止。

Parameters
$options : SiteSeedOptions
$logger : SiteSeedLogger
Return values
int

rewriteArchivesPrefix()

yaml 内の "DDD/..." 形式 (media/storage の blog_id プレフィックス) を新 blog_id で書き換え

private rewriteArchivesPrefix(string $yaml, int $blogId) : string

ACMS_POST_Backup_BlogImport::fixYaml と同じ正規表現。

Installer (複数 bin 投入) でも同じロジックが必要なため public で公開している。

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

summariseCounts()

private summariseCounts(array<string, mixed> $yamlData) : array<string, int>
Parameters
$yamlData : array<string, mixed>
Return values
array<string, int>

userExists()

private userExists(int $userId) : bool
Parameters
$userId : int
Return values
bool

        
On this page

Search results