SitemapPresenter
extends BasePresenter
in package
uses
SitemapBuilderTrait
Table of Contents
Constants
- ADVERT_CHANGEFREQ : mixed = 'daily'
- ADVERT_PRIORITY : mixed = '0.5'
- ADVERTS_PREFIX : mixed = 'sitemap-bazaar-adverts'
- CATEGORY_CHANGEFREQ : mixed = 'weekly'
- CATEGORY_PRIORITY : mixed = '0.7'
- FILE_CATEGORIES : mixed = 'sitemap-bazaar-categories.xml'
- SETTINGS_GROUP : mixed = 5
- 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 adverts, split into files by ID ranges (size depends on the number of languages).
- actionCategory() : void
- Sitemap of all active Bazaar 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
ADVERT_CHANGEFREQ
private
mixed
ADVERT_CHANGEFREQ
= 'daily'
ADVERT_PRIORITY
private
mixed
ADVERT_PRIORITY
= '0.5'
ADVERTS_PREFIX
private
mixed
ADVERTS_PREFIX
= 'sitemap-bazaar-adverts'
CATEGORY_CHANGEFREQ
private
mixed
CATEGORY_CHANGEFREQ
= 'weekly'
CATEGORY_PRIORITY
private
mixed
CATEGORY_PRIORITY
= '0.7'
FILE_CATEGORIES
private
mixed
FILE_CATEGORIES
= 'sitemap-bazaar-categories.xml'
SETTINGS_GROUP
private
mixed
SETTINGS_GROUP
= 5
SITEMAP_BATCH_SIZE
Number of entities loaded by one query.
private
mixed
SITEMAP_BATCH_SIZE
= 500
The file (bucket) size is computed separately from the language count, see SitemapBucketWriter::bucketSizeFor().
Properties
$cronLockManager
public
CronLockManager
$cronLockManager
Attributes
- #[Inject]
$linkGenerator
public
LinkGenerator
$linkGenerator
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]
$sitemapLocalizationManager
public
LocalizationManager
$sitemapLocalizationManager
Attributes
- #[Inject]
$sitemapRouterDispatcher
public
RouterDispatcher
$sitemapRouterDispatcher
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]
$debugMode
protected
bool
$debugMode
= false
$productionMode
protected
bool
$productionMode
= false
$advertManager read-only
private
AdvertManager
$advertManager
$categoryManager read-only
private
CategoryManager
$categoryManager
Methods
__construct()
public
__construct(CategoryManager $categoryManager, AdvertManager $advertManager) : mixed
Parameters
- $categoryManager : CategoryManager
- $advertManager : AdvertManager
actionAdvert()
Sitemap of active adverts, 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/bazaar/sitemap/advert?token=xxx[&save=1]
Frequency: daily, at night.
Attributes
- #[CronJob]
- $frequency: 'daily:03:05'
- $outbound: false
- $query: ['save' => '1']
actionCategory()
Sitemap of all active Bazaar categories with hreflang variants.
public
actionCategory() : void
URL: /cron/bazaar/sitemap/category?token=xxx[&save=1]
Frequency: daily, at night.
Attributes
- #[CronJob]
- $frequency: 'daily:03:00'
- $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
startup()
public
startup() : void
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
Return values
stringgenerateUrl()
protected
generateUrl(string $destination, array<string, mixed> $params) : string|null
Parameters
- $destination : string
- $params : array<string, mixed>
Return values
string|nullisSameSiteRequest()
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
boolloadActiveLocalizations()
Loads active localizations including the linked language.
protected
loadActiveLocalizations() : array<int, Localization>
Return values
array<int, Localization>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=1it returns a JSON preview (how many buckets would be created) - with
?save=1it 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.xmlfiles (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
$limitentities 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
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
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
nevershouldSaveSitemap()
protected
shouldSaveSitemap() : bool
Return values
booltryCall()
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
boolwarmupTranslator()
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|nullbuildCategoryUrl()
private
buildCategoryUrl(Category $category, int $listPageId, string $localeKey, int $languageId) : string|null
Parameters
- $category : Category
- $listPageId : int
- $localeKey : string
- $languageId : int
Return values
string|nullbuildUrlsByLocale()
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
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
neverloadAdvertsBatch()
private
loadAdvertsBatch(int $afterId, int $limit) : array<int, Advert>
Parameters
- $afterId : int
- $limit : int
Return values
array<int, Advert>loadCategories()
private
loadCategories() : array<int, Category>
Return values
array<int, Category>resolveAdvertLastmod()
private
static resolveAdvertLastmod(Advert $advert) : string
Parameters
- $advert : Advert
Return values
stringresolveMaxAdvertId()
private
resolveMaxAdvertId() : int
Return values
intresolvePageId()
private
resolvePageId(string $key) : int
Parameters
- $key : string
Return values
intresolveSitemapDir()
private
resolveSitemapDir() : string
Return values
stringresolveSitemapItemId()
private
static resolveSitemapItemId(object $item) : int
Parameters
- $item : object