CoolCMS API

ExternalConnectionGroupSaveTrait

Api operation "save a connection and switch off the alternatives of its group".

The administration used to save the chosen row and only then disable the siblings with separate best-effort saves: a failed sibling write (or two admins switching at once) left two alternatives enabled while the form reported success. Here it is a single operation in a single DB transaction: lock every row of the group, write the chosen row, disable the enabled siblings, commit — or roll back everything.

The trait is split into seams so the contract ("a failure in the middle writes nothing") is testable without DB, DI or network (ExternalConnectionGroupSaveTest):

  • fetchConnectionType() — immutable type code of the row,
  • resolveConnectionGroupTypes() — type codes of the group (registry in code),
  • lockConnectionRows() — current rows inside the transaction, locked,
  • storeConnectionEnabled() / storeConnection() — single writes (may throw),
  • inConnectionGroupTransaction() — the real transaction (implemented by the manager).

Table of Contents

Methods

saveExclusive()  : Result
Saves `enabled` + `config` of one connection. Enabling it disables every other enabled connection of the same group in the same transaction.
fetchConnectionType()  : string|null
Type code of the connection, null when the row does not exist.
inConnectionGroupTransaction()  : Result
lockConnectionRows()  : array<int, array{type: string, enabled: bool}>
Current rows of the given types, locked until the end of the transaction.
resolveConnectionGroupTypes()  : array<int, string>
Type codes the connection is an alternative to, including its own type (just `[$type]` for a type without a group).
storeConnection()  : void
storeConnectionEnabled()  : void

Methods

saveExclusive()

Saves `enabled` + `config` of one connection. Enabling it disables every other enabled connection of the same group in the same transaction.

public saveExclusive(int $connectionId, bool $enabled, array<string, scalar|null> $config) : Result
Parameters
$connectionId : int
$enabled : bool
$config : array<string, scalar|null>
Return values
Result —

success data: ['disabled' => list<string>] — type codes switched off

fetchConnectionType()

Type code of the connection, null when the row does not exist.

protected abstract fetchConnectionType(int $connectionId) : string|null
Parameters
$connectionId : int
Return values
string|null

lockConnectionRows()

Current rows of the given types, locked until the end of the transaction.

protected abstract lockConnectionRows(array<int, string> $types) : array<int, array{type: string, enabled: bool}>
Parameters
$types : array<int, string>
Return values
array<int, array{type: string, enabled: bool}> —

indexed by connection id

resolveConnectionGroupTypes()

Type codes the connection is an alternative to, including its own type (just `[$type]` for a type without a group).

protected abstract resolveConnectionGroupTypes(string $type) : array<int, string>
Parameters
$type : string
Return values
array<int, string>

storeConnection()

protected abstract storeConnection(int $connectionId, bool $enabled, array<string, scalar|null> $config) : void
Parameters
$connectionId : int
$enabled : bool
$config : array<string, scalar|null>

storeConnectionEnabled()

protected abstract storeConnectionEnabled(int $connectionId, bool $enabled) : void
Parameters
$connectionId : int
$enabled : bool
On this page

Search results