From 9c31afbe2b68040a450c99775ee7cbc9ff711e1a Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Tue, 6 Sep 2022 17:26:06 +0100 Subject: [PATCH 1/5] FIX: Ensure attributes are stored against the Image record (fixes #513) --- src/ImageManipulation.php | 17 ++++------- tests/php/ImageManipulationTest.php | 28 ++++++++++++++++--- .../LazyLoadAccessorExtension.php | 13 +++++++++ 3 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 tests/php/ImageManipulationTest/LazyLoadAccessorExtension.php diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index f656a044..5f75a9c6 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -1072,23 +1072,15 @@ protected function castDimension($value, $dimension) */ private function copyImageBackend(): AssetContainer { - // Store result in new DBFile instance - /** @var DBFile $file */ - $file = DBField::create_field( - 'DBFile', - [ - 'Filename' => $this->getFilename(), - 'Hash' => $this->getHash(), - 'Variant' => $this->getVariant() - ] - ); + $file = clone $this; $backend = $this->getImageBackend(); if ($backend) { $file->setImageBackend($backend); } - return $file->setOriginal($this); + $file->File->setOriginal($this); + return $file; } /** @@ -1107,6 +1099,9 @@ public function setAttribute($name, $value) [$name => $value] )); + // If this file has already been rendered then AttributesHTML will be cached, so we have to clear the cache + $file->objCacheClear(); + return $file; } diff --git a/tests/php/ImageManipulationTest.php b/tests/php/ImageManipulationTest.php index f17a18d5..e302bcd9 100644 --- a/tests/php/ImageManipulationTest.php +++ b/tests/php/ImageManipulationTest.php @@ -2,19 +2,16 @@ namespace SilverStripe\Assets\Tests; -use InvalidArgumentException; use Prophecy\Prophecy\ObjectProphecy; use Silverstripe\Assets\Dev\TestAssetStore; use SilverStripe\Assets\File; use SilverStripe\Assets\Folder; use SilverStripe\Assets\Image; -use SilverStripe\Assets\Image_Backend; use SilverStripe\Assets\InterventionBackend; -use SilverStripe\Assets\Storage\AssetContainer; use SilverStripe\Assets\Storage\AssetStore; use SilverStripe\Assets\Storage\DBFile; +use SilverStripe\Assets\Tests\ImageManipulationTest\LazyLoadAccessorExtension; use SilverStripe\Core\Config\Config; -use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\View\SSViewer; @@ -363,6 +360,29 @@ public function testBadLazyLoad($val) ); } + public function testLazyLoadIsAccessibleInExtensions() + { + Image::add_extension(LazyLoadAccessorExtension::class); + + /** @var Image $origin */ + $image = $this->objFromFixture(Image::class, 'imageWithTitle'); + + $this->assertTrue( + $image->LazyLoad(true)->getLazyLoadValueViaExtension(), + 'Incorrect LazyLoad value reported by extension' + ); + $this->assertFalse( + $image->LazyLoad(false)->getLazyLoadValueViaExtension(), + 'Incorrect LazyLoad value reported by extension' + ); + $this->assertTrue( + $image->LazyLoad(false)->LazyLoad(true)->getLazyLoadValueViaExtension(), + 'Incorrect LazyLoad value reported by extension' + ); + + Image::remove_extension(LazyLoadAccessorExtension::class); + } + public function renderProvider() { $alt = 'This is a image Title'; diff --git a/tests/php/ImageManipulationTest/LazyLoadAccessorExtension.php b/tests/php/ImageManipulationTest/LazyLoadAccessorExtension.php new file mode 100644 index 00000000..f210e43f --- /dev/null +++ b/tests/php/ImageManipulationTest/LazyLoadAccessorExtension.php @@ -0,0 +1,13 @@ +getOwner()->IsLazyLoaded(); + } +} From 8e50259031ca5b5d0252d4f1b15d347073524c4a Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 10 Mar 2023 12:21:26 +1300 Subject: [PATCH 2/5] MNT Update development dependencies --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 113f61c1..18374262 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "silverstripe/framework": "^4.10", + "silverstripe/framework": "4.13.x-dev", "silverstripe/vendor-plugin": "^1.0", "symfony/filesystem": "^3.4|^4.0|^5.0", "intervention/image": "^2.7", @@ -50,4 +50,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} +} \ No newline at end of file From b46993cd07f1b8fc254aeca16421522bdfa23035 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 10 Mar 2023 15:50:59 +1300 Subject: [PATCH 3/5] MNT Update release dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 18374262..b84ac174 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "silverstripe/framework": "4.13.x-dev", + "silverstripe/framework": "4.13.0-beta1", "silverstripe/vendor-plugin": "^1.0", "symfony/filesystem": "^3.4|^4.0|^5.0", "intervention/image": "^2.7", From 31a7f6a5fa8676bd0c870300f21a99a8cddacdbc Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 10 Mar 2023 15:51:03 +1300 Subject: [PATCH 4/5] MNT Update development dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b84ac174..18374262 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "silverstripe/framework": "4.13.0-beta1", + "silverstripe/framework": "4.13.x-dev", "silverstripe/vendor-plugin": "^1.0", "symfony/filesystem": "^3.4|^4.0|^5.0", "intervention/image": "^2.7", From fb2e4b69fa17b742a507360d4c9c260a32d88883 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 28 Mar 2023 16:47:21 +1300 Subject: [PATCH 5/5] MNT Revert erroneous dependency changes (#547) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 18374262..28768508 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "silverstripe/framework": "4.13.x-dev", + "silverstripe/framework": "^4.10", "silverstripe/vendor-plugin": "^1.0", "symfony/filesystem": "^3.4|^4.0|^5.0", "intervention/image": "^2.7",