From 7df3eb6db75bc73b97f3410a614a325f3e620de7 Mon Sep 17 00:00:00 2001 From: Mark Wijsman Date: Thu, 19 Mar 2026 13:41:51 +0100 Subject: [PATCH 1/3] Fix CDN path invalidation for replaced assets with the same filename --- src/Plugin.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index 4cd9353..44def34 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -62,7 +62,12 @@ function(ReplaceAssetEvent $event) { // when replacing asset with another one with the same filename, invalidate the cdn path for the original file too // see https://github.com/craftcms/aws-s3/issues/184 for details if ($oldFilename === $newFilename) { - $fs->invalidateCdnPath($asset->getPath()); + $folderPath = trim($asset->getFolder()->path, '/'); + $oldPath = $folderPath !== '' + ? $folderPath . '/' . $oldFilename + : $oldFilename; + + $fs->invalidateCdnPath($oldPath); } } ); From 3fd1fbb19d05086de4491dd5dc89752bb111ccdf Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Tue, 9 Jun 2026 18:02:48 -0700 Subject: [PATCH 2/3] Update comments and fix optional chaining in Plugin.php --- src/Plugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 44def34..acbea49 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -59,10 +59,10 @@ function(ReplaceAssetEvent $event) { $oldFilename = $asset->getFilename(); $newFilename = $event->filename; - // when replacing asset with another one with the same filename, invalidate the cdn path for the original file too - // see https://github.com/craftcms/aws-s3/issues/184 for details + // when replacing an asset with another one with the same filename, invalidate the CDN path for the original file too + // see https://github.com/craftcms/aws-s3/issues/184 and https://github.com/craftcms/aws-s3/issues/195 for details if ($oldFilename === $newFilename) { - $folderPath = trim($asset->getFolder()->path, '/'); + $folderPath = trim($asset->getFolder()?->path, '/'); $oldPath = $folderPath !== '' ? $folderPath . '/' . $oldFilename : $oldFilename; From 80d57aa8090d87e199a2c7071f1c8725c3b66f63 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Tue, 9 Jun 2026 18:06:02 -0700 Subject: [PATCH 3/3] Fix formatting of folderPath assignment --- src/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index acbea49..61ace47 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -62,7 +62,7 @@ function(ReplaceAssetEvent $event) { // when replacing an asset with another one with the same filename, invalidate the CDN path for the original file too // see https://github.com/craftcms/aws-s3/issues/184 and https://github.com/craftcms/aws-s3/issues/195 for details if ($oldFilename === $newFilename) { - $folderPath = trim($asset->getFolder()?->path, '/'); + $folderPath = trim($asset->getFolder()->path, '/'); $oldPath = $folderPath !== '' ? $folderPath . '/' . $oldFilename : $oldFilename;