XML Sitemap Generator: Technical Details
Technical structure of the XML Sitemap Generator: generation flow, services and URL providers, scheduled task, config subscriber, admin component, default interval and file system behaviour.
XML Sitemap Generator: Technical Details
Live Demo: Try this and other plugins live — no installation, no risk: demo.markus-michalski.net
Generation flow
graph TD
A["Admin button / scheduled task / console command"] --> B["SitemapGeneratorService.generate()"]
B --> C{"clearExisting?"}
C -->|"yes"| D["FileWriterService: delete sitemap*.xml"]
C -->|"no"| E["determine active URL providers"]
D --> E
E --> F["ProductUrlProvider"]
E --> G["CategoryUrlProvider"]
E --> H["CmsPageUrlProvider"]
E --> I["ManufacturerUrlProvider"]
F --> J["XmlWriterService: urlset per file"]
G --> J
H --> J
I --> J
J --> K["FileWriterService: write sitemap-type.xml"]
K --> L["XmlWriterService: sitemapindex"]
L --> M["FileWriterService: write sitemap.xml"]
There is no cache: every call of generate() reads the data anew and writes the files anew.
Building blocks
| Class | Responsibility |
|---|---|
SitemapGeneratorService |
Orchestrates generation, splits at the file limit, writes the index |
AbstractUrlProvider and four providers |
Deliver the URLs per type as a generator, default values for priority and change frequency |
HreflangService |
Reads alternate SEO URLs of all languages via SQL in one block |
XmlWriterService |
Creates urlset and sitemapindex as XML (DOM) |
FileWriterService |
Writes, deletes and lists files in the target directory |
ConfigService |
Reads the plugin settings (MmdSitemap.config.*) per Sales Channel, cleans directory and slug |
GenerateSitemapCommand |
Console command mmd:sitemap:generate |
SitemapGenerationTask and SitemapGenerationTaskHandler |
Scheduled task mmd.sitemap.generation |
ConfigChangeSubscriber |
Transfers a changed interval to the scheduled task |
SitemapController |
Admin API routes for generation and statistics |
MmdSitemap |
Plugin class, cleans up task and settings on uninstall |
The providers are tagged mmd.sitemap.url_provider in the service container and are processed in the order products (100), categories (90), CMS pages (80), manufacturers (70). A custom provider can therefore only be attached through the container, there is no documented extension point.
Processing
- The providers load data in blocks of 100 entries each. SEO URLs and hreflang alternates are queried collectively per block.
- The generator collects the URLs of a type until the per-file limit is reached and then writes them as one file.
- The per-file limit is the Max URLs per Sitemap File setting, capped at 50,000.
- The index uses
scheme://host[:port]of the Sales Channel's domain matching the context language, otherwise the first domain. - The plugin creates directories as needed with permissions
0755. The web server user must be allowed to write topublic/<output directory>, otherwise no files are created. --clearand the automatic deletion remove only files matchingsitemap*.xmlin the respective Sales Channel's target directory.
Scheduled task and interval
- The task is named
mmd.sitemap.generationand has a default interval of 86,400 seconds. - When the value
MmdSitemap.config.scheduledTaskIntervalchanges, theConfigChangeSubscribersets the task's interval to the global value of the setting. The task is a single entry overall, which is why only the global value counts. - On a run the handler first checks the global switch, then per active storefront Sales Channel the Sales Channel's switch. Errors of one Sales Channel are logged and do not stop the others.
Admin interface
The Vue component mmd-sitemap-generator is embedded in the plugin configuration as the Manual Generation card. It reads the Sales Channel from the parent configuration page, calls the Admin API and shows statistics and result. Texts come from the snippets in German and English.