SiteSeeder
in package
SiteSeed メインオーケストレーター
state-less。seed() 呼び出しごとに以下を実行する:
- bin パス解決 (yaml / archives / media / storage / themes)
- 冪等性チェック (asChild=true なら親 blog 存在 / asChild=false なら対象 blog 存在)
- asChild=true なら新規子 blog を作成、false なら targetBlogId をそのまま使う
- yaml 内の "001/" 等のアーカイブパスを新 blog_id に書き換え
- Acms\Services\Blog\Import::run() に DB 投入を委譲
- bin のファイル群 (archives/media/storage/themes) を SCRIPT_DIR 配下にコピー
- キャッシュ全クリア
旧 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
$blogRepository read-only
private
BlogRepository
$blogRepository
= new BlogRepository()
$destination read-only
private
SiteSeedDestination|null
$destination
= null
$paths read-only
private
SiteSeedPathResolver
$paths
Methods
__construct()
public
__construct(SiteSeedPathResolver $paths[, SiteSeedDestination|null $destination = null ][, BlogRepository $blogRepository = new BlogRepository() ]) : mixed
Parameters
- $paths : SiteSeedPathResolver
- $destination : SiteSeedDestination|null = null
- $blogRepository : BlogRepository = new BlogRepository()
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>
paths()
public
paths() : SiteSeedPathResolver
Return values
SiteSeedPathResolverseed()
public
seed(SiteSeedOptions $options[, SiteSeedLogger|null $logger = null ]) : SiteSeedResult
Parameters
- $options : SiteSeedOptions
- $logger : SiteSeedLogger|null = null
Return values
SiteSeedResultassertBlogExists()
private
assertBlogExists(int $blogId, string $label) : void
Parameters
- $blogId : int
- $label : string
assertIdempotency()
private
assertIdempotency(SiteSeedOptions $options) : void
Parameters
- $options : SiteSeedOptions
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
intdestination()
コピー先ディレクトリを解決する。 コンストラクタで指定されなければ SCRIPT_DIR 配下を使う。
private
destination() : SiteSeedDestination
Return values
SiteSeedDestinationensureTargetBlog()
private
ensureTargetBlog(SiteSeedOptions $options, SiteSeedLogger $logger) : int
Parameters
- $options : SiteSeedOptions
- $logger : SiteSeedLogger
Return values
intfindSmallestUserId()
private
findSmallestUserId() : int|null
Return values
int|nulllookupParentDomain()
private
lookupParentDomain(int $parentBlogId) : string
Parameters
- $parentBlogId : int
Return values
stringreadYaml()
private
readYaml(string $path) : string
Parameters
- $path : string
Return values
stringresolveUserId()
`entry_last_update_user_id` 等に挿入する user_id を確定する。
private
resolveUserId(SiteSeedOptions $options, SiteSeedLogger $logger) : int
優先順位:
$options->userIdが指定されていれば、その値を検証して採用 (正の整数 + DB に存在)- 未指定なら、DB 内の最小
user_idを fallback として採用 - DB に user が 1 件も存在しない場合はエラー
旧実装では未指定時に固定で 1 を使っていたが、存在しない user を 参照する孤児行を作る危険があったため廃止。
Parameters
- $options : SiteSeedOptions
- $logger : SiteSeedLogger
Return values
intrewriteArchivesPrefix()
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
stringsummariseCounts()
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