CoolCMS API

MessageThreadManager extends Manager
in package

Private message threads in the admin.

IMPORTANT: openThread() is the admin counterpart of MessageThreadManager::openThread(), not a call to it: the admin branch goes through the ApiBridge and may only call save/find on endpoints, not a foreign domain method. The orchestration is therefore duplicated on purpose, as with the Bazaar and Comcat ResponseManager; when the two diverge, fix both.

Manual creation is the only way a thread comes into existence without a front end action, so it lives in the admin behind the RBAC key :Admin:Base:MessageThread:add.

Tags
extends

Table of Contents

Properties

$service  : TService
Manager service; subclasses narrow the type (`@property` in the Api/Admin/Front manager).
$appContext  : AppContext
$cacheTagInvalidator  : CacheTagInvalidator|null
Post-commit invalidator of the wire-payload query cache (tag bump per entity class).
$languageContext  : LanguageContext|null
$paramsConfig  : Config|null
Neon parameters (`%params%`: server paths and directories), set by the decorator (`decorators.neon`) like `setAppContext()`.
$presenterContext  : PresenterContext
$settingContext  : SettingContext
$messageManager  : MessageManager
$messageParticipantManager  : MessageParticipantManager

Methods

__construct()  : mixed
addParticipant()  : Result
Invites another participant (arbiter, another user) into the thread.
delete()  : Result
deleteAll()  : Result
find()  : SingleQuery<string|int, T>
Finds one entity by id (returns a `SingleQuery` object).
findAll()  : Query<string|int, T>
Finds all entities (returns a `Query` object).
findBy()  : SingleQuery<string|int, T>
Finds one entity by filters (returns a `SingleQuery` object).
getAppContext()  : AppContext
getLanguageContext()  : LanguageContext|null
getPresenterContext()  : PresenterContext
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getTotalCount()  : int|null
Returns the total count of the last `findAll()` of this manager's service, computed only when the query asked for it (`findAll(..., computeTotalCount: true)`); otherwise the last stored value.
initializeAllContexts()  : void
openThread()  : Result
Opens a thread between two registered users and inserts the first message into it.
removeParticipant()  : Result
Removes a participant from the thread (`$participantId` is the participant row id); the row stays and is marked as removed.
save()  : Result
setAppContext()  : $this
setCacheTagInvalidator()  : static
setLanguageContext()  : $this
setParamsConfig()  : static
setPresenterContext()  : $this
setSettingContext()  : $this
updateColumn()  : Result
updateColumns()  : Result
bumpCacheTags()  : void
Bumps cache tags for the entity after commit: its class, the owned-cascade classes from metadata and the optional `additionalCacheTags()` of the manager.
bumpCacheTagsExplicit()  : void
Bumps the given classes explicitly (raw-DBAL paths with a cross-entity effect).
bumpCacheTagsForClass()  : void
Bumps cache tags by class name when there is no instance (bulk delete, `updateColumns()`, raw DBAL, tree operations).
classCacheTags()  : array<string|int, string>
Returns extra tags for a bump that has no entity, typically tree operations ({@see \App\Core\Traits\Api\Models\Managers\TreeTrait::treeTransaction()}) that rewrite `lft`/`rgt` on many rows.
getService()  : TService
Returns the service for the traits.
compensateOpenThread()  : void
Compensates for a partially created thread.
createParticipant()  : MessageParticipant

Properties

$service

Manager service; subclasses narrow the type (`@property` in the Api/Admin/Front manager).

public TService $service

$cacheTagInvalidator

Post-commit invalidator of the wire-payload query cache (tag bump per entity class).

protected CacheTagInvalidator|null $cacheTagInvalidator = null

Set by the decorator (decorators.neon) like setParamsConfig(). Nullable and fail-open: without wiring (or without Redis) a bump is a no-op.

$paramsConfig

Neon parameters (`%params%`: server paths and directories), set by the decorator (`decorators.neon`) like `setAppContext()`.

protected Config|null $paramsConfig = null

Write logic (asset directories) reads paths from here, not from getSettings() or the setting context, which may be filled by the client without server paths. The property cannot be named $config: it collides with the promoted $config in some managers.

Methods

addParticipant()

Invites another participant (arbiter, another user) into the thread.

public addParticipant(int $threadId, int $userId) : Result

The rules and rejections live in MessageThreadManager::addParticipant(); this only forwards the call because the admin goes through the ApiBridge and may call only the Api action. A failure carries a ResultCode so the presenter can pick the message.

Parameters
$threadId : int
$userId : int
Return values
Result

delete()

public delete(int|array<string|int, mixed> $id) : Result
Parameters
$id : int|array<string|int, mixed>
Return values
Result

deleteAll()

public deleteAll([array<string|int, mixed> $filters = [] ]) : Result
Parameters
$filters : array<string|int, mixed> = []
Return values
Result

find()

Finds one entity by id (returns a `SingleQuery` object).

public find(int $id[, string|array<string|int, mixed> $includes = [] ]) : SingleQuery<string|int, T>
Parameters
$id : int

entity id

$includes : string|array<string|int, mixed> = []

relations to load (['translations', 'routes'] or '*' for all)

Return values
SingleQuery<string|int, T>

findAll()

Finds all entities (returns a `Query` object).

public findAll([array<string|int, mixed>|null $filters = [] ][, array<string|int, mixed>|null $orderBy = null ][, int|null $offset = null ][, int|null $limit = null ][, array<string|int, mixed>|null $columns = null ][, string|array<string|int, mixed> $includes = [] ][, bool $computeTotalCount = false ]) : Query<string|int, T>
Parameters
$filters : array<string|int, mixed>|null = []

filters for the where conditions

$orderBy : array<string|int, mixed>|null = null

ordering ['column' => 'ASC/DESC']

$offset : int|null = null

offset for pagination

$limit : int|null = null

result limit

$columns : array<string|int, mixed>|null = null

specific columns to load

$includes : string|array<string|int, mixed> = []

relations to load (['translations', 'routes.translations'] or '*' for all)

$computeTotalCount : bool = false

whether to compute the total count for pagination

Return values
Query<string|int, T>

findBy()

Finds one entity by filters (returns a `SingleQuery` object).

public findBy([array<string|int, mixed> $filters = [] ][, string|array<string|int, mixed> $includes = [] ]) : SingleQuery<string|int, T>
Parameters
$filters : array<string|int, mixed> = []

filters for the where conditions

$includes : string|array<string|int, mixed> = []

relations to load (['translations', 'routes'] or '*' for all)

Return values
SingleQuery<string|int, T>

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

getTotalCount()

Returns the total count of the last `findAll()` of this manager's service, computed only when the query asked for it (`findAll(..., computeTotalCount: true)`); otherwise the last stored value.

public getTotalCount() : int|null

Same value as Query::getTotalCount() of that query.

Return values
int|null

openThread()

Opens a thread between two registered users and inserts the first message into it.

public openThread(string|null $subject, int $senderUserId, int $recipientUserId, string $text) : Result

Both participants are users (picked in the admin), so the thread is always created as system; a conversation with a guest is never opened from the admin.

Parameters
$subject : string|null
$senderUserId : int
$recipientUserId : int
$text : string
Return values
Result

removeParticipant()

Removes a participant from the thread (`$participantId` is the participant row id); the row stays and is marked as removed.

public removeParticipant(int $threadId, int $participantId) : Result
Parameters
$threadId : int
$participantId : int
Return values
Result

setParamsConfig()

public setParamsConfig(Config $paramsConfig) : static
Parameters
$paramsConfig : Config
Return values
static

updateColumn()

public updateColumn(int|array<string|int, mixed> $entityId, string $property, mixed $value) : Result
Parameters
$entityId : int|array<string|int, mixed>

id, or a list of ids / composite-id arrays

$property : string
$value : mixed
Return values
Result

updateColumns()

public updateColumns(int|array<string|int, mixed> $entityId, array<string, mixed> $values) : Result
Parameters
$entityId : int|array<string|int, mixed>

id, or a list of ids / composite-id arrays

$values : array<string, mixed>

property name => new value

Return values
Result

bumpCacheTags()

Bumps cache tags for the entity after commit: its class, the owned-cascade classes from metadata and the optional `additionalCacheTags()` of the manager.

protected bumpCacheTags(object $entity) : void

Fail-open (the invalidator swallows exceptions). Called from the manager Save/Delete/Tree traits after the commit.

Parameters
$entity : object

bumpCacheTagsExplicit()

Bumps the given classes explicitly (raw-DBAL paths with a cross-entity effect).

protected bumpCacheTagsExplicit(array<string|int, string> $classes) : void
Parameters
$classes : array<string|int, string>

bumpCacheTagsForClass()

Bumps cache tags by class name when there is no instance (bulk delete, `updateColumns()`, raw DBAL, tree operations).

protected bumpCacheTagsForClass(class-string $rootClass[, array<string|int, string> $extraTags = [] ]) : void

Bumps the root class and its owned-cascade classes.

Parameters
$rootClass : class-string
$extraTags : array<string|int, string> = []

classCacheTags()

Returns extra tags for a bump that has no entity, typically tree operations ({@see \App\Core\Traits\Api\Models\Managers\TreeTrait::treeTransaction()}) that rewrite `lft`/`rgt` on many rows.

protected classCacheTags() : array<string|int, string>

IMPORTANT: additionalCacheTags(object) receives an entity, so a class-level bump cannot use it; without this hook a delete would lose the cross-entity tag (Comment to CommentThread). A manager whose cross-entity tag does not depend on a particular entity returns it here.

NOTE: unlike additionalCacheTags(), this hook is declared (with an empty default) instead of being an opt-in through method_exists(); method_exists() is always true in a manager that has the method, which phpstan reports as alreadyNarrowedType.

Return values
array<string|int, string>

getService()

Returns the service for the traits.

protected getService() : TService
Return values
TService

compensateOpenThread()

Compensates for a partially created thread.

private compensateOpenThread(int $threadId, array<int, int> $participantIds) : void

The admin branch goes through the ApiBridge and every save() is a separate call, so one shared transaction cannot be opened (the shared SaveTrait only delegates to ApiService). Without compensation, a failure of a later step would leave an orphan thread and participant that the admin UI never shows (a thread without a message does not reach the list). Deletion is best-effort: if it fails too, the caller still receives the original save error and the failure is only logged so it can be cleaned up by hand.

Parameters
$threadId : int
$participantIds : array<int, int>
On this page

Search results