From c0d69f7205dd620c9902f8e1919c298cd3e3d47f Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 7 Jul 2022 14:22:22 +0200 Subject: [PATCH] Do not delete thumbnail queue when replacing an asset Thumbnails are normally created on demand, e.g. when processing the format codes in a post's body text. Normally, the temporary URL is only used once to generate thumbnails ad-hoc. However, when cache is enabled, a reference to the asset may be used in a cached version of a formatted body text, skipping the normal thumbnail generation routine. When an asset is replaced, currently, all thumbnails are removed and references to them are removed from the database. In case the asset is still referenced in a cached formatted body text, this could lead to an error when requesting the thumbnail, as the thumbnail request is no longer present in the system. As we do not know what posts use particular assets at this point in the code, it is best to work around this issue by unsetting the thumbnail filenames rather than deleting the entries outright. This effectively generates them again on the next request. In the future, we should aim to keep track of what posts make use of assets, so cache may be invalidated in a more targeted way. --- models/Image.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/Image.php b/models/Image.php index 99a9fbe6..212c1dc0 100644 --- a/models/Image.php +++ b/models/Image.php @@ -158,7 +158,8 @@ class Image extends Asset } return Registry::get('db')->query(' - DELETE FROM assets_thumbs + UPDATE assets_thumbs + SET filename = NULL WHERE id_asset = {int:id_asset}', ['id_asset' => $this->id_asset]); }