From f6a05b78209198555f1521a1abeb1bfede821b7f Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 8 May 2024 19:05:48 -0400 Subject: [PATCH 1/7] fix: Fixed an issue where field content was not propagated to other sites on multi-site installs, causing missing images --- src/services/OptimizedImages.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/services/OptimizedImages.php b/src/services/OptimizedImages.php index 82d83669..08781295 100644 --- a/src/services/OptimizedImages.php +++ b/src/services/OptimizedImages.php @@ -291,18 +291,20 @@ public function updateOptimizedImageFieldData(Field $field, ElementInterface $as if ($field->handle !== null) { $asset->setFieldValue($field->handle, $field->serializeValue($model, $asset)); $fieldLayout = $asset->getFieldLayout(); - $siteSettingsRecord = Element_SiteSettingsRecord::findOne([ + $siteSettingsRecords = Element_SiteSettingsRecord::findAll([ 'elementId' => $asset->id, - 'siteId' => $asset->siteId, ]); - // Set the field values - if ($siteSettingsRecord && $fieldLayout) { - $content = Json::decodeIfJson($siteSettingsRecord->content) ?: []; - $content[$field->layoutElement->uid] = $field->serializeValue($asset->getFieldValue($field->handle), $asset); - $siteSettingsRecord->content = $content; - // Save the site settings record - if (!$siteSettingsRecord->save(false)) { - Craft::error('Couldn’t save elements’ site settings record.', __METHOD__); + // Update it for all of the sites + foreach ($siteSettingsRecords as $siteSettingsRecord) { + // Set the field values + if ($siteSettingsRecord && $fieldLayout) { + $content = Json::decodeIfJson($siteSettingsRecord->content) ?: []; + $content[$field->layoutElement->uid] = $field->serializeValue($asset->getFieldValue($field->handle), $asset); + $siteSettingsRecord->content = $content; + // Save the site settings record + if (!$siteSettingsRecord->save(false)) { + Craft::error('Couldn’t save elements’ site settings record.', __METHOD__); + } } } } From c39e00bce255e9904493c293762bf7dbf54c38fc Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 8 May 2024 19:06:00 -0400 Subject: [PATCH 2/7] chore: Version 5.0.1 --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06d51901..3a78d3cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # ImageOptimize Changelog +## 5.0.1 - UNRELEASED +### Fixed +* Fixed an issue where field content was not propagated to other sites on multi-site installs, causing missing images + ## 5.0.0 - 2024.04.15 ### Added * Stable release for Craft CMS 5 diff --git a/composer.json b/composer.json index 08fe3936..e139e470 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-imageoptimize", "description": "Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like imgix, with zero template changes.", "type": "craft-plugin", - "version": "5.0.0", + "version": "5.0.1", "keywords": [ "craft", "cms", From 47c80e68a7ac9bb9461df0f438f4dc2ee2c11b98 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 8 May 2024 22:47:16 -0400 Subject: [PATCH 3/7] fix: Fixed an issue where the `.imgTag()` and `.pictureTag()` would output and invalid `style` attribute for lazy loaded images ([#400](https://github.com/nystudio107/craft-imageoptimize/issues/400)) --- src/models/BaseImageTag.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/models/BaseImageTag.php b/src/models/BaseImageTag.php index 175492ad..93906989 100644 --- a/src/models/BaseImageTag.php +++ b/src/models/BaseImageTag.php @@ -35,10 +35,11 @@ protected function swapLazyLoadAttrs(string $loading, string $placeHolder, array } // Set the style on this element to be the placeholder image as the background-image if (isset($attrs['style']) && !empty($attrs['src'])) { - $attrs['style'] = trim( - $attrs['style'] . - 'background-image:url(' . $this->getLazyLoadSrc($placeHolder) . '); background-size: cover;' - ); + if (empty($attrs['style'])) { + $attrs['style'] = []; + } + $attrs['style']['background-image'] = 'url(' . $this->getLazyLoadSrc($placeHolder) . ')'; + $attrs['style']['background-size'] = 'cover'; } // Handle attributes that lazy and lazySizesFallback have in common switch ($loading) { From a5e7a3b7313bc98b38fa68f70e92c5e81dbc3fd7 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 8 May 2024 22:47:31 -0400 Subject: [PATCH 4/7] chore: Version 5.0.1 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a78d3cf..0369dbc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 5.0.1 - UNRELEASED ### Fixed * Fixed an issue where field content was not propagated to other sites on multi-site installs, causing missing images +* Fixed an issue where the `.imgTag()` and `.pictureTag()` would output and invalid `style` attribute for lazy loaded images ([#400](https://github.com/nystudio107/craft-imageoptimize/issues/400)) ## 5.0.0 - 2024.04.15 ### Added From fb17fd8edba9cad85d78d54deda79ac9e9283e6a Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 8 May 2024 23:10:48 -0400 Subject: [PATCH 5/7] fix: Fixed an issue where the Subpath wasn't being included for remote volumes like S3 & Google Cloud ([#403](https://github.com/nystudio107/craft-imageoptimize/issues/403)) --- src/imagetransforms/ImageTransform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imagetransforms/ImageTransform.php b/src/imagetransforms/ImageTransform.php index 6c4b405b..e3b6faa9 100644 --- a/src/imagetransforms/ImageTransform.php +++ b/src/imagetransforms/ImageTransform.php @@ -99,7 +99,7 @@ public function purgeUrl(string $url): bool public function getAssetUri(Asset $asset): ?string { $volume = $asset->getVolume(); - $assetPath = $asset->getPath(); + $assetPath = $volume->getSubpath() . $asset->getPath(); // Account for volume types with a subfolder setting // e.g. craftcms/aws-s3, craftcms/google-cloud From 58b9c556d106ac9c6fe43c44c8e977501e213e48 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 8 May 2024 23:10:54 -0400 Subject: [PATCH 6/7] chore: Version 5.0.1 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0369dbc4..32bd2cf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed * Fixed an issue where field content was not propagated to other sites on multi-site installs, causing missing images * Fixed an issue where the `.imgTag()` and `.pictureTag()` would output and invalid `style` attribute for lazy loaded images ([#400](https://github.com/nystudio107/craft-imageoptimize/issues/400)) +* Fixed an issue where the Subpath wasn't being included for remote volumes like S3 & Google Cloud ([#403](https://github.com/nystudio107/craft-imageoptimize/issues/403)) ## 5.0.0 - 2024.04.15 ### Added From 646dd1308db7873042744a9a8b18d610bd96c35d Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Thu, 9 May 2024 15:51:51 -0400 Subject: [PATCH 7/7] chore: Version 5.0.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32bd2cf7..1d3a868f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # ImageOptimize Changelog -## 5.0.1 - UNRELEASED +## 5.0.1 - 2024.05.09 ### Fixed * Fixed an issue where field content was not propagated to other sites on multi-site installs, causing missing images * Fixed an issue where the `.imgTag()` and `.pictureTag()` would output and invalid `style` attribute for lazy loaded images ([#400](https://github.com/nystudio107/craft-imageoptimize/issues/400))