SettingBatchTrait
Saves a whole set of settings in one DB transaction.
IMPORTANT: saving keys one by one would leave the keys written before a failure committed,
e.g. theme.frontend pointing to the new template and theme.frontend.path to the old
folder while the form reports a failure.
Contract:
- the whole set is validated before the first write (shape, column limits, duplicate
keys); depending on
sql_mode, the database would fail a longer value with a generic error or silently truncate it, - the write is a per-row upsert inside one transaction; any failure rolls back the set,
is_publicof an existing row is not changed (the upsert changes onlyvalue), same as the genericsave(); a new key is created fail-closed withis_public = 0.
The operation grants no more power than the generic setting save() (which may write any
key), so the RBAC key :Api:System:Setting:saveBatch copies the relations of save.
Orchestration lives here (testable without DB); the manager supplies the transaction and the DBAL write.
Table of Contents
Constants
- SETTING_BATCH_MAX_ITEMS : int = 200
- Upper limit of keys in one set.
Methods
- normalizeSettingBatch() : array<int, array{module: int, key: string, value: string}>|Result
- saveSettingBatch() : Result
- inSettingBatchTransaction() : Result
- Runs `$work` in a transaction; a failure or an exception rolls back the whole set.
- upsertSettingValue() : void
- Upserts one key; a failure is reported by an exception (the transaction turns it into a rollback).
Constants
SETTING_BATCH_MAX_ITEMS
Upper limit of keys in one set.
public
int
SETTING_BATCH_MAX_ITEMS
= 200
Methods
normalizeSettingBatch()
public
static normalizeSettingBatch(array<int|string, mixed> $items) : array<int, array{module: int, key: string, value: string}>|Result
Parameters
- $items : array<int|string, mixed>
Return values
array<int, array{module: int, key: string, value: string}>|ResultsaveSettingBatch()
public
saveSettingBatch(array<int|string, mixed> $items) : Result
Parameters
- $items : array<int|string, mixed>
-
list of
{module, key, value}items
Return values
ResultinSettingBatchTransaction()
Runs `$work` in a transaction; a failure or an exception rolls back the whole set.
protected
abstract inSettingBatchTransaction(callable(): Result $work) : Result
Parameters
- $work : callable(): Result
Return values
ResultupsertSettingValue()
Upserts one key; a failure is reported by an exception (the transaction turns it into a rollback).
protected
abstract upsertSettingValue(int $module, string $key, string $value) : void
Parameters
- $module : int
- $key : string
- $value : string