CoolCMS API

AssetUsageRepository extends ApiRepository
in package

FinalYes

Image usages and variant assignments: Api endpoint `api/system/asset-usage` (`get-assignments`, `save-assignments`, `get-regeneration-stats`, `regenerate-variants`, `delete-originals`, `delete-outdated-variants`).

Table of Contents

Properties

$apiEndpoint  : string
Api presenter path (e.g. `api/system/page`); set by each concrete repository.
$bridge  : ApiBridge

Methods

__construct()  : mixed
delete()  : Result
deleteAll()  : Result
deleteOriginals()  : Result
Deletes the stored originals of one usage (POST, irreversible).
deleteOutdatedVariants()  : Result
Deletes variants outside the current usage settings (POST, irreversible).
find()  : array<string|int, mixed>
findAll()  : array<string|int, mixed>
findBy()  : array<string|int, mixed>
getAssignments()  : array{usages: list>, variants: list>}|null
getRegenerationStats()  : array<int, array<string, mixed>>|null
Returns the variant regeneration state and the deletable originals per usage.
regenerateVariants()  : Result
Regenerates one batch of missing variants of one usage (POST). `$overwrite` also overwrites existing files whose dimensions differ from the plan; `$retry` first resets the usage's attempt counter.
save()  : Result
saveAssignments()  : Result
Saves the whole set of usages in one Api call, which is one DB transaction.
updateColumns()  : Result
failSoftRead()  : array<string|int, mixed>
Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
getApiCallSource()  : string
Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.
postUsageAction()  : Result
rows()  : array<int, array<string, mixed>>

Properties

$apiEndpoint

Api presenter path (e.g. `api/system/page`); set by each concrete repository.

protected string $apiEndpoint = 'api/system/asset-usage'

Methods

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

deleteOriginals()

Deletes the stored originals of one usage (POST, irreversible).

public deleteOriginals(int $usageId) : Result
Parameters
$usageId : int
Return values
Result —

data: deleted, bytes, failed, remaining

deleteOutdatedVariants()

Deletes variants outside the current usage settings (POST, irreversible).

public deleteOutdatedVariants(int $usageId) : Result
Parameters
$usageId : int
Return values
Result —

data: deleted, bytes, failed, remaining

find()

public find(int $id[, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
$id : int
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
array<string|int, mixed>

findAll()

public findAll([array<string|int, mixed>|null $filters = [] ][, array<string|int, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<string|int, mixed>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
$filters : array<string|int, mixed>|null = []
$orderBys : array<string|int, mixed>|null = null
$offset : int|null = null
$limit : int|null = null
$columns : array<string|int, mixed>|null = null
$computeTotalCount : bool = false
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
array<string|int, mixed>

findBy()

public findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
$filters : array<string|int, mixed>|null = []
$includes : string|array<string|int, mixed> = []
$useCache : bool|null = null
Return values
array<string|int, mixed>

getAssignments()

public getAssignments(int|null $moduleId) : array{usages: list>, variants: list>}|null
Parameters
$moduleId : int|null
Return values
array{usages: list>, variants: list>}|null —

null when the Api returned no data

getRegenerationStats()

Returns the variant regeneration state and the deletable originals per usage.

public getRegenerationStats(int|null $moduleId) : array<int, array<string, mixed>>|null
Parameters
$moduleId : int|null
Return values
array<int, array<string, mixed>>|null —

null when the Api returned no data

regenerateVariants()

Regenerates one batch of missing variants of one usage (POST). `$overwrite` also overwrites existing files whose dimensions differ from the plan; `$retry` first resets the usage's attempt counter.

public regenerateVariants(int $usageId[, bool $overwrite = false ][, bool $retry = false ]) : Result
Parameters
$usageId : int
$overwrite : bool = false
$retry : bool = false
Return values
Result —

data: processed, created, overwritten, failed, skipped, remaining, keysFilled, reset

save()

public save(array<string, mixed> $data[, array<string, mixed> $meta = [] ][, array<int, string> $skipFields = [] ]) : Result
Parameters
$data : array<string, mixed>

extracted entity payload

$meta : array<string, mixed> = []
$skipFields : array<int, string> = []
Return values
Result

saveAssignments()

Saves the whole set of usages in one Api call, which is one DB transaction.

public saveAssignments(array<int, array{usageId: int, keepOriginal: bool, assignments: list}> $usages, int|null $moduleId) : Result
Parameters
$usages : array<int, array{usageId: int, keepOriginal: bool, assignments: list}>
$moduleId : int|null
Return values
Result —

on validation error, data errors = array<usageId, list<{code, variantId, alias}>>

updateColumns()

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

ids or composite-id arrays

$values : array<string, mixed>

property name => new value

Return values
Result

failSoftRead()

Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.

protected failSoftRead(mixed $response, string $endpoint) : array<string|int, mixed>

NOTE: it does not log on purpose. ApiBridge::call(), which sees both the endpoint and the caller, has already written the API_FAILSOFT source=bridge line; a second copy would turn one failure into three lines in auth.log.

Parameters
$response : mixed
$endpoint : string

only for call readability; the log takes the endpoint from the bridge

Return values
array<string|int, mixed>

getApiCallSource()

Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.

protected getApiCallSource() : string
Return values
string

postUsageAction()

private postUsageAction(string $action, int $usageId[, array<string, bool> $flags = [] ]) : Result
Parameters
$action : string
$usageId : int
$flags : array<string, bool> = []
Return values
Result

rows()

private static rows(array<string|int, mixed> $items) : array<int, array<string, mixed>>
Parameters
$items : array<string|int, mixed>
Return values
array<int, array<string, mixed>>
On this page

Search results