a-blog cms PHP API Reference

BlogRepository
in package

Table of Contents

Constants

RELATED_TABLES  = ['alias' => 'alias_blog_id', 'app' => 'app_blog_id', 'approval' => 'approval_blog_id', 'approval_notification' => 'notification_blog_id', 'cache_reserve' => 'cache_reserve_blog_id', 'category' => 'category_blog_id', 'column' => 'column_blog_id', 'column_rev' => 'column_blog_id', 'comment' => 'comment_blog_id', 'config' => 'config_blog_id', 'config_set' => 'config_set_blog_id', 'dashboard' => 'dashboard_blog_id', 'entry' => 'entry_blog_id', 'entry_rev' => 'entry_blog_id', 'entry_sub_category' => 'entry_sub_category_blog_id', 'entry_sub_category_rev' => 'entry_sub_category_blog_id', 'field' => 'field_blog_id', 'field_rev' => 'field_blog_id', 'form' => 'form_blog_id', 'fulltext' => 'fulltext_blog_id', 'geo' => 'geo_blog_id', 'geo_rev' => 'geo_blog_id', 'layout_grid' => 'layout_grid_blog_id', 'log_form' => 'log_form_blog_id', 'module' => 'module_blog_id', 'role_blog' => 'blog_id', 'rule' => 'rule_blog_id', 'schedule' => 'schedule_blog_id', 'shop_address' => 'address_blog_id', 'shop_cart' => 'cart_blog_id', 'tag' => 'tag_blog_id', 'tag_rev' => 'tag_blog_id', 'user' => 'user_blog_id', 'webhook' => 'webhook_blog_id']
blog 削除時に blog_id 系カラムで参照される関連テーブル一覧。

Methods

cascadeStatusToSubtree()  : void
自身を含む配下の blog の status を、指定 status に一括書き換えする
changeParent()  : bool
ブログの親を付け替え、ツリーの left/right/sort を再配置する
delete()  : void
Blog 集約を物理削除する。
existsByDomainAndCode()  : bool
指定ドメイン内に同じコードを持つブログが存在するか
findBlogById()  : array<string, mixed>|null
指定ブログの行を取得する
findBoundary()  : array{left: int, right: int}|null
指定ブログの nested set 境界 (left, right) を取得
findLastChildInParent()  : array{right: int, sort: int}|null
指定親ブログ配下で最後の子(最大 blog_right の行)を返す。 新規追加時の挿入位置 / 親ブログ変更時の末尾追加位置の計算に利用する。
hasDescendantWithStatusIn()  : bool
指定ブログの子孫に、指定ステータスのブログが 1 件以上存在するか
insert()  : void
ブログを新規 INSERT
nextBlogId()  : int
blog_id のシーケンスから次の値を採番
reorderSibling()  : bool
同一親内での並び順を $toSort に変更し、関連する left/right/sort を再配置する
shiftLeftRightAfter()  : void
挿入時に nested set の空きを確保する(指定 left より大きい値を 2 シフト)
update()  : void
指定カラムで対象ブログを UPDATE
updateConfigSetBulk()  : void
指定 ID 群の blog_config_set_id を一括更新
updateDescendantsStatus()  : void
指定ブログの子孫ブログのうち、status が $statusIn に含まれる行を $status に一括書き換えする
updateMaintenanceMode()  : void
blog_maintenance_mode を更新する
updateStatusBulk()  : void
指定 ID 群の blog_status を一括更新
deleteRelatedRecords()  : void
blog に紐づく関連テーブルのレコードをまとめて削除する
inheritStatusFromParent()  : void
親ブログの status を、自身と子孫に継承させる
realignTreeAfterRemoval()  : void
ブログ削除に伴う nested set ツリーの詰め直し

Constants

blog 削除時に blog_id 系カラムで参照される関連テーブル一覧。

private array<string, string> RELATED_TABLES = ['alias' => 'alias_blog_id', 'app' => 'app_blog_id', 'approval' => 'approval_blog_id', 'approval_notification' => 'notification_blog_id', 'cache_reserve' => 'cache_reserve_blog_id', 'category' => 'category_blog_id', 'column' => 'column_blog_id', 'column_rev' => 'column_blog_id', 'comment' => 'comment_blog_id', 'config' => 'config_blog_id', 'config_set' => 'config_set_blog_id', 'dashboard' => 'dashboard_blog_id', 'entry' => 'entry_blog_id', 'entry_rev' => 'entry_blog_id', 'entry_sub_category' => 'entry_sub_category_blog_id', 'entry_sub_category_rev' => 'entry_sub_category_blog_id', 'field' => 'field_blog_id', 'field_rev' => 'field_blog_id', 'form' => 'form_blog_id', 'fulltext' => 'fulltext_blog_id', 'geo' => 'geo_blog_id', 'geo_rev' => 'geo_blog_id', 'layout_grid' => 'layout_grid_blog_id', 'log_form' => 'log_form_blog_id', 'module' => 'module_blog_id', 'role_blog' => 'blog_id', 'rule' => 'rule_blog_id', 'schedule' => 'schedule_blog_id', 'shop_address' => 'address_blog_id', 'shop_cart' => 'cart_blog_id', 'tag' => 'tag_blog_id', 'tag_rev' => 'tag_blog_id', 'user' => 'user_blog_id', 'webhook' => 'webhook_blog_id']

ablogcms/php/config/schema/db.schema.yaml を走査し、blog_id 系カラムを持つテーブルを列挙したもの。 キーがテーブル名、値がそのテーブルにおける blog_id カラム名。スキーマ追加時はこの定数にも追記する。

_rev 系テーブルおよび命名規則 {table_name}_blog_id を満たさないテーブル (role_blog.blog_id など) も含めるため、カラム名を明示的に保持している。

以下のテーブルは意図的に除外している:

  • sequence: 全システム単一行で「現在採番されている最大 blog_id」を管理するため、 個別ブログ削除と紐づくレコードではない
  • workflow / workflow_usergroup: deleteWorkflow() 経由でセットで削除されるため二重削除を避ける
  • media / media_tag: a-blog cms ではメディアは media_id 単独で参照され、所有 blog が 削除されても他 blog のエントリ / カスタムフィールド / ブロックエディタ から参照可能な設計。blog 削除に伴って消すと他 blog でリンク切れを起こす
  • audit_log: 監査証跡は「削除されたブログ上で行われた操作」も後から検証できる必要が あるため、blog 削除でカスケードしない

Methods

cascadeStatusToSubtree()

自身を含む配下の blog の status を、指定 status に一括書き換えする

public cascadeStatusToSubtree(int $blogId, string $status, array<int, string> $statusIn) : void

公開度が緩い ($statusIn に含まれる) 行を対象とし、対象範囲は 「指定ブログ自身を含む nested set 配下」(left/right を含む inclusive 範囲)。

Parameters
$blogId : int
$status : string
$statusIn : array<int, string>

置換対象として扱う status 値

changeParent()

ブログの親を付け替え、ツリーの left/right/sort を再配置する

public changeParent(int $blogId, int $toParentBlogId) : bool

必要な nested set / parent / sort はメソッド内で SELECT するため、呼び出し側は 「対象ブログ ID」と「移動先親ブログ ID」のみ渡せばよい。

以下の場合は false を返す:

  • 対象ブログが存在しない
  • すでに同じ親(no-op)
  • 移動先親が自分自身、もしくは自身の子孫
Parameters
$blogId : int
$toParentBlogId : int
Return values
bool

delete()

Blog 集約を物理削除する。

public delete(int $blogId) : void

集約に属する以下の永続状態をまとめて整合的に削除する:

  • blog 行そのもの
  • 関連テーブル群(alias / category / entry / field / ... の blog_id を持つ行)
  • ワークフロー定義
  • nested set ツリーの再配置(兄弟 sort / 祖先・末尾の left,right)

キャッシュ無効化はインフラ関心事のため、本メソッドの責務には含めない。 呼び出し側で必要に応じて Cache::flush() を行うこと。

対象 blog_id が存在しない場合は何もしない。

Parameters
$blogId : int

existsByDomainAndCode()

指定ドメイン内に同じコードを持つブログが存在するか

public existsByDomainAndCode(string $domain, string $code) : bool

カテゴリーコードがブログコードと衝突しないかの検証等で利用する。

Parameters
$domain : string
$code : string
Return values
bool

findBlogById()

指定ブログの行を取得する

public findBlogById(int $blogId) : array<string, mixed>|null
Parameters
$blogId : int
Return values
array<string, mixed>|null

findBoundary()

指定ブログの nested set 境界 (left, right) を取得

public findBoundary(int $blogId) : array{left: int, right: int}|null
Parameters
$blogId : int
Return values
array{left: int, right: int}|null

findLastChildInParent()

指定親ブログ配下で最後の子(最大 blog_right の行)を返す。 新規追加時の挿入位置 / 親ブログ変更時の末尾追加位置の計算に利用する。

public findLastChildInParent(int $parentBlogId) : array{right: int, sort: int}|null
Parameters
$parentBlogId : int
Return values
array{right: int, sort: int}|null

hasDescendantWithStatusIn()

指定ブログの子孫に、指定ステータスのブログが 1 件以上存在するか

public hasDescendantWithStatusIn(int $blogId, array<int, string> $statuses) : bool

対象ブログが存在しない場合は false を返す。

Parameters
$blogId : int
$statuses : array<int, string>
Return values
bool

insert()

ブログを新規 INSERT

public insert(array<string, mixed> $columns) : void
Parameters
$columns : array<string, mixed>

カラム名 => 値

nextBlogId()

blog_id のシーケンスから次の値を採番

public nextBlogId() : int
Return values
int

reorderSibling()

同一親内での並び順を $toSort に変更し、関連する left/right/sort を再配置する

public reorderSibling(int $blogId, int $toSort) : bool

必要な nested set / sort / parent はメソッド内で SELECT するため、呼び出し側は 「対象ブログ ID」と「移動先 sort」のみ渡せばよい。親ブログは対象ブログから自動解決する。

Parameters
$blogId : int
$toSort : int
Return values
bool

成功時 true、無効な対象 / 同位置 / 範囲外などは false

shiftLeftRightAfter()

挿入時に nested set の空きを確保する(指定 left より大きい値を 2 シフト)

public shiftLeftRightAfter(int $left) : void
Parameters
$left : int

update()

指定カラムで対象ブログを UPDATE

public update(int $blogId, array<string, mixed> $columns) : void
Parameters
$blogId : int
$columns : array<string, mixed>

カラム名 => 値

updateConfigSetBulk()

指定 ID 群の blog_config_set_id を一括更新

public updateConfigSetBulk(array<string|int, int|string> $blogIds, int|null $configSetId) : void
Parameters
$blogIds : array<string|int, int|string>
$configSetId : int|null

updateDescendantsStatus()

指定ブログの子孫ブログのうち、status が $statusIn に含まれる行を $status に一括書き換えする

public updateDescendantsStatus(int $blogId, string $status, array<int, string> $statusIn) : void

対象ブログが存在しない場合は何もしない。

Parameters
$blogId : int
$status : string
$statusIn : array<int, string>

置換対象として扱う status 値

updateMaintenanceMode()

blog_maintenance_mode を更新する

public updateMaintenanceMode(int $blogId, string $mode) : void
Parameters
$blogId : int
$mode : string

updateStatusBulk()

指定 ID 群の blog_status を一括更新

public updateStatusBulk(array<string|int, int|string> $blogIds, string $status) : void
Parameters
$blogIds : array<string|int, int|string>
$status : string

deleteRelatedRecords()

blog に紐づく関連テーブルのレコードをまとめて削除する

private deleteRelatedRecords(int $blogId) : void
Parameters
$blogId : int

inheritStatusFromParent()

親ブログの status を、自身と子孫に継承させる

private inheritStatusFromParent(int $blogId, int $parentBlogId) : void

親が close なら自身と子孫の open / secret を close に、 親が secret なら open を secret に書き換える。親が open なら何もしない。

Parameters
$blogId : int
$parentBlogId : int

realignTreeAfterRemoval()

ブログ削除に伴う nested set ツリーの詰め直し

private realignTreeAfterRemoval(array<string, mixed> $blog) : void
  • left/right が削除位置より後の行はギャップ 2 ぶん -2
  • 削除ブログの内側(祖先 - 子孫境界内)は -1
  • 同一親内の sort が削除位置より大きい兄弟は -1
Parameters
$blog : array<string, mixed>

削除済みブログの行(blog_left/blog_right/blog_sort/blog_parent を含む)


        
On this page

Search results