LogPresenter
extends BasePresenter
in package
Retention of the `log/` directory.
Deletes Tracy dumps (<channel>--YYYY-MM-DD--...html|md) older than N days and renames *.log files larger
than M MB to .log.1 (keeps 3 generations), see LogRetention.
URL: /cron/system/log/purge-old?token=xxx[&days=N][&maxSizeMb=M]
Retention is ?days, else the setting log.retentionDays (group 1), else 30 days.
Size limit is ?maxSizeMb, else the setting log.maxSizeMb, else 50 MB.
Frequency: daily. The endpoint guards itself to run at most once per GUARD_TTL seconds; URL
parameters do not bypass the guard.
Table of Contents
Constants
- GUARD_NAME : string = 'log.retention.lastRun'
- Lock row remembering the last run (`cms_cron_locks`) — deliberately never released.
- GUARD_TTL : int = 72000
- 20 h, not 24 h: a daily crontab fires a few seconds earlier than the previous run finished.
- SETTINGS_GROUP : int = 1
Properties
- $cronLockManager : CronLockManager
- $operationRunner : OperationRunner
- Boundary of one cron action (see {@see self::tryCall()}).
- $settingContext : SettingContext
- $settingManager : SettingManager
- $debugMode : bool
- $productionMode : bool
- $logRetention : LogRetention
Methods
- __construct() : mixed
- actionPurgeOld() : void
- releaseLock() : void
- Releases the lock at most once; called by both `shutdown()` and the PHP shutdown function.
- sendResponse() : void
- setConfigParameters() : void
- shutdown() : void
- startup() : void
- isSameSiteRequest() : bool
- Tells whether the request comes from the own site (Nette SameSite cookie); protects GET actions with a side effect.
- sendError() : never
- sendSkipped() : never
- Reports that the job did only part of the work and the next call finishes the rest (e.g. a reindex done in chunks).
- sendSuccess() : never
- tryCall() : bool
- Runs the `action<Action>()` method as one operation (transitional).
- resolveSetting() : int
Constants
GUARD_NAME
Lock row remembering the last run (`cms_cron_locks`) — deliberately never released.
private
string
GUARD_NAME
= 'log.retention.lastRun'
GUARD_TTL
20 h, not 24 h: a daily crontab fires a few seconds earlier than the previous run finished.
private
int
GUARD_TTL
= 72000
SETTINGS_GROUP
private
int
SETTINGS_GROUP
= 1
Properties
$cronLockManager
public
CronLockManager
$cronLockManager
Attributes
- #[Inject]
$operationRunner
Boundary of one cron action (see {@see self::tryCall()}).
public
OperationRunner
$operationRunner
Attributes
- #[Inject]
$settingContext
public
SettingContext
$settingContext
Attributes
- #[Inject]
$settingManager
public
SettingManager
$settingManager
Attributes
- #[Inject]
$debugMode
protected
bool
$debugMode
= false
$productionMode
protected
bool
$productionMode
= false
$logRetention read-only
private
LogRetention
$logRetention
Methods
__construct()
public
__construct(LogRetention $logRetention) : mixed
Parameters
- $logRetention : LogRetention
actionPurgeOld()
public
actionPurgeOld([int|null $days = null ][, int|null $maxSizeMb = null ]) : void
Parameters
- $days : int|null = null
- $maxSizeMb : int|null = null
Attributes
- #[CronJob]
- $frequency: 'daily:04:20'
- $outbound: false
releaseLock()
Releases the lock at most once; called by both `shutdown()` and the PHP shutdown function.
public
releaseLock() : void
sendResponse()
public
sendResponse(Response $response) : void
Parameters
- $response : Response
setConfigParameters()
public
setConfigParameters([bool $debugMode = false ][, bool $productionMode = false ]) : void
Parameters
- $debugMode : bool = false
- $productionMode : bool = false
shutdown()
public
shutdown(Response $response) : void
Parameters
- $response : Response
startup()
public
startup() : void
isSameSiteRequest()
Tells whether the request comes from the own site (Nette SameSite cookie); protects GET actions with a side effect.
protected
isSameSiteRequest() : bool
getHttpRequest() returns the IRequest interface, while isSameSite() exists only on
Nette\Http\Request.
Return values
boolsendError()
protected
sendError(string $message[, int $code = 500 ]) : never
Parameters
- $message : string
- $code : int = 500
Return values
neversendSkipped()
Reports that the job did only part of the work and the next call finishes the rest (e.g. a reindex done in chunks).
protected
sendSkipped(string $reason[, array<string, mixed> $data = [] ]) : never
The scheduler does not record skipped as a run, so the job stays due and is called
again on the next tick.
Parameters
- $reason : string
- $data : array<string, mixed> = []
Return values
neversendSuccess()
protected
sendSuccess([array<string|int, mixed> $data = [] ]) : never
Parameters
- $data : array<string|int, mixed> = []
Return values
nevertryCall()
Runs the `action<Action>()` method as one operation (transitional).
protected
tryCall(string $method, array<string, mixed> $params) : bool
Cron has no internalAction*(): its actions call the Api managers directly, so without this in
scoped mode nothing would ever empty the unit of work of a cron run. The boundary is the action
only; startup() (settings, token, lock) stays outside like the startup of an Api request. A cron
action ends with AbortException from send*(), which is a regular end: the outcome comes from the
response (ok succeeded, skipped unknown — possibly a part of a batch was done, error failed).
Render and signal methods are not wrapped (cron presenters have none).
Parameters
- $method : string
- $params : array<string, mixed>
Return values
boolresolveSetting()
private
resolveSetting(string $key, int $default) : int
Parameters
- $key : string
- $default : int