Move Gzip compression out of XmlSitemapWriter::endDocument()

Created on 30 May 2023, about 1 year ago

Problem/Motivation

Currently when the Gzip option is enabled, we are reading back the XML file in XmlSitemapWriter::endDocument() using file_get_contents() and compressing it before writing it back.

The problem is that it is not guaranteed that the file exists at this point. When using stream wrappers (e.g. using the S3FS module), the XML file is only written at the time the XmlSitemapWriter object is deconstructed. The deconstruction of the object causes the file to be flushed, which triggers the writing of the file when using remote file systems.

A very similar issue was filed way back in 2014 for the D7 version of the module: see #2292717: XMLSitemapWriter::endDocument() calls filesize() prematurely. β†’ .

Steps to reproduce

  1. Enable the S3FS module and set it up to handle the public file system.
  2. Enable GZip compression for XmlSitemap.
  3. Run drush xmlsitemap:regenerate.

Result: errors are thrown:

Error executing "GetObject" on "https://s3.eu-west-1.amazonaws.com/mybucket/public/xmlsitemap/NCkDAB1jjJ..."; AWS HTTP error: Client error: `GET https://s3.eu-west-1.amazonaws.com/mybucket/public/xmlsitemap/NCkDAB1jjJ...` resulted in a `404 Not Found` response

Proposed resolution

We shouldn't attempt to read the XML document that was just generated inside XmlSitemapWriter::endDocument(). This should be moved to the calling code.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡¬Bulgaria pfrenssen Sofia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024