From 85f5f8284f827b8f2b426943e357e3df117ad1f5 Mon Sep 17 00:00:00 2001 From: MrMeshok <72924086+MrMeshok@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:42:14 +0500 Subject: [PATCH] Copy media with manipulations (#3590) --- src/MediaCollections/Models/Media.php | 1 + tests/Feature/Media/CopyTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/MediaCollections/Models/Media.php b/src/MediaCollections/Models/Media.php index 7796e1306..7aa0443fb 100644 --- a/src/MediaCollections/Models/Media.php +++ b/src/MediaCollections/Models/Media.php @@ -407,6 +407,7 @@ public function copy(HasMedia $model, $collectionName = 'default', string $diskN ->addMedia($temporaryFile) ->usingName($this->name) ->setOrder($this->order_column) + ->withManipulations($this->manipulations) ->withCustomProperties($this->custom_properties); if ($fileName !== '') { $fileAdder->usingFileName($fileName); diff --git a/tests/Feature/Media/CopyTest.php b/tests/Feature/Media/CopyTest.php index 49580c0a8..6112105a6 100644 --- a/tests/Feature/Media/CopyTest.php +++ b/tests/Feature/Media/CopyTest.php @@ -148,3 +148,18 @@ expect($media->getPath())->toBeFile(); expect($anotherMedia->getPath())->toBeFile(); }); + +it('can copy media with manipulations', function () { + $model = TestModel::create(['name' => 'original']); + + $media = $model + ->addMedia($this->getTestJpg()) + ->withManipulations(['thumb' => ['greyscale' => [], 'height' => [10]]]) + ->toMediaCollection(); + + $anotherModel = TestModel::create(['name' => 'target']); + + $anotherMedia = $media->copy($anotherModel); + + expect($media->manipulations)->toEqual($anotherMedia->manipulations); +});