CoolCMS API

SitemapPresenter extends BasePresenter
in package
uses SitemapBuilderTrait

Table of Contents

Constants

ADVERT_CHANGEFREQ  : mixed = 'daily'
ADVERT_PRIORITY  : mixed = '0.5'
ADVERTS_PREFIX  : mixed = 'sitemap-comcat-adverts'
CATEGORY_CHANGEFREQ  : mixed = 'weekly'
CATEGORY_PRIORITY  : mixed = '0.7'
FILE_CATEGORIES  : mixed = 'sitemap-comcat-categories.xml'
SETTINGS_GROUP  : mixed = 6
SITEMAP_BATCH_SIZE  : mixed = 500
Number of entities loaded by one query.

Properties

$cronLockManager  : CronLockManager
$linkGenerator  : LinkGenerator
$operationRunner  : OperationRunner
Boundary of one cron action (see {@see self::tryCall()}).
$settingContext  : SettingContext
$settingManager  : SettingManager
$sitemapLocalizationManager  : LocalizationManager
$sitemapRouterDispatcher  : RouterDispatcher
$sitemapSiteBaseUrl  : SiteBaseUrl
Website address from `site.baseUrl`.
$debugMode  : bool
$productionMode  : bool
$advertManager  : AdvertManager
$categoryManager  : CategoryManager

Methods

__construct()  : mixed
actionAdvert()  : void
Sitemap of active company profiles, split into files by ID ranges (size depends on the number of languages).
actionCategory()  : void
Sitemap of all active Comcat categories with hreflang variants.
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
buildSitemapXml()  : string
Builds the sitemap XML from entities.
generateUrl()  : string|null
isSameSiteRequest()  : bool
Tells whether the request comes from the own site (Nette SameSite cookie); protects GET actions with a side effect.
loadActiveLocalizations()  : array<int, Localization>
Loads active localizations including the linked language.
respondBucketedSitemap()  : void
Splits a large sitemap into N files by fixed ID ranges.
respondSitemap()  : void
Sends the XML response, or writes it to a file and sends a JSON success.
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
shouldSaveSitemap()  : bool
tryCall()  : bool
Runs the `action<Action>()` method as one operation (transitional).
warmupTranslator()  : void
Warms the translator cache from already loaded entities, avoiding the global `warmupCache(null)`.
buildAdvertUrl()  : string|null
buildCategoryUrl()  : string|null
buildUrlsByLocale()  : array<string, string>
Returns the item URL for every active localization (localization key => URL); an empty result means the item does not belong in the sitemap.
failSitemapWrite()  : never
Reports a write failure: the detail (including the path) goes to the server log only, the response carries no absolute path.
loadAdvertsBatch()  : array<int, Advert>
loadCategories()  : array<int, Category>
resolveAdvertLastmod()  : string
resolveMaxAdvertId()  : int
resolvePageId()  : int
resolveSitemapDir()  : string
resolveSitemapItemId()  : int

Constants

FILE_CATEGORIES

private mixed FILE_CATEGORIES = 'sitemap-comcat-categories.xml'

Properties

$operationRunner

Boundary of one cron action (see {@see self::tryCall()}).

public OperationRunner $operationRunner
Attributes
#[Inject]

$sitemapSiteBaseUrl

Website address from `site.baseUrl`.

public SiteBaseUrl $sitemapSiteBaseUrl

A sitemap holds published addresses, so it must not depend on the host cron called the site under. An empty setting falls back to the request address.

Attributes
#[Inject]

Methods

actionAdvert()

Sitemap of active company profiles, split into files by ID ranges (size depends on the number of languages).

public actionAdvert() : void

Without ?save=1 it returns a JSON preview (bucket count); with ?save=1 it generates the files.

URL: /cron/comcat/sitemap/advert?token=xxx[&save=1]

Frequency: daily, at night.

Attributes
#[CronJob]
$frequency: 'daily:03:24'
$outbound: false
$query: ['save' => '1']

actionCategory()

Sitemap of all active Comcat categories with hreflang variants.

public actionCategory() : void

URL: /cron/comcat/sitemap/category?token=xxx[&save=1]

Frequency: daily, at night.

Attributes
#[CronJob]
$frequency: 'daily:03:22'
$outbound: false
$query: ['save' => '1']

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

buildSitemapXml()

Builds the sitemap XML from entities.

protected buildSitemapXml(iterable<string|int, TItem> $items, callable(TItem $item, string $localeKey, int $languageId): Array $urlBuilder, callable(TItem $item): array{changefreq?: string, priority?: ?string, lastmod?: ?string} $metaBuilder, array<int, Localization> $localizations) : string

Calls $urlBuilder for every entity and localization, and $metaBuilder once per entity.

Parameters
$items : iterable<string|int, TItem>
$urlBuilder : callable(TItem $item, string $localeKey, int $languageId): Array
$metaBuilder : callable(TItem $item): array{changefreq?: string, priority?: ?string, lastmod?: ?string}
$localizations : array<int, Localization>
Tags
template
Return values
string

generateUrl()

protected generateUrl(string $destination, array<string, mixed> $params) : string|null
Parameters
$destination : string
$params : array<string, mixed>
Return values
string|null

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
bool

respondBucketedSitemap()

Splits a large sitemap into N files by fixed ID ranges.

protected respondBucketedSitemap(string $filenamePrefix, callable(): int $maxIdResolver, callable(int $afterId, int $limit): array<int, TItem> $batchLoader, callable(TItem $item, string $localeKey, int $languageId): Array $urlBuilder, callable(TItem $item): array{changefreq?: string, priority?: ?string, lastmod?: ?string} $metaBuilder[, array<string, int|string> $statsExtra = [] ]) : void

The ID boundaries are stable: deleting one item does not move others between files.

  • without ?save=1 it returns a JSON preview (how many buckets would be created)
  • with ?save=1 it reads entities in keyset batches and writes each to the temp file of its bucket; only when all are written does it publish them atomically and delete surplus old {prefix}-N.xml files (StagedFileSet)

Only one batch (SITEMAP_BATCH_SIZE) is held in memory; the Api read of the next batch runs UnitOfWork::clear(), so nothing keeps the previous batch alive. The bucket size follows the language count and the protocol limits are enforced by SitemapBucketWriter.

Parameters
$filenamePrefix : string

e.g. "sitemap-bazaar-adverts" (without number and extension)

$maxIdResolver : callable(): int

returns the max ID of the active subset (0 = no data), preview only

$batchLoader : callable(int $afterId, int $limit): array<int, TItem>

loads at most $limit entities with ID > $afterId, ascending by ID

$urlBuilder : callable(TItem $item, string $localeKey, int $languageId): Array
$metaBuilder : callable(TItem $item): array{changefreq?: string, priority?: ?string, lastmod?: ?string}
$statsExtra : array<string, int|string> = []

extra statistics for the JSON response

Tags
template

respondSitemap()

Sends the XML response, or writes it to a file and sends a JSON success.

protected respondSitemap(string $xml[, string|null $filename = null ][, array<string, int|string> $stats = [] ]) : void
Parameters
$xml : string
$filename : string|null = null
$stats : array<string, int|string> = []

extra statistics for the JSON response (e.g. items, languages)

sendError()

protected sendError(string $message[, int $code = 500 ]) : never
Parameters
$message : string
$code : int = 500
Return values
never

sendSkipped()

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
never

sendSuccess()

protected sendSuccess([array<string|int, mixed> $data = [] ]) : never
Parameters
$data : array<string|int, mixed> = []
Return values
never

tryCall()

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
bool

warmupTranslator()

Warms the translator cache from already loaded entities, avoiding the global `warmupCache(null)`.

protected warmupTranslator(string $translatorClass, array<int, object> $entities) : void
Parameters
$translatorClass : string
$entities : array<int, object>

buildAdvertUrl()

private buildAdvertUrl(Advert $advert, int $detailPageId, string $localeKey) : string|null
Parameters
$advert : Advert
$detailPageId : int
$localeKey : string
Return values
string|null

buildCategoryUrl()

private buildCategoryUrl(Category $category, int $listPageId, string $localeKey, int $languageId) : string|null
Parameters
$category : Category
$listPageId : int
$localeKey : string
$languageId : int
Return values
string|null

buildUrlsByLocale()

Returns the item URL for every active localization (localization key => URL); an empty result means the item does not belong in the sitemap.

private buildUrlsByLocale(TItem $item, callable(TItem $item, string $localeKey, int $languageId): Array $urlBuilder, array<int, Localization> $localizations) : array<string, string>
Parameters
$item : TItem
$urlBuilder : callable(TItem $item, string $localeKey, int $languageId): Array
$localizations : array<int, Localization>
Tags
template
Return values
array<string, string>

failSitemapWrite()

Reports a write failure: the detail (including the path) goes to the server log only, the response carries no absolute path.

private failSitemapWrite(RuntimeException $e, string $fileName) : never
Parameters
$e : RuntimeException
$fileName : string
Return values
never

loadAdvertsBatch()

private loadAdvertsBatch(int $afterId, int $limit) : array<int, Advert>
Parameters
$afterId : int
$limit : int
Return values
array<int, Advert>

resolveAdvertLastmod()

private static resolveAdvertLastmod(Advert $advert) : string
Parameters
$advert : Advert
Return values
string

resolveMaxAdvertId()

private resolveMaxAdvertId() : int
Return values
int

resolvePageId()

private resolvePageId(string $key) : int
Parameters
$key : string
Return values
int

resolveSitemapItemId()

private static resolveSitemapItemId(object $item) : int
Parameters
$item : object
Return values
int
On this page

Search results